OverviewFilesCommitsIssuesDocsReleasesPeers

hypergodot commits / 1ecbcee

Moved sources, embed binaries, auto-start hyper-gateway process
1ecbcee51997376532c304d33f0e8f7bfa523fd8
by mauve <ranger@mauve.moe> · 2021-05-27T05:57:01.000Z

Changed files (10) +274 -0

hyper-gateway/hyper-gateway-linux +0 -0
(no content changes — binary or rename)
hyper-gateway/hyper-gateway-macos +0 -0
(no content changes — binary or rename)
hyper-gateway/hyper-gateway-win.exe +0 -0
(no content changes — binary or rename)
package.json +1 -0
……@@ -0,0 +1 @@
1{}
src/GatewayRequest.gd +91 -0
……@@ -0,0 +1,91 @@
1extends HTTPRequest
2
3signal loaded_data(data)
4signal loading_data(url)
5signal failed_load(url, error)
6signal starting_gateway()
7signal started_gateway(pid)
8
9var processPID = 0
10var storageDirectory = defaultDirectory()
11
12# Called when the node enters the scene tree for the first time.
13func _ready():
14 pass # Replace with function body.
15
16func _notification(what):
17 if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
18 cleanupGateway()
19 pass
20
21func 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
29func 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
54func ensureSetup():
55 if processPID != 0: return
56 setupGateway()
57 pass
58
59func 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
67func 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
77func 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
84func _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.
src/HyperLoad.tscn +87 -0
……@@ -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"]
10script = ExtResource( 5 )
11__meta__ = {
12"_edit_use_anchors_": false
13}
14
15[node name="Title" type="Label" parent="."]
16margin_right = 280.0
17margin_bottom = 14.0
18size_flags_horizontal = 4
19text = "Enter your `hyper://` URL and press `Load`"
20align = 1
21__meta__ = {
22"_edit_use_anchors_": false
23}
24
25[node name="HBoxContainer" type="HBoxContainer" parent="."]
26margin_top = 18.0
27margin_right = 280.0
28margin_bottom = 42.0
29alignment = 1
30
31[node name="URLBar" type="LineEdit" parent="HBoxContainer"]
32margin_right = 234.0
33margin_bottom = 24.0
34size_flags_horizontal = 3
35text = "hyper://blog.mauve.moe/"
36caret_blink = true
37caret_blink_speed = 0.5
38script = ExtResource( 1 )
39__meta__ = {
40"_edit_use_anchors_": false
41}
42
43[node name="LoadButton" type="Button" parent="HBoxContainer"]
44margin_left = 238.0
45margin_right = 280.0
46margin_bottom = 24.0
47text = "Load"
48__meta__ = {
49"_edit_use_anchors_": false
50}
51
52[node name="ScrollContainer" type="ScrollContainer" parent="."]
53margin_top = 46.0
54margin_right = 280.0
55margin_bottom = 46.0
56size_flags_vertical = 3
57scroll_horizontal_enabled = false
58
59[node name="Output" type="RichTextLabel" parent="ScrollContainer"]
60margin_right = 280.0
61size_flags_horizontal = 3
62size_flags_vertical = 3
63script = ExtResource( 4 )
64
65[node name="StatusLabel" type="Label" parent="."]
66margin_top = 50.0
67margin_right = 280.0
68margin_bottom = 64.0
69text = "Status: Waiting"
70script = ExtResource( 3 )
71__meta__ = {
72"_edit_use_anchors_": false
73}
74
75[node name="HyperLoad" type="HTTPRequest" parent="."]
76script = 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"]
src/Output.gd +5 -0
……@@ -0,0 +1,5 @@
1extends RichTextLabel
2
3func setContent(data):
4 text = data
5 pass # Replace with function body.
src/ResizeRoot.gd +23 -0
……@@ -0,0 +1,23 @@
1extends 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.
10func _ready():
11 get_tree().get_root().connect("size_changed", self, "fitParent")
12 fitParent()
13 pass # Replace with function body.
14
15func 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
src/StatusLabel.gd +38 -0
……@@ -0,0 +1,38 @@
1extends 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.
10func _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
17func setLoaded(data):
18 text = "Status: Loaded"
19 pass # Replace with function body.
20
21func setLoading(url):
22 text = "Status: Loading " + url
23 pass # Replace with function body.
24
25
26func setError(url, error):
27 text = "Status: Failed Load" + error
28 pass # Replace with function body.
29
30
31func setGatewayLoading():
32 text = "Status: Starting Gateway"
33 pass # Replace with function body.
34
35
36func setGatewayLoaded(pid):
37 text = "Status: Gateway Loaded"
38 pass # Replace with function body.
src/URLBar.gd +29 -0
……@@ -0,0 +1,29 @@
1extends LineEdit
2
3signal 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.
11func _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
20func navigate():
21 var url = text
22 if url.begins_with("hyper://"):
23 emit_signal("url", url)
24 pass # Replace with function body.
25
26
27func _on_URLBar_text_entered(new_text):
28 navigate()
29 pass # Replace with function body.