summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-08-06 15:34:51 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-09-23 09:51:06 +0200
commit7d045b8543d6fa84a3e00a44c75014a3bf183216 (patch)
treeb416ff5aea1fd93c5a278543f7fbf00cc784c772
parent27ab97501b4b39ce200c0609071d2dd12d7b7c12 (diff)
Expose request_quit method to JS in HTML5 export.
-rw-r--r--platform/javascript/javascript_main.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index a30d84a52c..464712ca6d 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -39,6 +39,17 @@
static OS_JavaScript *os = nullptr;
static uint64_t target_ticks = 0;
+extern "C" EMSCRIPTEN_KEEPALIVE void _request_quit_callback(char *p_filev[], int p_filec) {
+ DisplayServerJavaScript *ds = DisplayServerJavaScript::get_singleton();
+ if (ds) {
+ Variant event = int(DisplayServer::WINDOW_EVENT_CLOSE_REQUEST);
+ Variant *eventp = &event;
+ Variant ret;
+ Callable::CallError ce;
+ ds->window_event_callback.call((const Variant **)&eventp, 1, ret, ce);
+ }
+}
+
void exit_callback() {
emscripten_cancel_main_loop(); // After this, we can exit!
Main::cleanup();
@@ -102,6 +113,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();