| … | … | @@ -0,0 +1 @@ |
| 1 | {} |
| … | … | @@ -0,0 +1,91 @@ |
| 1 | extends HTTPRequest | |
| 2 | ||
| 3 | signal loaded_data(data) | |
| 4 | signal loading_data(url) | |
| 5 | signal failed_load(url, error) | |
| 6 | signal starting_gateway() | |
| 7 | signal started_gateway(pid) | |
| 8 | ||
| 9 | var processPID = 0 | |
| 10 | var storageDirectory = defaultDirectory() | |
| 11 | ||
| 12 | # Called when the node enters the scene tree for the first time. | |
| 13 | func _ready(): | |
| 14 | pass # Replace with function body. | |
| 15 | ||
| 16 | func _notification(what): | |
| 17 | if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: | |
| 18 | cleanupGateway() | |
| 19 | pass | |
| 20 | ||
| 21 | func cleanupGateway(): | |
| 22 | if processPID == 0: | |
| 23 | print('Gateway already closed ' + str(processPID)) | |
| 24 | return | |
| 25 | print('Cleaning up gateway ' + str(processPID)) | |
| 26 | OS.kill(processPID) | |
| 27 | pass | |
| 28 | ||
| 29 | func setupGateway(): | |
| 30 | emit_signal("starting_gateway") | |
| 31 | var executiblePath = getExecutiblePath() | |
| 32 | var executibleFile = File.new() | |
| 33 | ||
| 34 | executibleFile.open(executiblePath, File.READ) | |
| 35 | ||
| 36 | var path = executibleFile.get_path_absolute() | |
| 37 | executibleFile.close() | |
| 38 | ||
| 39 | var args = ["run", "--no-persist"] | |
| 40 | ||
| 41 | print("Starting gateway from " + path) | |
| 42 | ||
| 43 | # Start the hyper-gateway in a process | |
| 44 | processPID = OS.execute(path, args, false) | |
| 45 | ||
| 46 | # Sleep for a bit while the gateway loads | |
| 47 | # TODO: Find a better indicator like polling the HTTP server socket | |
| 48 | OS.delay_msec(2000) | |
| 49 | ||
| 50 | print("Started gateway at " + str(processPID)) | |
| 51 | emit_signal("started_gateway", processPID) | |
| 52 | pass | |
| 53 | ||
| 54 | func ensureSetup(): | |
| 55 | if processPID != 0: return | |
| 56 | setupGateway() | |
| 57 | pass | |
| 58 | ||
| 59 | func getExecutiblePath(): | |
| 60 | var name = OS.get_name() | |
| 61 | if name == 'X11': return "res://hyper-gateway/hyper-gateway-linux" | |
| 62 | if name == 'OSX': return "res://hyper-gateway/hyper-gateway-macos" | |
| 63 | if name == 'Windows': return "res://hyper-gateway/hyper-gateway-windows.exe" | |
| 64 | push_error("Can not start gateway, invalid operating system " + name) | |
| 65 | pass | |
| 66 | ||
| 67 | func defaultDirectory(): | |
| 68 | var dir = Directory.new() | |
| 69 | dir.open('user://gateway-data/') | |
| 70 | return dir.get_current_dir() | |
| 71 | pass | |
| 72 | ||
| 73 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 74 | #func _process(delta): | |
| 75 | # pass | |
| 76 | ||
| 77 | func requestHyper(url): | |
| 78 | ensureSetup() | |
| 79 | var toload = url.replace("hyper://", "http://127.0.0.1:4973/hyper/") | |
| 80 | print("Loading " + toload) | |
| 81 | request(toload) | |
| 82 | pass | |
| 83 | ||
| 84 | func _on_request_completed(result, response_code, headers, body): | |
| 85 | print("Response Code ", response_code) | |
| 86 | if response_code != 200: | |
| 87 | var message = body.get_string_from_utf8() | |
| 88 | print("Error message:", message) | |
| 89 | emit_signal("failed_load", result, message) | |
| 90 | else: emit_signal("loaded_data", body.get_string_from_utf8()) | |
| 91 | pass # Replace with function body. |
| … | … | @@ -0,0 +1,87 @@ |
| 1 | [gd_scene load_steps=6 format=2] | |
| 2 | ||
| 3 | [ext_resource path="res://src/URLBar.gd" type="Script" id=1] | |
| 4 | [ext_resource path="res://src/GatewayRequest.gd" type="Script" id=2] | |
| 5 | [ext_resource path="res://src/StatusLabel.gd" type="Script" id=3] | |
| 6 | [ext_resource path="res://src/Output.gd" type="Script" id=4] | |
| 7 | [ext_resource path="res://src/ResizeRoot.gd" type="Script" id=5] | |
| 8 | ||
| 9 | [node name="Control" type="VBoxContainer"] | |
| 10 | script = ExtResource( 5 ) | |
| 11 | __meta__ = { | |
| 12 | "_edit_use_anchors_": false | |
| 13 | } | |
| 14 | ||
| 15 | [node name="Title" type="Label" parent="."] | |
| 16 | margin_right = 280.0 | |
| 17 | margin_bottom = 14.0 | |
| 18 | size_flags_horizontal = 4 | |
| 19 | text = "Enter your `hyper://` URL and press `Load`" | |
| 20 | align = 1 | |
| 21 | __meta__ = { | |
| 22 | "_edit_use_anchors_": false | |
| 23 | } | |
| 24 | ||
| 25 | [node name="HBoxContainer" type="HBoxContainer" parent="."] | |
| 26 | margin_top = 18.0 | |
| 27 | margin_right = 280.0 | |
| 28 | margin_bottom = 42.0 | |
| 29 | alignment = 1 | |
| 30 | ||
| 31 | [node name="URLBar" type="LineEdit" parent="HBoxContainer"] | |
| 32 | margin_right = 234.0 | |
| 33 | margin_bottom = 24.0 | |
| 34 | size_flags_horizontal = 3 | |
| 35 | text = "hyper://blog.mauve.moe/" | |
| 36 | caret_blink = true | |
| 37 | caret_blink_speed = 0.5 | |
| 38 | script = ExtResource( 1 ) | |
| 39 | __meta__ = { | |
| 40 | "_edit_use_anchors_": false | |
| 41 | } | |
| 42 | ||
| 43 | [node name="LoadButton" type="Button" parent="HBoxContainer"] | |
| 44 | margin_left = 238.0 | |
| 45 | margin_right = 280.0 | |
| 46 | margin_bottom = 24.0 | |
| 47 | text = "Load" | |
| 48 | __meta__ = { | |
| 49 | "_edit_use_anchors_": false | |
| 50 | } | |
| 51 | ||
| 52 | [node name="ScrollContainer" type="ScrollContainer" parent="."] | |
| 53 | margin_top = 46.0 | |
| 54 | margin_right = 280.0 | |
| 55 | margin_bottom = 46.0 | |
| 56 | size_flags_vertical = 3 | |
| 57 | scroll_horizontal_enabled = false | |
| 58 | ||
| 59 | [node name="Output" type="RichTextLabel" parent="ScrollContainer"] | |
| 60 | margin_right = 280.0 | |
| 61 | size_flags_horizontal = 3 | |
| 62 | size_flags_vertical = 3 | |
| 63 | script = ExtResource( 4 ) | |
| 64 | ||
| 65 | [node name="StatusLabel" type="Label" parent="."] | |
| 66 | margin_top = 50.0 | |
| 67 | margin_right = 280.0 | |
| 68 | margin_bottom = 64.0 | |
| 69 | text = "Status: Waiting" | |
| 70 | script = ExtResource( 3 ) | |
| 71 | __meta__ = { | |
| 72 | "_edit_use_anchors_": false | |
| 73 | } | |
| 74 | ||
| 75 | [node name="HyperLoad" type="HTTPRequest" parent="."] | |
| 76 | script = ExtResource( 2 ) | |
| 77 | ||
| 78 | [connection signal="text_entered" from="HBoxContainer/URLBar" to="HBoxContainer/URLBar" method="_on_URLBar_text_entered"] | |
| 79 | [connection signal="url" from="HBoxContainer/URLBar" to="HyperLoad" method="requestHyper"] | |
| 80 | [connection signal="pressed" from="HBoxContainer/LoadButton" to="HBoxContainer/URLBar" method="navigate"] | |
| 81 | [connection signal="failed_load" from="HyperLoad" to="StatusLabel" method="setError"] | |
| 82 | [connection signal="loaded_data" from="HyperLoad" to="StatusLabel" method="setLoaded"] | |
| 83 | [connection signal="loaded_data" from="HyperLoad" to="ScrollContainer/Output" method="setContent"] | |
| 84 | [connection signal="loading_data" from="HyperLoad" to="StatusLabel" method="setLoadingData"] | |
| 85 | [connection signal="request_completed" from="HyperLoad" to="HyperLoad" method="_on_request_completed"] | |
| 86 | [connection signal="started_gateway" from="HyperLoad" to="StatusLabel" method="setGatewayLoaded"] | |
| 87 | [connection signal="starting_gateway" from="HyperLoad" to="StatusLabel" method="setGatewayLoading"] |
| … | … | @@ -0,0 +1,5 @@ |
| 1 | extends RichTextLabel | |
| 2 | ||
| 3 | func setContent(data): | |
| 4 | text = data | |
| 5 | pass # Replace with function body. |
| … | … | @@ -0,0 +1,23 @@ |
| 1 | extends VBoxContainer | |
| 2 | ||
| 3 | ||
| 4 | # Declare member variables here. Examples: | |
| 5 | # var a = 2 | |
| 6 | # var b = "text" | |
| 7 | ||
| 8 | ||
| 9 | # Called when the node enters the scene tree for the first time. | |
| 10 | func _ready(): | |
| 11 | get_tree().get_root().connect("size_changed", self, "fitParent") | |
| 12 | fitParent() | |
| 13 | pass # Replace with function body. | |
| 14 | ||
| 15 | func fitParent(): | |
| 16 | var root = get_tree().get_root() | |
| 17 | var rootSize = root.get_size() | |
| 18 | print(rootSize) | |
| 19 | self.set_size(rootSize) | |
| 20 | pass | |
| 21 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 22 | #func _process(delta): | |
| 23 | # pass |
| … | … | @@ -0,0 +1,38 @@ |
| 1 | extends Label | |
| 2 | ||
| 3 | ||
| 4 | # Declare member variables here. Examples: | |
| 5 | # var a = 2 | |
| 6 | # var b = "text" | |
| 7 | ||
| 8 | ||
| 9 | # Called when the node enters the scene tree for the first time. | |
| 10 | func _ready(): | |
| 11 | pass # Replace with function body. | |
| 12 | ||
| 13 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 14 | #func _process(delta): | |
| 15 | # pass | |
| 16 | ||
| 17 | func setLoaded(data): | |
| 18 | text = "Status: Loaded" | |
| 19 | pass # Replace with function body. | |
| 20 | ||
| 21 | func setLoading(url): | |
| 22 | text = "Status: Loading " + url | |
| 23 | pass # Replace with function body. | |
| 24 | ||
| 25 | ||
| 26 | func setError(url, error): | |
| 27 | text = "Status: Failed Load" + error | |
| 28 | pass # Replace with function body. | |
| 29 | ||
| 30 | ||
| 31 | func setGatewayLoading(): | |
| 32 | text = "Status: Starting Gateway" | |
| 33 | pass # Replace with function body. | |
| 34 | ||
| 35 | ||
| 36 | func setGatewayLoaded(pid): | |
| 37 | text = "Status: Gateway Loaded" | |
| 38 | pass # Replace with function body. |
| … | … | @@ -0,0 +1,29 @@ |
| 1 | extends LineEdit | |
| 2 | ||
| 3 | signal url(url) | |
| 4 | ||
| 5 | # Declare member variables here. Examples: | |
| 6 | # var a = 2 | |
| 7 | # var b = "text" | |
| 8 | ||
| 9 | ||
| 10 | # Called when the node enters the scene tree for the first time. | |
| 11 | func _ready(): | |
| 12 | pass # Replace with function body. | |
| 13 | ||
| 14 | ||
| 15 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 16 | #func _process(delta): | |
| 17 | # pass | |
| 18 | ||
| 19 | ||
| 20 | func navigate(): | |
| 21 | var url = text | |
| 22 | if url.begins_with("hyper://"): | |
| 23 | emit_signal("url", url) | |
| 24 | pass # Replace with function body. | |
| 25 | ||
| 26 | ||
| 27 | func _on_URLBar_text_entered(new_text): | |
| 28 | navigate() | |
| 29 | pass # Replace with function body. |