Skip to content

Commit

Permalink
Move version_tag and user_agent to Globals singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
noidexe committed Feb 15, 2023
1 parent 751056c commit d8cf92b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
11 changes: 11 additions & 0 deletions scenes/Globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ const DOWNLOAD_DB_FILE_PATH: String = "user://download_db.json"

const DEFAULT_CONFIG : Dictionary = { "ui":{"alpha": false, "beta": false, "rc": false}, "versions" : [] }

# Update before commiting
# Use semver
# Add '-devel' for versions not intended for release
# Remove '-devel' when commiting a build to be tagged as release
# Remember to update version in export settings before exporting
const version_tag = "v1.11.1"
var user_agent : String

func _ready():
user_agent = "Godot Version Manager/%s (%s) Godot/%s" % [version_tag.lstrip("v"), OS.get_name(), Engine.get_version_info().string ]

# Read the config from file
func read_config() -> Dictionary:
var file = File.new()
Expand Down
4 changes: 2 additions & 2 deletions scenes/NewsFeed.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func _refresh_news():
var up_to_date := false
var new_etag := ""

$req.request(BASE_URL + "/blog/", ["User-Agent: %s" % $"%Version".user_agent], true, HTTPClient.METHOD_HEAD)
$req.request(BASE_URL + "/blog/", ["User-Agent: %s" % Globals.user_agent], true, HTTPClient.METHOD_HEAD)
var head_response = yield($req,"request_completed")
for header in head_response[2]:
# No ETag being returned by the server as of 2023/02/15
Expand All @@ -37,7 +37,7 @@ func _refresh_news():
break

if not up_to_date:
$req.request(BASE_URL + "/blog/", ["User-Agent: %s" % $"%Version".user_agent])
$req.request(BASE_URL + "/blog/", ["User-Agent: %s" % Globals.user_agent])
var response = yield($req,"request_completed")
var news = _get_news(response[3])

Expand Down
2 changes: 1 addition & 1 deletion scenes/NewsItem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func _load_image(_url : String, target : TextureRect):
dir.make_dir(BASE_DIR)
if not dir.file_exists(local_path):
$req.download_file = local_path
$req.request(_url)
$req.request(_url, ["User-Agent: %s" % Globals.user_agent])
var response = yield($req,"request_completed")
if not response[1] == 200:
printerr("Could not find or download image")
Expand Down
19 changes: 5 additions & 14 deletions scenes/Version.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ extends HBoxContainer

const api_endpoint = "https://api.github.com/repos/noidexe/godot-version-manager/releases"

# Update before commiting
# Use semver
# Add '-devel' for versions not intended for release
# Remove '-devel' when commiting a build to be tagged as release
# Remember to update version in export settings before exporting
const version_tag = "v1.11.1"
var user_agent : String

const DOWNLOAD_SUFFIXES = {
"OSX" : "osx.zip",
"Windows": "win.zip",
Expand All @@ -24,11 +16,10 @@ var download_url = RELEASES_URL


func _ready():
user_agent = "Godot Version Manager/%s (%s) Godot/%s" % [version_tag.lstrip("v"), OS.get_name(), Engine.get_version_info().string ]
$update.hide()
$tag.text = "Version Tag: " + version_tag
$tag.text = "Version Tag: " + Globals.version_tag

$req.request(api_endpoint, ["Accept: application/vnd.github.v3+json"])
$req.request(api_endpoint, ["Accept: application/vnd.github.v3+json", "User-Agent: %s" % Globals.user_agent])


func _on_request_completed(_result, response_code : int, _headers, body : PoolByteArray):
Expand All @@ -44,12 +35,12 @@ func _on_request_completed(_result, response_code : int, _headers, body : PoolBy
printerr("Invalid data received when requesting release list")

var last_tag : Dictionary = json[0]
var last_version_tag : String = last_tag.get("tag_name", version_tag)
var last_version_tag : String = last_tag.get("tag_name", Globals.version_tag)

# The update button SHOULD always appear if the local version tag doesn't
# match tag for the latest official release, even if it is a lower version
if last_version_tag == version_tag:
$tag.text = "Version Tag: " + version_tag + " (up to date)"
if last_version_tag == Globals.version_tag:
$tag.text = "Version Tag: " + Globals.version_tag + " (up to date)"
else:
$update.hint_tooltip = last_tag.get("name", "") # Show title of new release as tooltip

Expand Down
4 changes: 2 additions & 2 deletions scenes/VersionSelect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func _find_links(url:String, db : Dictionary):

var req = HTTPRequest.new()
add_child(req)
req.request(url, ["User-Agent: %s" % $"%Version".user_agent] )
req.request(url, ["User-Agent: %s" % Globals.user_agent] )

refresh_button.text = "Scraping%s %s" % [ [".", "..", "..."][randi() % 3] ,url.rsplit("/",true,2)[1] ]

Expand Down Expand Up @@ -359,7 +359,7 @@ func _on_Download_pressed():
var req = HTTPRequest.new()
add_child(req)
req.download_file = filename
req.request(url, ["User-Agent: %s" % $"%Version".user_agent], false)
req.request(url, ["User-Agent: %s" % Globals.user_agent], false)

var divisor : float = 1024 * 1024

Expand Down

0 comments on commit d8cf92b

Please sign in to comment.