Inject Android bridge into legacy platform services
This commit is contained in:
@@ -12,16 +12,6 @@
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "main.h"
|
||||
void displayKeyboard(bool pShow);
|
||||
void android_async_lock();
|
||||
void android_async_swap();
|
||||
void android_async_unlock();
|
||||
void android_attach_jni();
|
||||
void android_detach_jni();
|
||||
void android_pick_file(std::function<void(std::string)> callback);
|
||||
void android_pick_file_save(std::function<void(std::string)> callback);
|
||||
std::string android_get_clipboard();
|
||||
bool android_set_clipboard(const std::string& s);
|
||||
#elif __APPLE__
|
||||
#include <Foundation/Foundation.h>
|
||||
void delete_all_files_in_path(const std::string& source_path);
|
||||
@@ -50,6 +40,7 @@ class LegacyPlatformServices final : public pp::platform::PlatformServices {
|
||||
public:
|
||||
explicit LegacyPlatformServices(pp::platform::legacy::LegacyPlatformServicesConfig config = {})
|
||||
: glfw_shell_(std::move(config.glfw_shell))
|
||||
, android_bridge_(std::move(config.android_bridge))
|
||||
#ifdef __ANDROID__
|
||||
, android_storage_paths_(std::move(config.android_storage_paths))
|
||||
#endif
|
||||
@@ -127,7 +118,9 @@ public:
|
||||
return pp::platform::apple::active_legacy_apple_document_platform_services().clipboard_text();
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
return android_get_clipboard();
|
||||
if (android_bridge_.clipboard_text)
|
||||
return android_bridge_.clipboard_text();
|
||||
return {};
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
@@ -142,7 +135,9 @@ public:
|
||||
#endif
|
||||
const std::string value(text);
|
||||
#ifdef __ANDROID__
|
||||
return android_set_clipboard(value);
|
||||
if (android_bridge_.set_clipboard_text)
|
||||
return android_bridge_.set_clipboard_text(value);
|
||||
return false;
|
||||
#else
|
||||
(void)value;
|
||||
return false;
|
||||
@@ -163,7 +158,8 @@ public:
|
||||
#ifdef __IOS__
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().set_virtual_keyboard_visible(visible);
|
||||
#elif __ANDROID__
|
||||
displayKeyboard(visible);
|
||||
if (android_bridge_.set_virtual_keyboard_visible)
|
||||
android_bridge_.set_virtual_keyboard_visible(visible);
|
||||
#else
|
||||
(void)visible;
|
||||
#endif
|
||||
@@ -172,14 +168,16 @@ public:
|
||||
void attach_ui_thread() override
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
android_attach_jni();
|
||||
if (android_bridge_.attach_ui_thread)
|
||||
android_bridge_.attach_ui_thread();
|
||||
#endif
|
||||
}
|
||||
|
||||
void detach_ui_thread() override
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
android_detach_jni();
|
||||
if (android_bridge_.detach_ui_thread)
|
||||
android_bridge_.detach_ui_thread();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -188,7 +186,8 @@ public:
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().acquire_render_context();
|
||||
#elif __ANDROID__
|
||||
android_async_lock();
|
||||
if (android_bridge_.acquire_render_context)
|
||||
android_bridge_.acquire_render_context();
|
||||
#elif __LINUX__ || __WEB__
|
||||
invoke_legacy_glfw_shell_callback(glfw_shell_.acquire_render_context);
|
||||
#endif
|
||||
@@ -199,7 +198,8 @@ public:
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().release_render_context();
|
||||
#elif __ANDROID__
|
||||
android_async_unlock();
|
||||
if (android_bridge_.release_render_context)
|
||||
android_bridge_.release_render_context();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -208,7 +208,8 @@ public:
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().present_render_context();
|
||||
#elif __ANDROID__
|
||||
android_async_swap();
|
||||
if (android_bridge_.present_render_context)
|
||||
android_bridge_.present_render_context();
|
||||
#elif __LINUX__ || __WEB__
|
||||
invoke_legacy_glfw_shell_callback(glfw_shell_.present_render_context);
|
||||
#endif
|
||||
@@ -351,7 +352,8 @@ public:
|
||||
#elif __OSX__
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().pick_image(std::move(callback));
|
||||
#elif __ANDROID__
|
||||
android_pick_file(callback);
|
||||
if (android_bridge_.pick_file)
|
||||
android_bridge_.pick_file(std::move(callback));
|
||||
#elif __LINUX__
|
||||
if (auto p = tinyfd_openFileDialog("Open File", "", 0, nullptr, nullptr, false))
|
||||
invoke_picked_path_if_selected(p, callback);
|
||||
@@ -369,7 +371,8 @@ public:
|
||||
#elif __OSX__
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback));
|
||||
#elif __ANDROID__
|
||||
android_pick_file(callback);
|
||||
if (android_bridge_.pick_file)
|
||||
android_bridge_.pick_file(std::move(callback));
|
||||
#elif __LINUX__
|
||||
if (auto p = tinyfd_openFileDialog("Open File", "", 0, nullptr, nullptr, false))
|
||||
invoke_picked_path_if_selected(p, callback);
|
||||
@@ -386,7 +389,8 @@ public:
|
||||
#if __OSX__
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().pick_save_file(std::move(file_types), std::move(callback));
|
||||
#elif __ANDROID__
|
||||
android_pick_file_save(callback);
|
||||
if (android_bridge_.pick_save_file)
|
||||
android_bridge_.pick_save_file(std::move(callback));
|
||||
#else
|
||||
(void)file_types;
|
||||
(void)callback;
|
||||
@@ -577,6 +581,7 @@ private:
|
||||
}
|
||||
|
||||
pp::platform::legacy::LegacyGlfwPlatformShell glfw_shell_;
|
||||
pp::platform::legacy::LegacyAndroidPlatformBridge android_bridge_;
|
||||
#ifdef __ANDROID__
|
||||
std::shared_ptr<pp::platform::PlatformStoragePaths> android_storage_paths_;
|
||||
#endif
|
||||
|
||||
@@ -13,8 +13,22 @@ struct LegacyGlfwPlatformShell {
|
||||
std::function<void()> request_app_close;
|
||||
};
|
||||
|
||||
struct LegacyAndroidPlatformBridge {
|
||||
std::function<std::string()> clipboard_text;
|
||||
std::function<bool(std::string_view text)> set_clipboard_text;
|
||||
std::function<void(bool visible)> set_virtual_keyboard_visible;
|
||||
std::function<void()> attach_ui_thread;
|
||||
std::function<void()> detach_ui_thread;
|
||||
std::function<void()> acquire_render_context;
|
||||
std::function<void()> release_render_context;
|
||||
std::function<void()> present_render_context;
|
||||
std::function<void(PickedPathCallback callback)> pick_file;
|
||||
std::function<void(PickedPathCallback callback)> pick_save_file;
|
||||
};
|
||||
|
||||
struct LegacyPlatformServicesConfig {
|
||||
LegacyGlfwPlatformShell glfw_shell;
|
||||
LegacyAndroidPlatformBridge android_bridge;
|
||||
std::shared_ptr<pp::platform::PlatformStoragePaths> android_storage_paths;
|
||||
pp::platform::WebPlatformServices* web_platform_services = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user