Move request_quit to javascript_main.

This commit is contained in:
Fabio Alessandrelli 2020-07-28 07:39:26 +02:00
parent c8859f0463
commit c610ad3739
2 changed files with 13 additions and 6 deletions

View file

@ -50,6 +50,12 @@ extern "C" EMSCRIPTEN_KEEPALIVE void _drop_files_callback(char *p_filev[], int p
os->get_main_loop()->drop_files(files);
}
extern "C" EMSCRIPTEN_KEEPALIVE void _request_quit_callback(char *p_filev[], int p_filec) {
if (os && os->get_main_loop()) {
os->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
}
}
void exit_callback() {
emscripten_cancel_main_loop(); // After this, we can exit!
Main::cleanup();
@ -132,6 +138,12 @@ extern "C" EMSCRIPTEN_KEEPALIVE void main_after_fs_sync(char *p_idbfs_err) {
ResourceLoader::set_abort_on_missing_resources(false);
Main::start();
os->get_main_loop()->init();
// Expose method for requesting quit.
EM_ASM({
Module['request_quit'] = function() {
ccall("_request_quit_callback", null, []);
};
});
// Immediately run the first iteration.
// We are inside an animation frame, we want to immediately draw on the newly setup canvas.
main_loop_callback();

View file

@ -1077,16 +1077,11 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
Module.listeners['drop'] = Module.drop_handler; // Defined in native/utils.js
canvas.addEventListener('dragover', Module.listeners['dragover'], false);
canvas.addEventListener('drop', Module.listeners['drop'], false);
// Quit request
Module['request_quit'] = function() {
send_notification(notifications[notifications.length - 1]);
};
},
MainLoop::NOTIFICATION_WM_MOUSE_ENTER,
MainLoop::NOTIFICATION_WM_MOUSE_EXIT,
MainLoop::NOTIFICATION_WM_FOCUS_IN,
MainLoop::NOTIFICATION_WM_FOCUS_OUT,
MainLoop::NOTIFICATION_WM_QUIT_REQUEST
MainLoop::NOTIFICATION_WM_FOCUS_OUT
);
/* clang-format on */