Ported: Fix 'save & restart' logic for the Android Editor - m4gr3d

5aab84befb
This commit is contained in:
Relintai 2022-11-30 18:12:43 +01:00
parent 615529eb6b
commit 19efacc416
3 changed files with 60 additions and 29 deletions

View File

@ -30,6 +30,7 @@
#include "main.h"
#include "core/config/project_settings.h"
#include "core/crypto/crypto.h"
#include "core/input/input_map.h"
#include "core/io/file_access_network.h"
@ -39,13 +40,12 @@
#include "core/io/ip.h"
#include "core/io/resource_loader.h"
#include "core/object/message_queue.h"
#include "core/object/script_debugger_local.h"
#include "core/object/script_language.h"
#include "core/os/dir_access.h"
#include "core/os/os.h"
#include "core/os/time.h"
#include "core/config/project_settings.h"
#include "core/register_core_types.h"
#include "core/object/script_debugger_local.h"
#include "core/object/script_language.h"
#include "core/string/translation.h"
#include "core/version.h"
#include "drivers/register_driver_types.h"
@ -2418,6 +2418,9 @@ void Main::cleanup(bool p_force) {
OS::get_singleton()->delete_main_loop();
// Storing it for use when restarting as it's being cleared right below.
const String execpath = OS::get_singleton()->get_executable_path();
OS::get_singleton()->_cmdline.clear();
OS::get_singleton()->_execpath = "";
OS::get_singleton()->_local_clipboard = "";
@ -2478,10 +2481,9 @@ void Main::cleanup(bool p_force) {
if (OS::get_singleton()->is_restart_on_exit_set()) {
//attempt to restart with arguments
String exec = OS::get_singleton()->get_executable_path();
List<String> args = OS::get_singleton()->get_restart_on_exit_arguments();
OS::ProcessID pid = 0;
OS::get_singleton()->execute(exec, args, false, &pid);
OS::get_singleton()->execute(execpath, args, false, &pid);
OS::get_singleton()->set_restart_on_exit(false, List<String>()); //clear list (uses memory)
}

View File

@ -32,6 +32,7 @@ package net.relintai.pandemonium.editor
import net.relintai.pandemonium.pandemonium.FullScreenPandemoniumApp
import net.relintai.pandemonium.pandemonium.utils.PermissionsUtil
import net.relintai.pandemonium.pandemonium.utils.ProcessPhoenix
import android.Manifest
import android.content.Intent
@ -40,6 +41,7 @@ import android.os.Build
import android.os.Bundle
import android.os.Debug
import android.os.Environment
import android.util.Log
import android.widget.Toast
import androidx.window.layout.WindowMetricsCalculator;
@ -58,11 +60,16 @@ import kotlin.math.min
*/
open class PandemoniumEditor : FullScreenPandemoniumApp() {
companion object {
private val TAG = PandemoniumEditor::class.java.simpleName
private const val WAIT_FOR_DEBUGGER = false
private const val COMMAND_LINE_PARAMS = "command_line_params"
private const val EDITOR_ARG = "--editor"
private const val EDITOR_ARG_SHORT = "-e"
private const val PROJECT_MANAGER_ARG = "--project-manager"
private const val PROJECT_MANAGER_ARG_SHORT = "-p"
}
private val commandLineParams = ArrayList<String>()
@ -106,13 +113,13 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
var launchAdjacent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode || isLargeScreen)
for (arg in args) {
if (EDITOR_ARG == arg) {
if (EDITOR_ARG == arg || EDITOR_ARG_SHORT == arg) {
targetClass = PandemoniumEditor::class.java
launchAdjacent = false
break
}
if (PROJECT_MANAGER_ARG == arg) {
if (PROJECT_MANAGER_ARG == arg || PROJECT_MANAGER_ARG_SHORT == arg) {
targetClass = PandemoniumProjectManager::class.java
launchAdjacent = false
break
@ -126,8 +133,14 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
newInstance.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT)
}
if (targetClass == javaClass) {
Log.d(TAG, "Restarting $targetClass")
ProcessPhoenix.triggerRebirth(this, newInstance)
} else {
Log.d(TAG, "Starting $targetClass")
startActivity(newInstance)
}
}
// Get the screen's density scale
protected val isLargeScreen: Boolean

View File

@ -112,6 +112,40 @@ static void _initialize_java_modules() {
}
}
static void _terminate(JNIEnv *env, bool p_restart = false) {
step.set(-1); // Ensure no further steps are attempted and no further events are sent
// lets cleanup
if (java_class_wrapper) {
memdelete(java_class_wrapper);
}
if (input_handler) {
delete input_handler;
}
// Whether restarting is handled by 'Main::cleanup()'
bool restart_on_cleanup = false;
if (os_android) {
restart_on_cleanup = os_android->is_restart_on_exit_set();
os_android->main_loop_end();
Main::cleanup();
delete os_android;
}
if (pandemonium_io_java) {
delete pandemonium_io_java;
}
if (pandemonium_java) {
pandemonium_java->destroy_offscreen_gl(env);
if (!restart_on_cleanup) {
if (p_restart) {
pandemonium_java->restart(env);
} else {
pandemonium_java->force_quit(env);
}
}
delete pandemonium_java;
}
}
extern "C" {
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height) {
@ -149,23 +183,7 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_
}
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_ondestroy(JNIEnv *env, jclass clazz) {
// lets cleanup
if (java_class_wrapper) {
memdelete(java_class_wrapper);
}
if (pandemonium_io_java) {
delete pandemonium_io_java;
}
if (pandemonium_java) {
pandemonium_java->destroy_offscreen_gl(env);
delete pandemonium_java;
}
if (input_handler) {
delete input_handler;
}
if (os_android) {
delete os_android;
}
_terminate(env, false);
}
JNIEXPORT jboolean JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) {
@ -227,9 +245,7 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_
os_android->set_offscreen_gl_available(pandemonium_java->create_offscreen_gl(env));
} else {
// GL context recreated because it was lost; restart app to let it reload everything
step.set(-1); // Ensure no further steps are attempted and no further events are sent
os_android->main_loop_end();
pandemonium_java->restart(env);
_terminate(env, true);
}
}
}
@ -273,7 +289,7 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_
os_android->process_gyroscope(gyroscope);
if (os_android->main_loop_iterate()) {
pandemonium_java->force_quit(env);
_terminate(env, false);
}
}