Bind Apple platform services explicitly
This commit is contained in:
@@ -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<std::string> 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<std::string> 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<pp::platform::PlatformStoragePaths> android_storage_paths_;
|
||||
#endif
|
||||
pp::platform::WebPlatformServices* web_platform_services_ = nullptr;
|
||||
std::function<pp::platform::apple::AppleDocumentPlatformServices&()> apple_document_services_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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<pp::platform::PlatformStoragePaths> android_storage_paths;
|
||||
pp::platform::WebPlatformServices* web_platform_services = nullptr;
|
||||
std::function<pp::platform::apple::AppleDocumentPlatformServices&()> apple_document_services;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::unique_ptr<PlatformServices> create_platform_services(
|
||||
|
||||
Reference in New Issue
Block a user