Route prepared file saves through platform services

This commit is contained in:
2026-06-03 04:29:58 +02:00
parent e10e16f491
commit 2ea850cbcc
10 changed files with 109 additions and 27 deletions

View File

@@ -189,6 +189,10 @@ public:
void pick_dir(std::function<void(std::string path)> callback);
void display_file(std::string path);
void share_file(std::string path);
void save_prepared_file(
std::string path,
std::string suggested_name,
std::function<void(const std::string& path, bool saved)> callback);
void set_platform_services(pp::platform::PlatformServices* services) noexcept;
[[nodiscard]] pp::platform::PlatformServices* platform_services() const noexcept;
void showKeyboard();

View File

@@ -23,8 +23,6 @@
#include "oculus_vr.h"
#elif __WEB__
void webgl_pick_file(std::function<void(std::string)> callback);
void webgl_pick_file_save(const std::string& path,
const std::string& name, std::function<void(bool)> callback);
void webgl_sync();
#endif
@@ -459,7 +457,7 @@ void App::dialog_export(std::string ext)
//auto result = ovr_Media_ShareToFacebook("Sharing from PanoPainter on Oculus Quest", path.c_str(), ovrMediaContentType_Photo);
#elif __WEB__
ui_task([=]{
webgl_pick_file_save(target.path, target.suggested_name, [](bool success){ });
save_prepared_file(target.path, target.suggested_name, [](const std::string&, bool) { });
});
#endif
});

View File

@@ -31,11 +31,6 @@ namespace {
}
#ifdef __WEB__
void webgl_pick_file_save(const std::string& path,
const std::string& name, std::function<void(bool)> callback);
#endif
namespace {
[[nodiscard]] pp::platform::PlatformServices& active_platform_services()
@@ -187,10 +182,7 @@ void App::pick_file_save(const std::string& type, const std::string& default_nam
std::string path = tmp_path + "/" + default_name + ext;
std::thread([=]{
writer(path);
dispatch_async(dispatch_get_main_queue(), ^{
[ios_view pick_file_save:path];
});
callback(path, true);
save_prepared_file(path, default_name + ext, callback);
}).detach();
}
#elif __WEB__
@@ -201,7 +193,7 @@ void App::pick_file_save(const std::string& type, const std::string& default_nam
auto path = data_path + "/" + default_name + "." + type;
LOG("App::pick_file_save %s", path.c_str());
writer(path);
webgl_pick_file_save(path, default_name + "." + type, callback);
save_prepared_file(path, default_name + "." + type, std::move(callback));
}
#else
void App::pick_file_save(std::vector<std::string> types, std::function<void(std::string)> callback)
@@ -236,6 +228,19 @@ void App::share_file(std::string path)
active_platform_services().share_file(path);
}
void App::save_prepared_file(
std::string path,
std::string suggested_name,
std::function<void(const std::string& path, bool saved)> callback)
{
active_platform_services().save_prepared_file(
path,
suggested_name,
[callback = std::move(callback)](std::string saved_path, bool saved) {
callback(saved_path, saved);
});
}
bool App::mouse_down(int button, float x, float y, float pressure, kEventSource source, bool eraser)
{
redraw = true;

View File

@@ -8,6 +8,7 @@
namespace pp::platform {
using PickedPathCallback = std::function<void(std::string path)>;
using PreparedFileCallback = std::function<void(std::string path, bool saved)>;
class PlatformServices {
public:
@@ -23,6 +24,10 @@ public:
virtual void pick_file(std::vector<std::string> file_types, PickedPathCallback callback) = 0;
virtual void pick_save_file(std::vector<std::string> file_types, PickedPathCallback callback) = 0;
virtual void pick_directory(PickedPathCallback callback) = 0;
virtual void save_prepared_file(
std::string_view path,
std::string_view suggested_name,
PreparedFileCallback callback) = 0;
};
}

View File

@@ -202,6 +202,29 @@ public:
});
#else
(void)value;
#endif
}
void save_prepared_file(
std::string_view path,
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback) override
{
const std::string value(path);
const std::string name(suggested_name);
#ifdef __IOS__
(void)name;
dispatch_async(dispatch_get_main_queue(), ^{
[App::I->ios_view pick_file_save:value];
});
callback(value, true);
#elif __WEB__
webgl_pick_file_save(value, name, [callback = std::move(callback), value](bool success) {
callback(value, success);
});
#else
(void)name;
callback(value, false);
#endif
}
};

View File

@@ -201,6 +201,15 @@ public:
const std::string path = open_directory();
invoke_selected_path(path, callback);
}
void save_prepared_file(
std::string_view path,
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback) override
{
(void)suggested_name;
callback(std::string(path), false);
}
};
}