2020-05-09 19:07:31 +02:00
|
|
|
tool
|
|
|
|
extends EditorPlugin
|
|
|
|
|
2022-05-22 08:18:01 +02:00
|
|
|
const LIBS := [
|
|
|
|
"javascript.32.wasm",
|
|
|
|
"linux.32.so",
|
|
|
|
"linux.64.so",
|
|
|
|
"osx.64.dylib",
|
|
|
|
"windows.32.dll",
|
|
|
|
"windows.64.dll"
|
|
|
|
]
|
|
|
|
const LIB_DIR := "res://addons/godot_xterm/native/bin"
|
|
|
|
const ZIP_FILE := "%s/libgodot-xterm-release.zip" % LIB_DIR
|
|
|
|
|
|
|
|
const Unzipper := preload("./util/unzipper.gd")
|
|
|
|
|
|
|
|
signal _native_libs_checked
|
|
|
|
|
2021-07-02 19:27:34 +02:00
|
|
|
var pty_supported := OS.get_name() in ["X11", "Server", "OSX"]
|
2020-09-22 10:31:46 +02:00
|
|
|
var asciicast_import_plugin
|
2021-07-18 18:11:31 +02:00
|
|
|
var xrdb_import_plugin
|
2021-07-11 17:32:13 +02:00
|
|
|
var terminal_panel: Control
|
2020-09-22 10:31:46 +02:00
|
|
|
|
|
|
|
|
2022-05-22 08:18:01 +02:00
|
|
|
# Downloads release builds of native libraries from GitHub if available, otherwise
|
|
|
|
# you will need to compile them yourself.
|
|
|
|
func _download_native_libs():
|
|
|
|
var dir := Directory.new()
|
|
|
|
var skip := true
|
|
|
|
|
|
|
|
for lib in LIBS:
|
|
|
|
if not dir.file_exists("%s/libgodot-xterm.%s" % [LIB_DIR, lib]):
|
|
|
|
print("GodotXterm: Downloading native library libgodot-xterm.%s..." % lib)
|
|
|
|
skip = false
|
|
|
|
|
|
|
|
if skip:
|
|
|
|
emit_signal("_native_libs_checked")
|
|
|
|
return
|
|
|
|
|
|
|
|
var config_file := ConfigFile.new()
|
|
|
|
config_file.load("res://addons/godot_xterm/plugin.cfg")
|
|
|
|
|
|
|
|
var http_request := HTTPRequest.new()
|
|
|
|
add_child(http_request)
|
|
|
|
http_request.connect("request_completed", self, "_on_http_request_completed", [http_request])
|
|
|
|
http_request.download_file = ZIP_FILE
|
|
|
|
http_request.request(
|
|
|
|
(
|
|
|
|
"https://github.com/lihop/godot-xterm/releases/download/v%s/libgodot-xterm-release.zip"
|
|
|
|
% config_file.get_value("plugin", "version")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_http_request_completed(
|
|
|
|
result: int,
|
|
|
|
response_code: int,
|
|
|
|
_headers: PoolStringArray,
|
|
|
|
_body: PoolByteArray,
|
|
|
|
http_request: HTTPRequest
|
|
|
|
):
|
|
|
|
http_request.queue_free()
|
|
|
|
var dir := Directory.new()
|
|
|
|
if result == OK and response_code == 200:
|
|
|
|
var unzipped := Unzipper.unzip(ZIP_FILE)
|
|
|
|
if unzipped.error != OK:
|
|
|
|
push_error("GodotXterm: Error unzipping file: %s" % ZIP_FILE)
|
|
|
|
else:
|
|
|
|
for path in unzipped.files:
|
|
|
|
var target := "%s/%s" % [LIB_DIR, path.get_file()]
|
|
|
|
if not dir.file_exists("%s/%s" % [LIB_DIR, path.get_file()]):
|
|
|
|
if dir.copy(path, target) == OK:
|
|
|
|
print("GodotXterm: Native library %s installed!" % path.get_file())
|
|
|
|
else:
|
|
|
|
push_error(
|
|
|
|
"GodotXterm: Error installing native library %s" % path.get_file()
|
|
|
|
)
|
|
|
|
dir.remove(path)
|
|
|
|
dir.remove("%s/libgodot-xterm-release" % LIB_DIR)
|
|
|
|
else:
|
|
|
|
push_warning(
|
|
|
|
"GodotXterm: Error downloading native libraries. Please compile them yourself."
|
|
|
|
)
|
|
|
|
dir.remove(ZIP_FILE)
|
|
|
|
push_warning("GodotXterm: Installed missing native libraries. A Godot restart may be required.")
|
|
|
|
emit_signal("_native_libs_checked")
|
|
|
|
|
|
|
|
|
2020-05-09 19:07:31 +02:00
|
|
|
func _enter_tree():
|
2022-05-22 08:18:01 +02:00
|
|
|
call_deferred("_download_native_libs")
|
|
|
|
yield(self, "_native_libs_checked")
|
|
|
|
|
2021-07-15 16:30:09 +02:00
|
|
|
asciicast_import_plugin = preload("./import_plugins/asciicast_import_plugin.gd").new()
|
2020-09-22 10:31:46 +02:00
|
|
|
add_import_plugin(asciicast_import_plugin)
|
2021-05-26 05:39:48 +02:00
|
|
|
|
2021-07-18 18:11:31 +02:00
|
|
|
xrdb_import_plugin = preload("./import_plugins/xrdb_import_plugin.gd").new()
|
|
|
|
add_import_plugin(xrdb_import_plugin)
|
|
|
|
|
2021-07-15 16:30:09 +02:00
|
|
|
var asciicast_script = preload("./resources/asciicast.gd")
|
2020-09-22 10:31:46 +02:00
|
|
|
add_custom_type("Asciicast", "Animation", asciicast_script, null)
|
2021-05-26 05:39:48 +02:00
|
|
|
|
2021-07-25 19:31:23 +02:00
|
|
|
var terminal_script = preload("./terminal.gd")
|
2021-07-15 16:30:09 +02:00
|
|
|
var terminal_icon = preload("./nodes/terminal/terminal_icon.svg")
|
2020-09-17 10:14:04 +02:00
|
|
|
add_custom_type("Terminal", "Control", terminal_script, terminal_icon)
|
2021-05-26 05:39:48 +02:00
|
|
|
|
2021-07-02 19:27:34 +02:00
|
|
|
if pty_supported:
|
2021-07-15 16:30:09 +02:00
|
|
|
var base_dir = get_script().resource_path.get_base_dir()
|
|
|
|
var pty_icon = load("%s/nodes/pty/pty_icon.svg" % base_dir)
|
2021-07-02 19:27:34 +02:00
|
|
|
var pty_script
|
|
|
|
match OS.get_name():
|
|
|
|
"X11", "Server", "OSX":
|
2021-07-25 19:31:23 +02:00
|
|
|
pty_script = load("%s/nodes/pty/pty.gd" % base_dir)
|
2021-07-02 19:27:34 +02:00
|
|
|
add_custom_type("PTY", "Node", pty_script, pty_icon)
|
2021-07-12 18:11:28 +02:00
|
|
|
var terminal_settings_script = preload("./editor_plugins/terminal/settings/terminal_settings.gd")
|
|
|
|
add_custom_type("TerminalSettings", "Resource", terminal_settings_script, null)
|
2021-07-11 17:32:13 +02:00
|
|
|
terminal_panel = preload("./editor_plugins/terminal/terminal_panel.tscn").instance()
|
2021-07-12 18:11:28 +02:00
|
|
|
terminal_panel.editor_plugin = self
|
2021-07-11 17:32:13 +02:00
|
|
|
terminal_panel.editor_interface = get_editor_interface()
|
|
|
|
add_control_to_bottom_panel(terminal_panel, "Terminal")
|
2020-05-09 19:07:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _exit_tree():
|
2020-09-22 10:31:46 +02:00
|
|
|
remove_import_plugin(asciicast_import_plugin)
|
|
|
|
asciicast_import_plugin = null
|
2021-05-26 05:39:48 +02:00
|
|
|
|
2021-07-18 18:11:31 +02:00
|
|
|
remove_import_plugin(xrdb_import_plugin)
|
|
|
|
xrdb_import_plugin = null
|
|
|
|
|
2020-09-22 10:31:46 +02:00
|
|
|
remove_custom_type("Asciicast")
|
2020-05-09 19:07:31 +02:00
|
|
|
remove_custom_type("Terminal")
|
2021-07-02 19:27:34 +02:00
|
|
|
|
|
|
|
if pty_supported:
|
|
|
|
remove_custom_type("PTY")
|
2021-07-12 18:11:28 +02:00
|
|
|
remove_custom_type("TerminalSettings")
|
2021-07-11 17:32:13 +02:00
|
|
|
remove_control_from_bottom_panel(terminal_panel)
|
|
|
|
terminal_panel.free()
|