Attempt to restart the app using Linux shell

This commit is contained in:
pelya
2017-04-07 23:42:25 +03:00
committed by Sergii Pylypenko
parent dc5684681e
commit 54e44bbe7a
2 changed files with 43 additions and 8 deletions

View File

@@ -921,6 +921,48 @@ exit_bootstrap:
free(sounddriver);
exit_normal:
if (_restart_game) {
#ifdef __ANDROID__
// This makes OpenTTD reset all it's settings for some reason, because the process is not killed and shared libraries are not unloaded.
//SDL_ANDROID_RestartMyself("restart-settings");
/*
pid_t parent = getpid();
pid_t pid = fork();
if (pid == -1) return ret;
if (pid > 0) {
usleep(300 * 1000);
exit(0);
} else {
setsid();
close(0);
close(1);
close(2);
execlp("/system/bin/sh", "/system/bin/sh", "-c", "sleep 2 ; am start --user -2 -n org.openttd.sdl/.MainActivity </dev/null >/dev/null 2>&1");
exit(0);
}
*/
DEBUG(misc, 0, "============ Restarting OpenTTD");
class restart
{
public:
static void run(void *)
{
const char *cmd = "$APPDIR/setsid /system/bin/sh -c 'echo Sleeping ; sleep 3 ; am start --user -3 -n org.openttd.sdl/.MainActivity' >$DATADIR/restart1.log 2>&1 </dev/null";
DEBUG(misc, 0, "============ Starting cmd: %s", cmd);
system(cmd);
DEBUG(misc, 0, "============ Cmd finished");
}
};
ThreadObject *t;
ThreadObject::New(&restart::run, NULL, &t, "ottd:restart");
DEBUG(misc, 0, "============ Sleeping 400 ms");
usleep(400 * 1000);
DEBUG(misc, 0, "============ Exiting");
exit(0);
#endif
}
free(BaseGraphics::ini_set);
free(BaseSounds::ini_set);
free(BaseMusic::ini_set);
@@ -939,13 +981,6 @@ exit_normal:
}
#endif /* ENABLE_NETWORK */
if (_restart_game) {
#ifdef __ANDROID__
// This makes OpenTTD reset all it's settings for some reason. Just abort and pretend we crashed
//SDL_ANDROID_RestartMyself("restart-settings");
#endif
}
return ret;
}

View File

@@ -13,4 +13,4 @@
- Draggable combo boxes.
- Changing screen color depth resets all settings to zero.
- Rearrange toolbar menus to have less buttons.