diff --git a/PanoPainter-OSX/main.cpp b/PanoPainter-OSX/main.cpp index ae52450d..7ccf14c0 100644 --- a/PanoPainter-OSX/main.cpp +++ b/PanoPainter-OSX/main.cpp @@ -8,6 +8,7 @@ #include "keymap.h" #include "main.h" #include "platform_apple/apple_platform_services.h" +#include "platform_legacy/legacy_platform_services.h" #include "settings.h" #include #include @@ -23,6 +24,8 @@ @import AppCenterAnalytics; @import AppCenterCrashes; +static std::unique_ptr g_platform_services; + NSString* keyCodeToString(NSUInteger keyCode, NSUInteger mods) { TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); @@ -522,6 +525,12 @@ NSString* keyCodeToString(NSUInteger keyCode, NSUInteger mods) [MSCrashes class] ]]; + g_platform_services = pp::platform::legacy::create_platform_services({ + .apple_document_services = []() -> pp::platform::apple::AppleDocumentPlatformServices& { + return pp::platform::apple::active_legacy_apple_document_platform_services(); + }, + }); + App::I->set_platform_services(g_platform_services.get()); App::I->initLog(); App::I->create(); NSRect r = NSMakeRect(0, 0, App::I->width, App::I->height); diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index dd26b539..c5d18955 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -10,6 +10,7 @@ #import "GameViewController.h" #import #include "app.h" +#include "platform_legacy/legacy_platform_services.h" #include "platform_apple/apple_platform_services.h" #include "settings.h" #import "objc_utils.h" @@ -17,6 +18,7 @@ std::mutex render_mutex; std::condition_variable render_cv; +static std::unique_ptr g_platform_services; @interface GameImagePicker : UIImagePickerController { @@ -580,6 +582,12 @@ bool is_tap = true; pp::platform::apple::set_legacy_apple_state( self, (AppDelegate*)[[UIApplication sharedApplication] delegate]); + g_platform_services = pp::platform::legacy::create_platform_services({ + .apple_document_services = []() -> pp::platform::apple::AppleDocumentPlatformServices& { + return pp::platform::apple::active_legacy_apple_document_platform_services(); + }, + }); + App::I->set_platform_services(g_platform_services.get()); App::I->initLog(); //self.preferredFramesPerSecond = 60; diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 103b992a..478b60a4 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -18,6 +18,13 @@ agent or engineer to remove them without reconstructing context from chat. ## Reductions +- 2026-06-17: `DEBT-0016`/`DEBT-0017`/`DEBT-0051`/`DEBT-0052`/`DEBT-0053` + were narrowed again. `PanoPainter-OSX/main.cpp` and + `PanoPainter/GameViewController.m` now bind owned legacy + `PlatformServices` instances into `App`, and + `src/platform_legacy/legacy_platform_services.*` now takes an injected Apple + document-service provider instead of hardcoding direct calls to + `active_legacy_apple_document_platform_services()` in the touched path. - 2026-06-17: `DEBT-0016`/`DEBT-0017` were narrowed again. `src/platform_legacy/legacy_platform_services.*` now takes an explicit Android bridge through `create_platform_services(...)`, and diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index a3e16074..bcfb2b0b 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -70,6 +70,16 @@ What is already real: - `pp_app_core` Latest slice: +- `PanoPainter-OSX/main.cpp` and `PanoPainter/GameViewController.m` now bind + owned legacy `PlatformServices` instances into `App` explicitly at the Apple + entrypoints. +- `src/platform_legacy/legacy_platform_services.*` now takes an injected Apple + document-service provider through `create_platform_services(...)` instead of + hardcoding direct calls to + `active_legacy_apple_document_platform_services()` in the touched path. +- The touched Apple clipboard, keyboard visibility, render-context, + document-picker, display/share, save-ui-state, app-close, SonarPen, and + prepared-file execution now route through that injected Apple-owned provider. - `src/platform_legacy/legacy_platform_services.*` now takes an explicit Android bridge through `create_platform_services(...)` instead of declaring Android JNI/EGL/clipboard/file-picker hooks directly inside the legacy diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index ae4227f2..941d88db 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -78,6 +78,16 @@ Completed, blocked, and superseded task history moved to the queue is now ordered by code movement instead. Current slice: +- `PanoPainter-OSX/main.cpp` and `PanoPainter/GameViewController.m` now bind + owned legacy `PlatformServices` instances into `App` explicitly at the Apple + entrypoints. +- `src/platform_legacy/legacy_platform_services.*` now takes an injected Apple + document-service provider through `create_platform_services(...)` instead of + hardcoding direct calls to + `active_legacy_apple_document_platform_services()` in the touched path. +- The touched Apple clipboard, keyboard visibility, render-context, + document-picker, display/share, save-ui-state, app-close, SonarPen, and + prepared-file execution now route through that injected Apple-owned provider. - `src/platform_legacy/legacy_platform_services.*` now takes an explicit Android bridge through `create_platform_services(...)` instead of declaring Android JNI/EGL/clipboard/file-picker hooks directly inside the legacy diff --git a/src/platform_legacy/legacy_platform_services.cpp b/src/platform_legacy/legacy_platform_services.cpp index 1556e0bc..ce82560c 100644 --- a/src/platform_legacy/legacy_platform_services.cpp +++ b/src/platform_legacy/legacy_platform_services.cpp @@ -45,6 +45,7 @@ public: , android_storage_paths_(std::move(config.android_storage_paths)) #endif , web_platform_services_(config.web_platform_services) + , apple_document_services_(std::move(config.apple_document_services)) { } @@ -101,9 +102,9 @@ public: void trigger_crash_test() override { #ifdef __IOS__ - pp::platform::apple::active_legacy_apple_document_platform_services().trigger_crash_test(); + active_apple_document_platform_services().trigger_crash_test(); #elif __OSX__ - pp::platform::apple::active_legacy_apple_document_platform_services().trigger_crash_test(); + active_apple_document_platform_services().trigger_crash_test(); #elif defined(__ANDROID__) int *x = nullptr; *x = 42; LOG("%d", *x); @@ -115,7 +116,7 @@ public: #if defined(__IOS__) || defined(__OSX__) const auto family = pp::platform::current_platform_family(); if (family == pp::platform::PlatformFamily::ios || family == pp::platform::PlatformFamily::macos) - return pp::platform::apple::active_legacy_apple_document_platform_services().clipboard_text(); + return active_apple_document_platform_services().clipboard_text(); #endif #ifdef __ANDROID__ if (android_bridge_.clipboard_text) @@ -131,7 +132,7 @@ public: #if defined(__IOS__) || defined(__OSX__) const auto family = pp::platform::current_platform_family(); if (family == pp::platform::PlatformFamily::ios || family == pp::platform::PlatformFamily::macos) - return pp::platform::apple::active_legacy_apple_document_platform_services().set_clipboard_text(text); + return active_apple_document_platform_services().set_clipboard_text(text); #endif const std::string value(text); #ifdef __ANDROID__ @@ -147,7 +148,7 @@ public: void set_cursor_visible(bool visible) override { #if defined(__IOS__) || defined(__OSX__) - pp::platform::apple::active_legacy_apple_document_platform_services().set_cursor_visible(visible); + active_apple_document_platform_services().set_cursor_visible(visible); #else (void)visible; #endif @@ -156,7 +157,7 @@ public: void set_virtual_keyboard_visible(bool visible) override { #ifdef __IOS__ - pp::platform::apple::active_legacy_apple_document_platform_services().set_virtual_keyboard_visible(visible); + active_apple_document_platform_services().set_virtual_keyboard_visible(visible); #elif __ANDROID__ if (android_bridge_.set_virtual_keyboard_visible) android_bridge_.set_virtual_keyboard_visible(visible); @@ -184,7 +185,7 @@ public: void acquire_render_context() override { #if defined(__IOS__) || defined(__OSX__) - pp::platform::apple::active_legacy_apple_document_platform_services().acquire_render_context(); + active_apple_document_platform_services().acquire_render_context(); #elif __ANDROID__ if (android_bridge_.acquire_render_context) android_bridge_.acquire_render_context(); @@ -196,7 +197,7 @@ public: void release_render_context() override { #if defined(__IOS__) || defined(__OSX__) - pp::platform::apple::active_legacy_apple_document_platform_services().release_render_context(); + active_apple_document_platform_services().release_render_context(); #elif __ANDROID__ if (android_bridge_.release_render_context) android_bridge_.release_render_context(); @@ -206,7 +207,7 @@ public: void present_render_context() override { #if defined(__IOS__) || defined(__OSX__) - pp::platform::apple::active_legacy_apple_document_platform_services().present_render_context(); + active_apple_document_platform_services().present_render_context(); #elif __ANDROID__ if (android_bridge_.present_render_context) android_bridge_.present_render_context(); @@ -225,7 +226,7 @@ public: void bind_main_render_target() override { #if __IOS__ - pp::platform::apple::active_legacy_apple_document_platform_services().bind_main_render_target(); + active_apple_document_platform_services().bind_main_render_target(); #else bind_default_render_target(); #endif @@ -307,7 +308,7 @@ public: std::string_view data_path) override { #if defined(__IOS__) || defined(__OSX__) - return pp::platform::apple::active_legacy_apple_document_platform_services().document_browse_roots(work_path, data_path); + return active_apple_document_platform_services().document_browse_roots(work_path, data_path); #else return pp::platform::platform_document_browse_roots( pp::platform::current_platform_family(), @@ -321,7 +322,7 @@ public: if (!pp::platform::platform_saves_native_ui_state(pp::platform::current_platform_family())) return; #if defined(__IOS__) || defined(__OSX__) - pp::platform::apple::active_legacy_apple_document_platform_services().save_ui_state(); + active_apple_document_platform_services().save_ui_state(); #endif } @@ -348,9 +349,9 @@ public: void pick_image(pp::platform::PickedPathCallback callback) override { #ifdef __IOS__ - pp::platform::apple::active_legacy_apple_document_platform_services().pick_image(std::move(callback)); + active_apple_document_platform_services().pick_image(std::move(callback)); #elif __OSX__ - pp::platform::apple::active_legacy_apple_document_platform_services().pick_image(std::move(callback)); + active_apple_document_platform_services().pick_image(std::move(callback)); #elif __ANDROID__ if (android_bridge_.pick_file) android_bridge_.pick_file(std::move(callback)); @@ -367,9 +368,9 @@ public: void pick_file(std::vector file_types, pp::platform::PickedPathCallback callback) override { #ifdef __IOS__ - pp::platform::apple::active_legacy_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback)); + active_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback)); #elif __OSX__ - pp::platform::apple::active_legacy_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback)); + active_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback)); #elif __ANDROID__ if (android_bridge_.pick_file) android_bridge_.pick_file(std::move(callback)); @@ -387,7 +388,7 @@ public: void pick_save_file(std::vector file_types, pp::platform::PickedPathCallback callback) override { #if __OSX__ - pp::platform::apple::active_legacy_apple_document_platform_services().pick_save_file(std::move(file_types), std::move(callback)); + active_apple_document_platform_services().pick_save_file(std::move(file_types), std::move(callback)); #elif __ANDROID__ if (android_bridge_.pick_save_file) android_bridge_.pick_save_file(std::move(callback)); @@ -402,7 +403,7 @@ public: #ifdef __IOS__ (void)callback; #elif __OSX__ - pp::platform::apple::active_legacy_apple_document_platform_services().pick_directory(std::move(callback)); + active_apple_document_platform_services().pick_directory(std::move(callback)); #elif __ANDROID__ (void)callback; #else @@ -413,7 +414,7 @@ public: [[nodiscard]] bool supports_working_directory_picker() override { #if defined(__IOS__) || defined(__OSX__) - return pp::platform::apple::active_legacy_apple_document_platform_services().supports_working_directory_picker(); + return active_apple_document_platform_services().supports_working_directory_picker(); #else return pp::platform::platform_supports_working_directory_picker( pp::platform::current_platform_family()); @@ -423,7 +424,7 @@ public: [[nodiscard]] std::string format_working_directory_path(std::string_view path) override { #if defined(__IOS__) || defined(__OSX__) - return pp::platform::apple::active_legacy_apple_document_platform_services().format_working_directory_path(path); + return active_apple_document_platform_services().format_working_directory_path(path); #endif return std::string(path); } @@ -459,7 +460,7 @@ public: void start_sonarpen() override { #if __IOS__ - pp::platform::apple::active_legacy_apple_document_platform_services().start_sonarpen(); + active_apple_document_platform_services().start_sonarpen(); #endif } @@ -505,7 +506,7 @@ public: void display_file(std::string_view path) override { #if defined(__IOS__) || defined(__OSX__) - pp::platform::apple::active_legacy_apple_document_platform_services().display_file(path); + active_apple_document_platform_services().display_file(path); #else (void)path; #endif @@ -514,7 +515,7 @@ public: void share_file(std::string_view path) override { #if defined(__IOS__) || defined(__OSX__) - pp::platform::apple::active_legacy_apple_document_platform_services().share_file(path); + active_apple_document_platform_services().share_file(path); #else (void)path; #endif @@ -523,7 +524,7 @@ public: void request_app_close() override { #ifdef __OSX__ - pp::platform::apple::active_legacy_apple_document_platform_services().request_app_close(); + active_apple_document_platform_services().request_app_close(); #elif __LINUX__ invoke_legacy_glfw_shell_callback(glfw_shell_.request_app_close); #endif @@ -556,7 +557,7 @@ public: const std::string value(path); const std::string name(suggested_name); #ifdef __IOS__ - pp::platform::apple::active_legacy_apple_document_platform_services().save_prepared_file( + active_apple_document_platform_services().save_prepared_file( value, name, std::move(callback)); @@ -567,6 +568,13 @@ public: } private: + [[nodiscard]] pp::platform::apple::AppleDocumentPlatformServices& active_apple_document_platform_services() const noexcept + { + if (apple_document_services_) + return apple_document_services_(); + return pp::platform::apple::active_legacy_apple_document_platform_services(); + } + [[nodiscard]] pp::platform::WebPlatformServices& active_web_platform_services() const noexcept { if (web_platform_services_) @@ -586,6 +594,7 @@ private: std::shared_ptr android_storage_paths_; #endif pp::platform::WebPlatformServices* web_platform_services_ = nullptr; + std::function apple_document_services_; }; } diff --git a/src/platform_legacy/legacy_platform_services.h b/src/platform_legacy/legacy_platform_services.h index ea7078b7..0fcb467b 100644 --- a/src/platform_legacy/legacy_platform_services.h +++ b/src/platform_legacy/legacy_platform_services.h @@ -5,6 +5,10 @@ #include "platform_api/platform_services.h" +namespace pp::platform::apple { +class AppleDocumentPlatformServices; +} + namespace pp::platform::legacy { struct LegacyGlfwPlatformShell { @@ -31,6 +35,7 @@ struct LegacyPlatformServicesConfig { LegacyAndroidPlatformBridge android_bridge; std::shared_ptr android_storage_paths; pp::platform::WebPlatformServices* web_platform_services = nullptr; + std::function apple_document_services; }; [[nodiscard]] std::unique_ptr create_platform_services(