generated from MechanicalFlower/godot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add link to the latest available version
- Loading branch information
1 parent
4604a5b
commit b873d7f
Showing
9 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
extends Control | ||
|
||
const UpdateChecker := preload("res://addons/gh-release-checker/update_checker.gd") | ||
|
||
@onready var link_btn: LinkButton = $LinkBtn | ||
@onready var update_checker := UpdateChecker.new() | ||
|
||
|
||
func _ready() -> void: | ||
add_child(update_checker) | ||
update_checker.get_latest_version() | ||
update_checker.release_parsed.connect(on_released_parsed) | ||
|
||
|
||
func on_released_parsed(release: Dictionary) -> void: | ||
if release["new"]: | ||
link_btn.show() | ||
link_btn.text = "New version available: " + release["version"] | ||
else: | ||
link_btn.hide() | ||
#link_btn.text = "You have the latest version: " + release["version"] | ||
link_btn.uri = release["url"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[plugin] | ||
|
||
name="release_checker" | ||
description="" | ||
author="florianvazelle" | ||
version="0.0.0" | ||
script="plugin.gd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@tool | ||
extends EditorPlugin | ||
|
||
|
||
func _enter_tree(): | ||
if not ProjectSettings.has_setting("addons/release_checker/repo_url"): | ||
ProjectSettings.set_setting("addons/release_checker/repo_url", "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class_name UpdateChecker extends Node | ||
|
||
signal release_parsed(latest_release) | ||
|
||
var latest_release: Dictionary | ||
|
||
|
||
func get_latest_version() -> void: | ||
var req: HTTPRequest = HTTPRequest.new() | ||
add_child(req) | ||
req.request_completed.connect(on_request_completed) | ||
req.request(ProjectSettings.get_setting("addons/release_checker/repo_url")) | ||
|
||
|
||
func new_version_available(project_version: String, latest_version: String) -> bool: | ||
var project_numbers: Array = project_version.split(".") | ||
var latest_numbers: Array = latest_version.split(".") | ||
|
||
# We assume versions will have the same amount of numbers, otherwise IT BREAKS | ||
for i in range(project_numbers.size()): | ||
if int(latest_numbers[i]) > int(project_numbers[i]): | ||
return true | ||
|
||
return false | ||
|
||
|
||
func on_request_completed(_result, _response_code, _headers, body) -> void: | ||
var json = JSON.parse_string(body.get_string_from_utf8()) | ||
|
||
if json.has("message"): | ||
print(json["message"]) | ||
return | ||
|
||
# Remove the "v" for comparison | ||
var release_version: String = json["tag_name"].replace("v", "") | ||
|
||
latest_release = { | ||
"version": json["tag_name"], | ||
"url": json["html_url"], | ||
"new": | ||
new_version_available( | ||
ProjectSettings.get_setting("application/config/version"), release_version | ||
) | ||
} | ||
|
||
release_parsed.emit(latest_release) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters