mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-09-03 05:25:48 -04:00
remove platform specific sandbox code
This commit is contained in:
parent
faa9344ded
commit
632e718b2b
2 changed files with 12 additions and 111 deletions
|
@ -32,10 +32,10 @@ func start_bootup_check() -> void:
|
||||||
|
|
||||||
|
|
||||||
func bootup_check() -> void:
|
func bootup_check() -> void:
|
||||||
if snbx_manager.is_sandbox_running(): return
|
if snbx_manager.is_process_running(): return
|
||||||
|
|
||||||
bootup_timer.stop()
|
bootup_timer.stop()
|
||||||
on_timeout("Gate crashed")
|
on_timeout("Gate crashed on bootup")
|
||||||
|
|
||||||
|
|
||||||
func start_heartbeat_timer() -> void:
|
func start_heartbeat_timer() -> void:
|
||||||
|
@ -48,7 +48,7 @@ func restart_heartbeat_timer() -> void:
|
||||||
|
|
||||||
|
|
||||||
func heartbeat_check() -> void:
|
func heartbeat_check() -> void:
|
||||||
var error = "Gate is not responding" if snbx_manager.is_sandbox_running() else "Gate crashed"
|
var error = "Gate is not responding" if snbx_manager.is_process_running() else "Gate crashed on heartbeat"
|
||||||
|
|
||||||
heartbeat_timer.stop()
|
heartbeat_timer.stop()
|
||||||
on_timeout(error)
|
on_timeout(error)
|
||||||
|
|
|
@ -17,16 +17,7 @@ func _ready() -> void:
|
||||||
|
|
||||||
|
|
||||||
func start_sandbox(gate: Gate) -> void:
|
func start_sandbox(gate: Gate) -> void:
|
||||||
var pipe: Dictionary
|
var pipe = start_process(gate)
|
||||||
match Platform.get_platform():
|
|
||||||
Platform.WINDOWS:
|
|
||||||
pipe = start_sandbox_windows(gate)
|
|
||||||
Platform.LINUX_BSD:
|
|
||||||
pipe = start_sandbox_linux(gate)
|
|
||||||
Platform.MACOS:
|
|
||||||
pipe = start_sandbox_macos(gate)
|
|
||||||
_:
|
|
||||||
assert(false, "Platform is not supported")
|
|
||||||
if pipe.is_empty(): return
|
if pipe.is_empty(): return
|
||||||
|
|
||||||
snbx_pid = pipe["pid"]
|
snbx_pid = pipe["pid"]
|
||||||
|
@ -34,47 +25,12 @@ func start_sandbox(gate: Gate) -> void:
|
||||||
gate_events.gate_entered_emit()
|
gate_events.gate_entered_emit()
|
||||||
|
|
||||||
|
|
||||||
func start_sandbox_linux(gate: Gate) -> Dictionary:
|
func start_process(gate: Gate) -> Dictionary:
|
||||||
if not snbx_executable.exists():
|
if not snbx_executable.exists():
|
||||||
Debug.logerr("Sandbox executable not found at " + snbx_executable.path); return {}
|
Debug.logerr("Sandbox executable not found at " + snbx_executable.path); return {}
|
||||||
|
|
||||||
var pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
if Platform.get_platform() == Platform.WINDOWS:
|
||||||
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
DirAccess.make_dir_recursive_absolute(IPC_FOLDER)
|
||||||
var args = [
|
|
||||||
"--main-pack", pack_file,
|
|
||||||
"--resolution", "%dx%d" % [render_result.width, render_result.height],
|
|
||||||
"--url", gate.url,
|
|
||||||
"--verbose"
|
|
||||||
]
|
|
||||||
if not shared_libs.is_empty(): args += ["--gdext-libs-dir", shared_libs]
|
|
||||||
|
|
||||||
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY)
|
|
||||||
return OS.execute_with_pipe(snbx_executable.path, args)
|
|
||||||
|
|
||||||
|
|
||||||
func start_sandbox_windows(gate: Gate) -> Dictionary:
|
|
||||||
if not snbx_executable.exists():
|
|
||||||
Debug.logerr("Sandbox executable not found at " + snbx_executable.path); return {}
|
|
||||||
|
|
||||||
DirAccess.make_dir_recursive_absolute(IPC_FOLDER) # TODO: move to snbx_env
|
|
||||||
|
|
||||||
var pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
|
||||||
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
|
||||||
var args = [
|
|
||||||
"--main-pack", pack_file,
|
|
||||||
"--resolution", "%dx%d" % [render_result.width, render_result.height],
|
|
||||||
"--url", gate.url,
|
|
||||||
"--verbose"
|
|
||||||
]
|
|
||||||
if not shared_libs.is_empty(): args += ["--gdext-libs-dir", shared_libs]
|
|
||||||
|
|
||||||
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY)
|
|
||||||
return OS.execute_with_pipe(snbx_executable.path, args)
|
|
||||||
|
|
||||||
|
|
||||||
func start_sandbox_macos(gate: Gate) -> Dictionary:
|
|
||||||
if not snbx_executable.exists():
|
|
||||||
Debug.logerr("Sandbox executable not found at " + snbx_executable.path); return {}
|
|
||||||
|
|
||||||
var pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
var pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
||||||
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
||||||
|
@ -91,70 +47,15 @@ func start_sandbox_macos(gate: Gate) -> Dictionary:
|
||||||
|
|
||||||
|
|
||||||
func kill_sandbox() -> void:
|
func kill_sandbox() -> void:
|
||||||
match Platform.get_platform():
|
if OS.is_process_running(snbx_pid):
|
||||||
Platform.WINDOWS:
|
OS.kill(snbx_pid)
|
||||||
kill_sandbox_windows()
|
Debug.logclr("Process killed " + str(snbx_pid), Color.DIM_GRAY)
|
||||||
Platform.LINUX_BSD:
|
|
||||||
kill_sandbox_linux()
|
|
||||||
Platform.MACOS:
|
|
||||||
kill_sandbox_macos()
|
|
||||||
_:
|
|
||||||
assert(false, "Platform is not supported")
|
|
||||||
|
|
||||||
snbx_logger.call_thread_safe("cleanup")
|
snbx_logger.call_thread_safe("cleanup")
|
||||||
|
|
||||||
|
|
||||||
func kill_sandbox_linux() -> void:
|
func is_process_running() -> bool:
|
||||||
if snbx_pid == 0: return
|
return OS.is_process_running(snbx_pid)
|
||||||
|
|
||||||
var pids = snbx_env.get_subprocesses(snbx_pid)
|
|
||||||
pids.append(snbx_pid)
|
|
||||||
|
|
||||||
for pid in pids:
|
|
||||||
OS.kill(pid)
|
|
||||||
Debug.logclr("Process killed " + str(pid), Color.DIM_GRAY)
|
|
||||||
|
|
||||||
snbx_env.clean()
|
|
||||||
|
|
||||||
|
|
||||||
func kill_sandbox_windows() -> void:
|
|
||||||
if OS.is_process_running(snbx_pid):
|
|
||||||
OS.kill(snbx_pid)
|
|
||||||
Debug.logclr("Process killed " + str(snbx_pid), Color.DIM_GRAY)
|
|
||||||
|
|
||||||
|
|
||||||
func kill_sandbox_macos() -> void:
|
|
||||||
if OS.is_process_running(snbx_pid):
|
|
||||||
OS.kill(snbx_pid)
|
|
||||||
Debug.logclr("Process killed " + str(snbx_pid), Color.DIM_GRAY)
|
|
||||||
|
|
||||||
|
|
||||||
func is_sandbox_running() -> bool:
|
|
||||||
if snbx_pid == 0: return false
|
|
||||||
|
|
||||||
var output = []
|
|
||||||
match Platform.get_platform():
|
|
||||||
Platform.WINDOWS:
|
|
||||||
# tasklist /fi "PID eq 1234" /fi "STATUS eq RUNNING" | findstr 1234
|
|
||||||
OS.execute("cmd.exe", ["/c", "tasklist", "/fi", "PID eq " + str(snbx_pid), "/fi", "STATUS eq RUNNING", "|", "findstr", str(snbx_pid)], output)
|
|
||||||
return not output[0].is_empty()
|
|
||||||
|
|
||||||
Platform.LINUX_BSD:
|
|
||||||
# ps -o stat= -p 1234
|
|
||||||
OS.execute("ps", ["-o", "stat=", "-p", snbx_pid], output)
|
|
||||||
var stat = output[0].substr(0, 1)
|
|
||||||
return not stat.is_empty() and not stat in ["Z", "T"]
|
|
||||||
|
|
||||||
Platform.MACOS:
|
|
||||||
# ps -o stat= -p 1234
|
|
||||||
OS.execute("ps", ["-o", "stat=", "-p", snbx_pid], output)
|
|
||||||
var stat = output[0].substr(0, 1)
|
|
||||||
return not stat.is_empty() and not stat in ["Z", "T"]
|
|
||||||
|
|
||||||
_:
|
|
||||||
assert(false, "Platform is not supported")
|
|
||||||
|
|
||||||
return false
|
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue