Skip to content

Commit 5de713d

Browse files
authored
Merge pull request #92 from ThePat02/91-updatemanager-throws-an-error-when-the-editor-is-launched-without-internet-connection
fix: Dirty Update Manager now doesn't die when unable to fetch the plugin version
2 parents 4855d95 + a4d57dd commit 5de713d

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

addons/behaviour_toolkit/behaviour_toolkit.gd

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,41 @@ class_name BehaviourToolkit extends Node
33
## Base class for Behaviour Toolkit plugin nodes.
44

55

6+
enum LogType {
7+
DEFAULT,
8+
WARNING,
9+
ERROR,
10+
}
11+
12+
613
class Logger:
714
extends BehaviourToolkit
815
## Logger class for Behaviour Toolkit plugin.
916

1017
## Main color for logger messages.
1118
const COLOR_MAIN: String = "Orange"
1219
## Accent color for logger messages.
13-
const COLOR_ACCENT: String = "Yellow"
20+
const COLOR_ACCENT: String = "Blue"
21+
## Warning color for logger messages.
22+
const COLOR_WARNING: String = "Yellow"
23+
## Error color for logger messages.
24+
const COLOR_ERROR: String = "Red"
1425

1526
## Log a message to the console with the Behaviour Toolkit prefix.
16-
static func say(message: String, caller: Node = null) -> void:
27+
static func say(message: String, caller: Node = null, type: LogType = LogType.DEFAULT) -> void:
1728
var log_message: String
1829
log_message = colorize("[Behaviour Toolkit] ", COLOR_MAIN)
1930

31+
if not type == LogType.DEFAULT:
32+
var color: String
33+
match type:
34+
LogType.WARNING:
35+
color = COLOR_WARNING
36+
LogType.ERROR:
37+
color = COLOR_ERROR
38+
39+
log_message += colorize("[" + LogType.keys()[type] + "] ", color)
40+
2041
if caller != null:
2142

2243
log_message += colorize(caller.name + " ", COLOR_ACCENT)

addons/behaviour_toolkit/ui/utils/update_manager.gd

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ signal update_available
1616
## The URL to the repository config file. This file has to be the raw version!
1717
@export var repo_config_url = ""
1818

19+
## Error flag to prevent the error message from printing twice.
20+
static var had_error: bool = false
1921

2022
## The current version of the plugin.
2123
var current_version: String
@@ -24,6 +26,8 @@ var newest_version: String
2426

2527

2628
func _ready():
29+
current_version = get_current_version()
30+
2731
# Connect signals
2832
connect("request_completed", _on_http_request_request_completed)
2933

@@ -36,7 +40,6 @@ func _ready():
3640

3741
func start():
3842
# Get versions
39-
current_version = get_current_version()
4043
get_newest_version()
4144

4245

@@ -66,6 +69,18 @@ func get_newest_version() -> void:
6669

6770
## Called when the request to the repository is completed, parses the config file and sets the newest version.
6871
func _on_http_request_request_completed(result:int, response_code:int, headers:PackedStringArray, body:PackedByteArray):
72+
if result != OK:
73+
if not had_error:
74+
BehaviourToolkit.Logger.say(
75+
"Unable to fetch newest version from GitHub. Check your internet connection and reload the editor!",
76+
null,
77+
BehaviourToolkit.LogType.WARNING
78+
)
79+
had_error = true
80+
81+
emit_signal("update_request_completed")
82+
return
83+
6984
var config = ConfigFile.new()
7085
var err = config.parse(body.get_string_from_ascii())
7186

0 commit comments

Comments
 (0)