mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 08:17:34 -04:00
windows sandbox_manager fix
This commit is contained in:
parent
83e7958caf
commit
1117e20e72
3 changed files with 95 additions and 9 deletions
42
project/scripts/platform.gd
Normal file
42
project/scripts/platform.gd
Normal file
|
@ -0,0 +1,42 @@
|
|||
extends Node
|
||||
class_name Platform
|
||||
|
||||
enum {
|
||||
WINDOWS,
|
||||
MACOS,
|
||||
LINUX_BSD,
|
||||
ANDROID,
|
||||
IOS,
|
||||
WEB
|
||||
}
|
||||
|
||||
|
||||
static func is_windows() -> bool:
|
||||
return get_platform() == WINDOWS
|
||||
|
||||
|
||||
static func is_linux() -> bool:
|
||||
return get_platform() == LINUX_BSD
|
||||
|
||||
|
||||
static func is_debug() -> bool:
|
||||
return OS.is_debug_build()
|
||||
|
||||
|
||||
static func get_platform() -> int:
|
||||
match OS.get_name():
|
||||
"Windows", "UWP":
|
||||
return WINDOWS
|
||||
"macOS":
|
||||
return MACOS
|
||||
"Linux", "FreeBSD", "NetBSD", "OpenBSD", "BSD":
|
||||
return LINUX_BSD
|
||||
"Android":
|
||||
return ANDROID
|
||||
"iOS":
|
||||
return IOS
|
||||
"Web":
|
||||
return WEB
|
||||
_:
|
||||
assert(false, "No such platform")
|
||||
return -1
|
|
@ -17,12 +17,16 @@ func get_executable_path() -> String:
|
|||
|
||||
|
||||
func get_filename() -> String:
|
||||
if OS.is_debug_build():
|
||||
if OS.get_name() == "Windows": return windows_debug
|
||||
else: return linux_debug
|
||||
else:
|
||||
if OS.get_name() == "Windows": return windows
|
||||
else: return linux
|
||||
var is_debug = Platform.is_debug()
|
||||
|
||||
match Platform.get_platform():
|
||||
Platform.WINDOWS:
|
||||
return windows_debug if is_debug else windows
|
||||
Platform.LINUX_BSD:
|
||||
return linux_debug if is_debug else linux
|
||||
_:
|
||||
assert(false, "Platform is not supported")
|
||||
return ""
|
||||
|
||||
|
||||
func exists() -> bool:
|
||||
|
|
|
@ -14,6 +14,16 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func start_sandbox(gate: Gate) -> void:
|
||||
match Platform.get_platform():
|
||||
Platform.WINDOWS:
|
||||
start_sandbox_windows(gate)
|
||||
Platform.LINUX_BSD:
|
||||
start_sandbox_linux(gate)
|
||||
_:
|
||||
assert(false, "Platform is not supported")
|
||||
|
||||
|
||||
func start_sandbox_linux(gate: Gate) -> void:
|
||||
if not snbx_executable.exists():
|
||||
Debug.logerr("Sandbox executable not found at " + snbx_executable.path); return
|
||||
if not snbx_env.zip_exists():
|
||||
|
@ -21,12 +31,9 @@ func start_sandbox(gate: Gate) -> void:
|
|||
|
||||
snbx_env.create_env(snbx_executable.path, gate)
|
||||
|
||||
# var pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
||||
# var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
||||
var args = [
|
||||
snbx_env.start.get_base_dir(), # cd to dir
|
||||
"--main-pack", snbx_env.main_pack,
|
||||
# "--gdext-libs-dir", shared_libs,
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height]
|
||||
]
|
||||
Debug.logclr(snbx_env.start + " " + " ".join(args), Color.DARK_VIOLET)
|
||||
|
@ -35,7 +42,34 @@ func start_sandbox(gate: Gate) -> void:
|
|||
gate_events.gate_entered_emit()
|
||||
|
||||
|
||||
func start_sandbox_windows(gate: Gate) -> void:
|
||||
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 shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
||||
var args = [
|
||||
"--main-pack", pack_file,
|
||||
"--gdext-libs-dir", shared_libs,
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height]
|
||||
]
|
||||
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DARK_VIOLET)
|
||||
sandbox_pid = OS.create_process(snbx_executable.path, args)
|
||||
|
||||
gate_events.gate_entered_emit()
|
||||
|
||||
|
||||
func kill_sandbox() -> void:
|
||||
match Platform.get_platform():
|
||||
Platform.WINDOWS:
|
||||
kill_sandbox_windows()
|
||||
Platform.LINUX_BSD:
|
||||
kill_sandbox_linux()
|
||||
_:
|
||||
assert(false, "Platform is not supported")
|
||||
|
||||
|
||||
func kill_sandbox_linux() -> void:
|
||||
if sandbox_pid == 0: return
|
||||
|
||||
var pids = snbx_env.get_subprocesses(sandbox_pid)
|
||||
|
@ -48,5 +82,11 @@ func kill_sandbox() -> void:
|
|||
snbx_env.clean()
|
||||
|
||||
|
||||
func kill_sandbox_windows() -> void:
|
||||
if OS.is_process_running(sandbox_pid):
|
||||
OS.kill(sandbox_pid)
|
||||
Debug.logclr("Process killed " + str(sandbox_pid), Color.DIM_GRAY)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
kill_sandbox()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue