#include "SDL_internal.h"
#ifdef SDL_PLATFORM_EMSCRIPTEN
#include "../SDL_main_callbacks.h"
#include <emscripten/emscripten.h>
EM_JS_DEPS(sdlrunapp, "$dynCall,$stringToNewUTF8");
EMSCRIPTEN_KEEPALIVE int CallSDLEmscriptenMainFunction(int argc, char *argv[], SDL_main_func mainFunction)
{
return SDL_CallMainFunction(argc, argv, mainFunction);
}
int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserved)
{
(void)reserved;
MAIN_THREAD_EM_ASM({
var parms = new URLSearchParams(window.location.search);
for (const [key, value] of parms) {
if (key.startsWith("SDL_")) {
var ckey = stringToNewUTF8(key);
var cvalue = stringToNewUTF8(value);
if ((ckey != 0) && (cvalue != 0)) {
dynCall('iiii', $0, [ckey, cvalue, 1]);
}
_Emscripten_force_free(ckey); _Emscripten_force_free(cvalue);
}
}
}, SDL_setenv_unsafe);
#ifdef SDL_EMSCRIPTEN_PERSISTENT_PATH_STRING
MAIN_THREAD_EM_ASM({
const persistent_path = UTF8ToString($0);
const argc = $1;
const argv = $2;
const mainFunction = $3;
FS.mkdirTree(persistent_path);
FS.mount(IDBFS, { autoPersist: true }, persistent_path);
FS.syncfs(true, function(err) {
if (err) {
console.error(`WARNING: Failed to populate persistent store at '${persistent_path}' (${err.name}: ${err.message}). Save games likely lost?`);
}
_CallSDLEmscriptenMainFunction(argc, argv, mainFunction); });
}, SDL_EMSCRIPTEN_PERSISTENT_PATH_STRING, argc, argv, mainFunction);
emscripten_exit_with_live_runtime();
return 0;
#else
return CallSDLEmscriptenMainFunction(argc, argv, mainFunction);
#endif
}
#endif