Added check for update refresh button
This commit is contained in:
parent
06d51b1e58
commit
67f8c94d40
106
Main_menu.gd
106
Main_menu.gd
@ -26,6 +26,61 @@ func notice(msg, type):
|
||||
|
||||
$Notices.add_child(notice)
|
||||
|
||||
# Define check_for_update()
|
||||
# Checks for new available versions online, and updates the newest_version if needed
|
||||
func check_for_update():
|
||||
# Attempt to get the newest available online version
|
||||
var versions_request = HTTPRequest.new() # Get a new HTTPRequest node
|
||||
add_child(versions_request) # Add the node as a child of this one (Main_menu)
|
||||
|
||||
# Connect the request_completed signal to self (this script)'s _versions_request_completed function
|
||||
versions_request.connect("request_completed", self, "_versions_request_completed")
|
||||
# Send an HTTP request to the releases page of UltraFlare on code.retroedge.tech
|
||||
var error = versions_request.request("https://code.retroedge.tech/api/v1/repos/UltraFlare/UltraFlare/releases?draft=false&pre-release=true&limit=1")
|
||||
|
||||
# SIGNALS
|
||||
|
||||
# Define _versions_request_completed
|
||||
# Handles the signal sent by the HTTPRequest when the download completes.
|
||||
func _versions_request_completed(_result, _response_code, _headers, body):
|
||||
# Get the JSON data
|
||||
var data = JSON.parse(body.get_string_from_ascii()).result
|
||||
# Get the newest version
|
||||
newest_version = data[0].tag_name
|
||||
# Set the newest_version_data to the data received.
|
||||
newest_version_data = data[0]
|
||||
|
||||
print("Got versions!")
|
||||
|
||||
# Define _download_request_completed
|
||||
# Handles the signal sent by the HTTPRequest when the download completes.
|
||||
func _download_request_completed(_result, _response_code, _headers, body):
|
||||
# Get a new File object for the executable
|
||||
var dl_file = File.new()
|
||||
# Open the dl_file using the following path,
|
||||
dl_file.open(OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64"+suffix, File.WRITE)
|
||||
# Store the downloaded body in the dl_file
|
||||
dl_file.store_buffer(body)
|
||||
# Close the file
|
||||
dl_file.close()
|
||||
|
||||
# Set the local_version (The one installed on this computer) to the newest_version_data's tag_name
|
||||
local_version = newest_version_data.tag_name
|
||||
# Write the current_version to the store file
|
||||
Store.write_store("current_version", local_version)
|
||||
|
||||
# IF the os is "linux" based, use chmod to change the file to executable
|
||||
if os_name == "linux":
|
||||
var error = OS.execute("chmod", ["+x", OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64"])
|
||||
|
||||
# Enable (Un-disable?) the Play_button
|
||||
$Panel/Play_button.disabled = false
|
||||
$Panel/ProgressBar.hide()
|
||||
$Panel/ProgressBar.value = 0
|
||||
|
||||
|
||||
|
||||
|
||||
# Every _process tick
|
||||
func _process(_delta):
|
||||
# If the newest_version variable exists,
|
||||
@ -79,52 +134,7 @@ func _ready():
|
||||
else:
|
||||
suffix = ""
|
||||
|
||||
# Attempt to get the newest available online version
|
||||
var versions_request = HTTPRequest.new() # Get a new HTTPRequest node
|
||||
add_child(versions_request) # Add the node as a child of this one (Main_menu)
|
||||
|
||||
# Connect the request_completed signal to self (this script)'s _versions_request_completed function
|
||||
versions_request.connect("request_completed", self, "_versions_request_completed")
|
||||
# Send an HTTP request to the releases page of UltraFlare on code.retroedge.tech
|
||||
var error = versions_request.request("https://code.retroedge.tech/api/v1/repos/UltraFlare/UltraFlare/releases?draft=false&pre-release=true&limit=1")
|
||||
|
||||
# Define _versions_request_completed
|
||||
# Handles the signal sent by the HTTPRequest when the download completes.
|
||||
func _versions_request_completed(_result, _response_code, _headers, body):
|
||||
# Get the JSON data
|
||||
var data = JSON.parse(body.get_string_from_ascii()).result
|
||||
# Get the newest version
|
||||
newest_version = data[0].tag_name
|
||||
# Set the newest_version_data to the data received.
|
||||
newest_version_data = data[0]
|
||||
|
||||
print("Got versions!")
|
||||
|
||||
# Define _download_request_completed
|
||||
# Handles the signal sent by the HTTPRequest when the download completes.
|
||||
func _download_request_completed(_result, _response_code, _headers, body):
|
||||
# Get a new File object for the executable
|
||||
var dl_file = File.new()
|
||||
# Open the dl_file using the following path,
|
||||
dl_file.open(OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64"+suffix, 7)
|
||||
# Store the downloaded body in the dl_file
|
||||
dl_file.store_buffer(body)
|
||||
# Close the file
|
||||
dl_file.close()
|
||||
|
||||
# Set the local_version (The one installed on this computer) to the newest_version_data's tag_name
|
||||
local_version = newest_version_data.tag_name
|
||||
# Write the current_version to the store file
|
||||
Store.write_store("current_version", local_version)
|
||||
|
||||
# IF the os is "linux" based, use chmod to change the file to executable
|
||||
if os_name == "linux":
|
||||
var error = OS.execute("chmod", ["+x", OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64"])
|
||||
|
||||
# Enable (Un-disable?) the Play_button
|
||||
$Panel/Play_button.disabled = false
|
||||
$Panel/ProgressBar.hide()
|
||||
$Panel/ProgressBar.value = 0
|
||||
check_for_update()
|
||||
|
||||
# When the play button is pressed,
|
||||
func _on_Play_button_pressed():
|
||||
@ -190,3 +200,7 @@ func _on_Change_timer_timeout():
|
||||
|
||||
# Set the background
|
||||
$Background.texture = load("res://textures/backgrounds/background"+str(background_num)+".png")
|
||||
|
||||
# When the refresh button is pressed,
|
||||
func _on_Refresh_button_pressed():
|
||||
check_for_update()
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=15 format=2]
|
||||
[gd_scene load_steps=17 format=2]
|
||||
|
||||
[ext_resource path="res://textures/backgrounds/background1.png" type="Texture" id=1]
|
||||
[ext_resource path="res://fonts/SPACEBAR.ttf" type="DynamicFontData" id=2]
|
||||
@ -8,6 +8,7 @@
|
||||
[ext_resource path="res://fonts/SPACE.tres" type="DynamicFont" id=6]
|
||||
[ext_resource path="res://ProgressBar.gd" type="Script" id=7]
|
||||
[ext_resource path="res://fonts/retro_gaming.tres" type="DynamicFont" id=8]
|
||||
[ext_resource path="res://textures/kenny-game-icons/PNG/Black/2x/return.png" type="Texture" id=9]
|
||||
|
||||
[sub_resource type="Theme" id=1]
|
||||
default_font = ExtResource( 4 )
|
||||
@ -49,6 +50,10 @@ corner_radius_top_right = 4
|
||||
corner_radius_bottom_right = 4
|
||||
corner_radius_bottom_left = 4
|
||||
|
||||
[sub_resource type="StreamTexture" id=8]
|
||||
flags = 4
|
||||
load_path = "res://.import/return.png-37ee6a37bc4abf83a64fce1b810ae01f.stex"
|
||||
|
||||
[node name="Main_menu" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
@ -119,6 +124,9 @@ margin_right = 272.0
|
||||
margin_bottom = 24.0
|
||||
custom_fonts/font = ExtResource( 8 )
|
||||
text = "Local Version:"
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[node name="Online_version" type="Label" parent="Panel/Panel"]
|
||||
margin_left = 16.0
|
||||
@ -127,6 +135,18 @@ margin_right = 272.0
|
||||
margin_bottom = 48.0
|
||||
custom_fonts/font = ExtResource( 8 )
|
||||
text = "Online Version:"
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[node name="Refresh_button" type="TextureButton" parent="Panel/Panel"]
|
||||
margin_left = 232.0
|
||||
margin_top = 8.0
|
||||
margin_right = 332.0
|
||||
margin_bottom = 108.0
|
||||
rect_scale = Vector2( 0.3, 0.3 )
|
||||
texture_normal = SubResource( 8 )
|
||||
texture_pressed = ExtResource( 9 )
|
||||
|
||||
[node name="Notices" type="VBoxContainer" parent="."]
|
||||
margin_top = 80.0
|
||||
@ -135,3 +155,4 @@ margin_bottom = 272.0
|
||||
|
||||
[connection signal="timeout" from="Background/Change_timer" to="." method="_on_Change_timer_timeout"]
|
||||
[connection signal="pressed" from="Panel/Play_button" to="." method="_on_Play_button_pressed"]
|
||||
[connection signal="pressed" from="Panel/Panel/Refresh_button" to="." method="_on_Refresh_button_pressed"]
|
||||
|
Loading…
Reference in New Issue
Block a user