Route native close through platform services

This commit is contained in:
2026-06-03 04:36:10 +02:00
parent 537f0dcb2f
commit 22006eaf47
10 changed files with 47 additions and 19 deletions

View File

@@ -27,7 +27,6 @@ bool async_lock_try();
void async_lock();
void win32_async_swap();
void async_unlock();
void destroy_window();
void win32_renderdoc_frame_start();
void win32_renderdoc_frame_end();
#elif __LINUX__
@@ -273,16 +272,7 @@ bool App::request_close()
m->m_message->set_text("Do you want to close without saving?");
m->btn_ok->m_text->set_text("Yes");
m->btn_ok->on_click = [this](Node*) {
#ifdef _WIN32
destroy_window();
//PostQuitMessage(0);
#elif __OSX__
dispatch_async(dispatch_get_main_queue(), ^{
[osx_view close];
});
#elif __LINUX__
glfwSetWindowShouldClose(glfw_window, GLFW_TRUE);
#endif
request_app_close();
Canvas::I->m_unsaved = false;
};
m->btn_cancel->m_text->set_text("No");

View File

@@ -189,6 +189,7 @@ public:
void pick_dir(std::function<void(std::string path)> callback);
void display_file(std::string path);
void share_file(std::string path);
void request_app_close();
void save_prepared_file(
std::string path,
std::string suggested_name,

View File

@@ -214,6 +214,11 @@ void App::share_file(std::string path)
active_platform_services().share_file(path);
}
void App::request_app_close()
{
active_platform_services().request_app_close();
}
void App::save_prepared_file(
std::string path,
std::string suggested_name,

View File

@@ -20,6 +20,7 @@ public:
virtual void set_virtual_keyboard_visible(bool visible) = 0;
virtual void display_file(std::string_view path) = 0;
virtual void share_file(std::string_view path) = 0;
virtual void request_app_close() = 0;
virtual void pick_image(PickedPathCallback callback) = 0;
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;

View File

@@ -205,6 +205,17 @@ public:
#endif
}
void request_app_close() override
{
#ifdef __OSX__
dispatch_async(dispatch_get_main_queue(), ^{
[App::I->osx_view close];
});
#elif __LINUX__
glfwSetWindowShouldClose(App::I->glfw_window, GLFW_TRUE);
#endif
}
void save_prepared_file(
std::string_view path,
std::string_view suggested_name,

View File

@@ -7,6 +7,8 @@ extern HWND hWnd;
extern std::deque<std::packaged_task<void()>> main_tasklist;
extern std::mutex main_task_mutex;
void destroy_window();
namespace {
void show_cursor(bool visible)
@@ -176,6 +178,11 @@ public:
(void)path;
}
void request_app_close() override
{
destroy_window();
}
void pick_image(pp::platform::PickedPathCallback callback) override
{
const std::string path = open_file("Image Files (*.jpg, *.png)\0*.jpg;*.png");