Integrate dialog export and Apple service teams
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
#include "platform_legacy/legacy_platform_services.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "app_core/document_platform_io.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "log.h"
|
||||
#include "platform_apple/apple_platform_services.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
@@ -52,14 +52,6 @@ void webgl_sync();
|
||||
|
||||
namespace {
|
||||
|
||||
void invoke_picked_path_if_selected(
|
||||
const std::string& path,
|
||||
const std::function<void(std::string path)>& callback)
|
||||
{
|
||||
if (pp::app::plan_picked_path(path) == pp::app::PickedPathAction::invoke_callback)
|
||||
callback(path);
|
||||
}
|
||||
|
||||
#ifdef __WEB__
|
||||
class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices {
|
||||
public:
|
||||
@@ -102,6 +94,79 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
[[nodiscard]] NSMutableArray<NSString*>* apple_file_types_array(const std::vector<std::string>& file_types)
|
||||
{
|
||||
NSMutableArray<NSString*>* types = [NSMutableArray arrayWithCapacity:file_types.size()];
|
||||
for (const auto& type : file_types)
|
||||
{
|
||||
[types addObject:[NSString stringWithCString:type.c_str() encoding:NSUTF8StringEncoding]];
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::platform::apple::AppleDocumentPlatformServices& active_apple_document_platform_services()
|
||||
{
|
||||
#ifdef __IOS__
|
||||
static pp::platform::apple::AppleDocumentPlatformServices services(
|
||||
pp::platform::PlatformFamily::ios,
|
||||
[] {
|
||||
pp::platform::apple::AppleDocumentPickerBridge bridge;
|
||||
bridge.pick_image = [](pp::platform::PickedPathCallback callback) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[App::I->ios_view pick_photo:callback];
|
||||
});
|
||||
};
|
||||
bridge.pick_file = [](
|
||||
std::vector<std::string> file_types,
|
||||
pp::platform::PickedPathCallback callback) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[App::I->ios_view pick_file:apple_file_types_array(file_types) then:callback];
|
||||
});
|
||||
};
|
||||
return bridge;
|
||||
}());
|
||||
return services;
|
||||
#else
|
||||
static pp::platform::apple::AppleDocumentPlatformServices services(
|
||||
pp::platform::PlatformFamily::macos,
|
||||
[] {
|
||||
pp::platform::apple::AppleDocumentPickerBridge bridge;
|
||||
bridge.pick_file = [](
|
||||
std::vector<std::string> file_types,
|
||||
pp::platform::PickedPathCallback callback) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
const std::string path = [App::I->osx_view pick_file:apple_file_types_array(file_types)];
|
||||
callback(path);
|
||||
});
|
||||
};
|
||||
bridge.pick_save_file = [](
|
||||
std::vector<std::string> file_types,
|
||||
pp::platform::PickedPathCallback callback) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
const std::string path = [App::I->osx_view pick_file_save:apple_file_types_array(file_types)];
|
||||
callback(path);
|
||||
});
|
||||
};
|
||||
bridge.pick_directory = [](pp::platform::PickedPathCallback callback) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
const std::string path = [App::I->osx_view pick_dir];
|
||||
callback(path);
|
||||
});
|
||||
};
|
||||
bridge.format_working_directory_path = [](std::string_view path) {
|
||||
char path_buffer[4096] = {};
|
||||
if (realpath(std::string(path).c_str(), path_buffer))
|
||||
return std::string(path_buffer);
|
||||
return std::string(path);
|
||||
};
|
||||
return bridge;
|
||||
}());
|
||||
return services;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// DEBT-0017: fallback for platforms that do not inject PlatformServices yet.
|
||||
class LegacyPlatformServices final : public pp::platform::PlatformServices {
|
||||
public:
|
||||
@@ -376,10 +441,14 @@ public:
|
||||
std::string_view work_path,
|
||||
std::string_view data_path) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
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(),
|
||||
work_path,
|
||||
data_path);
|
||||
#endif
|
||||
}
|
||||
|
||||
void save_ui_state() override
|
||||
@@ -414,15 +483,9 @@ public:
|
||||
void pick_image(pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[App::I->ios_view pick_photo:callback];
|
||||
});
|
||||
active_apple_document_platform_services().pick_image(std::move(callback));
|
||||
#elif __OSX__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSArray* fileTypes = [NSArray arrayWithObjects:@"png", @"PNG", @"jpg", @"JPG", @"jpeg", nil];
|
||||
std::string path = [App::I->osx_view pick_file:fileTypes];
|
||||
invoke_picked_path_if_selected(path, callback);
|
||||
});
|
||||
active_apple_document_platform_services().pick_image(std::move(callback));
|
||||
#elif __ANDROID__
|
||||
android_pick_file(callback);
|
||||
#elif __LINUX__
|
||||
@@ -438,20 +501,9 @@ public:
|
||||
void pick_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:file_types.size()];
|
||||
for (const auto& t : file_types)
|
||||
[fileTypes addObject:[NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]];
|
||||
[App::I->ios_view pick_file:fileTypes then:callback];
|
||||
});
|
||||
active_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback));
|
||||
#elif __OSX__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:file_types.size()];
|
||||
for (const auto& t : file_types)
|
||||
[fileTypes addObject:[NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]];
|
||||
std::string path = [App::I->osx_view pick_file:fileTypes];
|
||||
invoke_picked_path_if_selected(path, callback);
|
||||
});
|
||||
active_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback));
|
||||
#elif __ANDROID__
|
||||
android_pick_file(callback);
|
||||
#elif __LINUX__
|
||||
@@ -468,13 +520,7 @@ public:
|
||||
void pick_save_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
#if __OSX__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:file_types.size()];
|
||||
for (const auto& t : file_types)
|
||||
[fileTypes addObject:[NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]];
|
||||
std::string path = [App::I->osx_view pick_file_save:fileTypes];
|
||||
invoke_picked_path_if_selected(path, callback);
|
||||
});
|
||||
active_apple_document_platform_services().pick_save_file(std::move(file_types), std::move(callback));
|
||||
#elif __ANDROID__
|
||||
android_pick_file_save(callback);
|
||||
#else
|
||||
@@ -488,10 +534,7 @@ public:
|
||||
#ifdef __IOS__
|
||||
(void)callback;
|
||||
#elif __OSX__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
std::string path = [App::I->osx_view pick_dir];
|
||||
invoke_picked_path_if_selected(path, callback);
|
||||
});
|
||||
active_apple_document_platform_services().pick_directory(std::move(callback));
|
||||
#elif __ANDROID__
|
||||
(void)callback;
|
||||
#else
|
||||
@@ -501,16 +544,18 @@ public:
|
||||
|
||||
[[nodiscard]] bool supports_working_directory_picker() override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
return active_apple_document_platform_services().supports_working_directory_picker();
|
||||
#else
|
||||
return pp::platform::platform_supports_working_directory_picker(
|
||||
pp::platform::current_platform_family());
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string format_working_directory_path(std::string_view path) override
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
char path_buffer[4096] = {};
|
||||
if (realpath(std::string(path).c_str(), path_buffer))
|
||||
return path_buffer;
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
return active_apple_document_platform_services().format_working_directory_path(path);
|
||||
#endif
|
||||
return std::string(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user