RetroDECK/tools/configurator/scripts/ToolsTab.gd

52 lines
1.9 KiB
GDScript3
Raw Normal View History

2024-09-10 11:17:04 +00:00
extends Control
@onready var http_request: HTTPRequest = HTTPRequest.new()
func _ready():
add_child(http_request)
http_request.request_completed.connect(_on_request_completed)
_connect_signals()
2024-09-10 17:13:53 +00:00
%backup_user_button.text += " - " + class_functions.rdhome + "/backup"
2024-09-10 11:17:04 +00:00
func _connect_signals() -> void:
%check_conn_button.pressed.connect(check_internet_connection)
2024-09-16 15:38:41 +00:00
%backup_user_button.pressed.connect(run_function.bind(%backup_user_button, "Start User Backup"))
2024-09-10 11:17:04 +00:00
2024-09-16 15:38:41 +00:00
func run_function(button: Button, message: String) -> void:
class_functions.logger("d",message)
match button.name:
"backup_user_button":
_run_backup(button)
func _run_backup(button: Button) -> void:
var original_txt = button.text
2024-09-10 17:13:53 +00:00
%progress_bar_backup.visible = true
2024-09-16 15:38:41 +00:00
button.text = "Backup Running"
2024-09-10 17:13:53 +00:00
var parameters = ["backup_retrodeck_userdata"]
var run_result = await class_functions.run_thread_command(class_functions.wrapper_command, parameters, true)
if run_result["exit_code"] == 0:
2024-09-16 15:38:41 +00:00
button.text = "Backup Complete - " + class_functions.rdhome + "/backup"
2024-09-10 17:13:53 +00:00
class_functions.logger("d","User Backup Completed")
await class_functions.wait(3.0)
2024-09-16 15:38:41 +00:00
button.text = original_txt
2024-09-10 17:13:53 +00:00
%progress_bar_backup.visible = false
else:
2024-09-16 15:38:41 +00:00
button.text = "Backup Failed"
2024-09-10 17:13:53 +00:00
class_functions.logger("e","User Backup Failed. " + run_result["exit_code"])
%progress_bar_backup.visible = false
2024-09-10 11:17:04 +00:00
func check_internet_connection():
2024-09-10 17:13:53 +00:00
class_functions.logger("i","Check Internet Connection")
2024-09-10 11:17:04 +00:00
%check_conn_button.text = "CHECK CONNECTION"
2024-09-10 14:33:58 +00:00
http_request.request("https://retrodeck.net/")
2024-09-10 11:17:04 +00:00
2024-09-10 14:33:58 +00:00
func _on_request_completed(_result, response_code, _headers, _body):
2024-09-10 11:17:04 +00:00
if response_code == 200:
2024-09-10 17:13:53 +00:00
class_functions.logger("i","Internet Connection Succesful")
2024-09-13 17:27:07 +00:00
%check_conn_button.button_pressed = true
2024-09-10 11:17:04 +00:00
%check_conn_button.text += " - CONNECTED"
else:
2024-09-10 17:13:53 +00:00
class_functions.logger("d","Internet Connection Failed")
2024-09-13 17:27:07 +00:00
%check_conn_button.button_pressed = false
2024-09-10 11:17:04 +00:00
%check_conn_button.text += " - NOT CONNECTED: " + str(response_code)