mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-03 19:04:40 +01:00
Some output from the Linux VM!!
This commit is contained in:
parent
49a3f880fe
commit
ad8d8f50d1
6 changed files with 53 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
|||
extends Node
|
||||
|
||||
var tmp_prefix = OS.get_user_data_dir() + "/tmp/"
|
||||
var tmp_prefix = get_tmp_prefix()
|
||||
var global_shell
|
||||
var fake_editor
|
||||
|
||||
|
@ -17,6 +17,12 @@ var state = {}
|
|||
|
||||
var mutex
|
||||
|
||||
func get_tmp_prefix():
|
||||
if OS.get_name() == "Web":
|
||||
return "/tmp/"
|
||||
else:
|
||||
OS.get_user_data_dir() + "/tmp/"
|
||||
|
||||
func _ready():
|
||||
mutex = Mutex.new()
|
||||
load_state()
|
||||
|
|
|
@ -96,6 +96,8 @@ func careful_delete(path_inside):
|
|||
# Windows treats paths case-insensitively:
|
||||
expected_prefix = expected_prefix.to_lower()
|
||||
path_inside = path_inside.to_lower()
|
||||
elif os == "Web":
|
||||
expected_prefix = "/tmp"
|
||||
|
||||
if path_inside.substr(0,expected_prefix.length()) != expected_prefix:
|
||||
helpers.crash("Refusing to delete directory %s that does not start with %s" % [path_inside, expected_prefix])
|
||||
|
|
|
@ -12,7 +12,7 @@ func _init():
|
|||
# Create required directories and move into the tmp directory.
|
||||
_cwd = "/tmp"
|
||||
run("mkdir -p '%s/repos'" % game.tmp_prefix)
|
||||
_cwd = game.tmp_prefixls
|
||||
_cwd = game.tmp_prefix
|
||||
|
||||
func cd(dir):
|
||||
_cwd = dir
|
||||
|
@ -39,6 +39,13 @@ func run_async(command, crash_on_fail=true):
|
|||
|
||||
return shell_command
|
||||
|
||||
func run_async_web(command, crash_on_fail=true):
|
||||
var shell_command = ShellCommand.new()
|
||||
shell_command.command = command
|
||||
shell_command.crash_on_fail = crash_on_fail
|
||||
run_async_thread(shell_command)
|
||||
return shell_command
|
||||
|
||||
func run_async_thread(shell_command):
|
||||
var debug = false
|
||||
|
||||
|
@ -86,22 +93,20 @@ func run_async_thread(shell_command):
|
|||
helpers.write_file(script_path, hacky_command)
|
||||
result = helpers.exec(_shell_binary(), [script_path], crash_on_fail)
|
||||
elif _os == "Web":
|
||||
hacky_command = hacky_command.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n")
|
||||
#hacky_command = hacky_command.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n")
|
||||
#var js_code = "await run_in_vm('" + hacky_command + "')"
|
||||
#print(js_code)
|
||||
#var output = JavaScriptBridge.eval(js_code, true)
|
||||
|
||||
var output = JavaScriptBridge.eval("testy()")
|
||||
#var output = JavaScriptBridge.eval("testy()")
|
||||
|
||||
#print(hacky_command)
|
||||
#var output = web_shell.run_in_vm(hacky_command)
|
||||
|
||||
result = {}
|
||||
result["output"] = output
|
||||
result["exit_code"] = 0
|
||||
shell_command.js_callback = JavaScriptBridge.create_callback(Callable(shell_command, "callback"))
|
||||
web_shell.run_in_vm(hacky_command).then(shell_command.js_callback)
|
||||
else:
|
||||
helpers.crash("Unimplemented OS: %s" % _os)
|
||||
|
||||
if _os != "Web":
|
||||
if debug:
|
||||
print(result["output"])
|
||||
|
||||
|
@ -117,25 +122,8 @@ func _shell_binary():
|
|||
else:
|
||||
helpers.crash("Unsupported OS: %s" % _os)
|
||||
|
||||
#var _t
|
||||
#func run_async(command):
|
||||
# _t = Thread.new()
|
||||
# _t.start(self, "run_async_thread", command)
|
||||
#
|
||||
#func run_async_thread(command):
|
||||
# var port = 1000 + (randi() % 1000)
|
||||
# var s = TCP_Server.new()
|
||||
# s.listen(port)
|
||||
# var _pid = OS.execute("ncat", ["127.0.0.1", str(port), "-c", command], false, [], true)
|
||||
# while not s.is_connection_available():
|
||||
# pass
|
||||
# var c = s.take_connection()
|
||||
# while c.get_status() == StreamPeerTCP.STATUS_CONNECTED:
|
||||
# read_from(c)
|
||||
# OS.delay_msec(1000/30)
|
||||
# read_from(c)
|
||||
# c.disconnect_from_host()
|
||||
# s.stop()
|
||||
func callback(args):
|
||||
print(args)
|
||||
|
||||
func read_from(c):
|
||||
var total_available = c.get_available_bytes()
|
||||
|
|
|
@ -8,7 +8,15 @@ var output
|
|||
var exit_code
|
||||
var crash_on_fail = true
|
||||
var thread
|
||||
var js_callback # For JavaScriptBridge
|
||||
|
||||
func _unused():
|
||||
# This is just to suppress a warning about the signal never being emitted.
|
||||
emit_signal("done")
|
||||
|
||||
func callback(_output):
|
||||
#print(_output)
|
||||
print(_output[0])
|
||||
output = _output[0]
|
||||
exit_code = 0
|
||||
emit_signal("done")
|
||||
|
|
|
@ -90,16 +90,16 @@ func send_command(command):
|
|||
|
||||
shell.cd(repository.path)
|
||||
|
||||
#var cmd = shell.run_async(command, false)
|
||||
#await cmd.done
|
||||
#call_deferred("command_done", cmd)
|
||||
var cmd = shell.run_async_web(command, false)
|
||||
await cmd.done
|
||||
call_deferred("command_done", cmd)
|
||||
|
||||
var output = shell.run(command, false)
|
||||
var shell_command = ShellCommand.new()
|
||||
shell_command.exit_code = 0
|
||||
shell_command.output = output
|
||||
shell_command.command = command
|
||||
command_done(shell_command)
|
||||
# var output = shell.run(command, false)
|
||||
# var shell_command = ShellCommand.new()
|
||||
# shell_command.exit_code = 0
|
||||
# shell_command.output = output
|
||||
# shell_command.command = command
|
||||
# command_done(shell_command)
|
||||
|
||||
func command_done(cmd):
|
||||
if cmd.exit_code == 0:
|
||||
|
|
|
@ -3,11 +3,11 @@ var emulator;
|
|||
// Whether or not to restore the VM state from a file. Set to false to perform a regular boot.
|
||||
let restoreState = true;
|
||||
|
||||
async function testy() {
|
||||
return await new Promise((resolve, reject) => {
|
||||
function testy(cmd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve("testy");
|
||||
}, 1000);
|
||||
resolve("testy!!" + cmd);
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
window.testy = testy;
|
||||
|
@ -40,7 +40,7 @@ function run_in_vm(cmd) {
|
|||
});
|
||||
}
|
||||
window.run_in_vm = run_in_vm;
|
||||
window.web_shell = { run_in_vm: run_in_vm };
|
||||
window.web_shell = { run_in_vm, testy };
|
||||
|
||||
/*
|
||||
|
||||
|
|
Loading…
Reference in a new issue