Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
emscripten: Send SDL_APP_TERMINATING before unload (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Beuc committed Apr 9, 2020
1 parent 9f738f5 commit aa72f38
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/video/emscripten/SDL_emscriptenevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,16 @@ Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChang
return 0;
}

static const char*
Emscripten_HandleBeforeUnload(int eventType, const void *reserved, void *userData)
{
/* This event will need to be handled synchronously, e.g. using
SDL_AddEventWatch, as the page is being closed *now*. */
/* No need to send a SDL_QUIT, the app won't get control again. */
SDL_SendAppEvent(SDL_APP_TERMINATING);
return ""; /* don't trigger confirmation dialog */
}

void
Emscripten_RegisterEventHandlers(SDL_WindowData *data)
{
Expand Down Expand Up @@ -684,6 +694,8 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data)
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, data, 0, Emscripten_HandleResize);

emscripten_set_visibilitychange_callback(data, 0, Emscripten_HandleVisibilityChange);

emscripten_set_beforeunload_callback(data, Emscripten_HandleBeforeUnload);
}

void
Expand Down Expand Up @@ -726,6 +738,8 @@ Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 0, NULL);

emscripten_set_visibilitychange_callback(NULL, 0, NULL);

emscripten_set_beforeunload_callback(NULL, NULL);
}

#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
Expand Down

0 comments on commit aa72f38

Please sign in to comment.