Skip to content

Commit

Permalink
[icon_explorer] Add check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Apr 23, 2024
1 parent e3b4a0b commit d1a9116
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 28 deletions.
20 changes: 16 additions & 4 deletions addons/icon_explorer/internal/ext/bootstrap/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ func install(http: HTTPRequest, _version: String) -> Error:
DirAccess.make_dir_recursive_absolute(self.directory())
var zip_path: String = self.directory().path_join("icons.zip")
http.download_file = zip_path
var downloader: Io.FileDownloader = Io.FileDownloader.new(http)
downloader.request.bind(_DOWNLOAD_FILE).call_deferred()

downloader.wait()
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request(_DOWNLOAD_FILE)
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

Expand All @@ -120,6 +118,20 @@ func remove() -> Error:
self.version = ""
return super.remove()

# OVERRIDE
func update_latest_version(http: HTTPRequest) -> void:
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request("https://raw.githubusercontent.com/twbs/icons/main/package.json")
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(downloader.body.get_string_from_utf8())
if res_version != OK:
push_warning("could get latest bootstrap version: '%s'", [parser_version.get_error_message()])
return
self.latest_version = parser_version.data["version"]

# OVERRIDE
func icon_directory() -> String:
return self.directory().path_join("icons-main/icons/")
Expand Down
20 changes: 16 additions & 4 deletions addons/icon_explorer/internal/ext/country_flag_icons/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ func install(http: HTTPRequest, _version: String) -> Error:
DirAccess.make_dir_recursive_absolute(self.directory())
var zip_path: String = self.directory().path_join("icons.zip")
http.download_file = zip_path
var downloader: Io.FileDownloader = Io.FileDownloader.new(http)
downloader.request.bind(_DOWNLOAD_FILE).call_deferred()

downloader.wait()
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request(_DOWNLOAD_FILE)
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

Expand All @@ -90,6 +88,20 @@ func remove() -> Error:
self.version = ""
return super.remove()

# OVERRIDE
func update_latest_version(http: HTTPRequest) -> void:
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request("https://gitlab.com/catamphetamine/country-flag-icons/-/raw/master/package.json")
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(downloader.body.get_string_from_utf8())
if res_version != OK:
push_warning("could get latest country flag icons version: '%s'", [parser_version.get_error_message()])
return
self.latest_version = parser_version.data["version"]

# OVERRIDE
func icon_directory() -> String:
return self.directory().path_join("country-flag-icons-master/3x2/")
19 changes: 16 additions & 3 deletions addons/icon_explorer/internal/ext/font_awesome/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ func install(http: HTTPRequest, _version: String) -> Error:
DirAccess.make_dir_recursive_absolute(self.directory())
var zip_path: String = self.directory().path_join("icons.zip")
http.download_file = zip_path
var downloader: Io.FileDownloader = Io.FileDownloader.new(http)
downloader.request.bind(_DOWNLOAD_FILE).call_deferred()
downloader.wait()
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request(_DOWNLOAD_FILE)
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

Expand All @@ -87,6 +86,20 @@ func remove() -> Error:
self.version = ""
return super.remove()

# OVERRIDE
func update_latest_version(http: HTTPRequest) -> void:
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request("https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.x/js-packages/%40fortawesome/fontawesome-free/package.json")
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(downloader.body.get_string_from_utf8())
if res_version != OK:
push_warning("could get latest font awesome version: '%s'", [parser_version.get_error_message()])
return
self.latest_version = parser_version.data["version"]

# OVERRIDE
func icon_directory() -> String:
return self.directory().path_join("Font-Awesome-6.x/svgs/")
20 changes: 16 additions & 4 deletions addons/icon_explorer/internal/ext/icon_tabler/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ func install(http: HTTPRequest, _version: String) -> Error:
DirAccess.make_dir_recursive_absolute(self.directory())
var zip_path: String = self.directory().path_join("icons.zip")
http.download_file = zip_path
var downloader: Io.FileDownloader = Io.FileDownloader.new(http)
downloader.request.bind(_DOWNLOAD_FILE).call_deferred()

downloader.wait()
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request(_DOWNLOAD_FILE)
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

Expand All @@ -82,6 +80,20 @@ func remove() -> Error:
self.version = ""
return super.remove()

# OVERRIDE
func update_latest_version(http: HTTPRequest) -> void:
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request("https://raw.githubusercontent.com/tabler/tabler-icons/main/package.json")
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(downloader.body.get_string_from_utf8())
if res_version != OK:
push_warning("could get latest icon tabler version: '%s'", [parser_version.get_error_message()])
return
self.latest_version = parser_version.data["version"]

# OVERRIDE
func icon_directory() -> String:
return self.directory().path_join("tabler-icons-master/icons/")
20 changes: 16 additions & 4 deletions addons/icon_explorer/internal/ext/material_design/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ func install(http: HTTPRequest, _version: String) -> Error:
DirAccess.make_dir_recursive_absolute(self.directory())
var zip_path: String = self.directory().path_join("icons.zip")
http.download_file = zip_path
var downloader: Io.FileDownloader = Io.FileDownloader.new(http)
downloader.request.bind(_DOWNLOAD_FILE).call_deferred()

downloader.wait()
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request(_DOWNLOAD_FILE)
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

Expand All @@ -84,6 +82,20 @@ func remove() -> Error:
self.version = ""
return super.remove()

# OVERRIDE
func update_latest_version(http: HTTPRequest) -> void:
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request("https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/master/package.json")
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(downloader.body.get_string_from_utf8())
if res_version != OK:
push_warning("could get latest icon tabler version: '%s'", [parser_version.get_error_message()])
return
self.latest_version = parser_version.data["version"]

# OVERRIDE
func icon_directory() -> String:
return self.directory().path_join("MaterialDesign-SVG-master/svg/")
20 changes: 16 additions & 4 deletions addons/icon_explorer/internal/ext/simple_icons/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ func install(http: HTTPRequest, _version: String) -> Error:
DirAccess.make_dir_recursive_absolute(self.directory())
var zip_path: String = self.directory().path_join("icons.zip")
http.download_file = zip_path
var downloader: Io.FileDownloader = Io.FileDownloader.new(http)
downloader.request.bind(_DOWNLOAD_FILE).call_deferred()

downloader.wait()
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request(_DOWNLOAD_FILE)
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

Expand All @@ -143,6 +141,20 @@ func remove() -> Error:
self.version = ""
return super.remove()

# OVERRIDE
func update_latest_version(http: HTTPRequest) -> void:
var downloader: Io.Downloader = Io.Downloader.new(http)
downloader.await_request("https://raw.githubusercontent.com/simple-icons/simple-icons/develop/package.json")
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(downloader.body.get_string_from_utf8())
if res_version != OK:
push_warning("could get latest simple icons version: '%s'", [parser_version.get_error_message()])
return
self.latest_version = parser_version.data["version"]

# OVERRIDE
func icon_directory() -> String:
return self.directory().path_join("simple-icons-master/icons/")
2 changes: 1 addition & 1 deletion addons/icon_explorer/internal/scripts/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func icon_directory() -> String:
return ""

# VIRTUAL
func update_latest_version() -> void:
func update_latest_version(http: HTTPRequest) -> void:
pass

func directory() -> String:
Expand Down
6 changes: 5 additions & 1 deletion addons/icon_explorer/internal/scripts/tools/io.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static func rrm_dir(dir_path: String) -> bool:
DirAccess.remove_absolute(dir_path)
return true

class FileDownloader:
class Downloader:
extends RefCounted

var result: int
Expand Down Expand Up @@ -49,6 +49,10 @@ class FileDownloader:
var res: Array = await self._http.request_completed
self.from_array(res)
self._sema.post()

func await_request(uri: String) -> void:
self.request.bind(uri).call_deferred()
self.wait()

func wait() -> void:
self._sema.wait()
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum ButtonId {
}

@export var _check_update_button: Button
@export var _check_progress_bar: ProgressBar
@export var _tree: Tree

var db: IconDatabase:
Expand All @@ -21,6 +22,7 @@ var _http_request: HTTPRequest
var _processing: int = -1
var _process_spinner_frame: int
var _process_spinner_msec: float
var _update_thread: Thread

func set_db(db_: IconDatabase) -> void:
if db != null:
Expand Down Expand Up @@ -62,6 +64,7 @@ func _ready() -> void:
self._tree.set_column_expand(Column.WEB, false)
self._tree.set_column_expand(Column.ACTIONS, false)
self._tree.button_clicked.connect(self._on_button_clicked)
self._check_update_button.pressed.connect(self._check_for_updates)

if Engine.is_editor_hint():
ProjectSettings.settings_changed.connect(self.update)
Expand All @@ -85,6 +88,9 @@ func update() -> void:
var is_processed: bool = self._processing == coll.id()
if is_processed:
pass
elif coll.version != "" && coll.latest_version != "" && coll.latest_version > coll.version:
item.set_icon(Column.INSTALLED, self.get_theme_icon(&"StatusWarning", &"EditorIcons"))
item.set_tooltip_text(Column.INSTALLED, "Update Available")
elif coll.is_installed():
item.set_icon(Column.INSTALLED, self.get_theme_icon(&"StatusSuccess", &"EditorIcons"))
item.set_tooltip_text(Column.INSTALLED, "Installed")
Expand All @@ -94,12 +100,41 @@ func update() -> void:

var is_one_processed: bool = self._processing != -1
if coll.is_installed():
item.add_button(Column.ACTIONS, self.get_theme_icon(&"Reload", &"EditorIcons"), ButtonId.INSTALL, is_one_processed || coll.latest_version >= coll.version || coll.latest_version == "", "Update")
item.add_button(Column.ACTIONS, self.get_theme_icon(&"Reload", &"EditorIcons"), ButtonId.INSTALL, is_one_processed || coll.latest_version == "" || coll.latest_version <= coll.version, "Update")
else:
item.add_button(Column.ACTIONS, self.get_theme_icon(&"AssetLib", &"EditorIcons"), ButtonId.INSTALL, is_one_processed, "Install")
item.add_button(Column.ACTIONS, self.get_theme_icon(&"Remove", &"EditorIcons"), ButtonId.REMOVE, is_one_processed || !coll.is_installed(), "Remove")
item.add_button(Column.ACTIONS, self.get_theme_icon(&"Filesystem", &"EditorIcons"), ButtonId.OPEN_DIR, !coll.is_installed(), "Show in File Explorer")

func _check_for_updates() -> void:
if self._update_thread != null && self._update_thread.is_alive():
return
if self._update_thread != null:
self._update_thread.wait_to_finish()

self._check_update_button.disabled = true
self._check_progress_bar.max_value = self.db.collections().size()
self._check_progress_bar.value = 0
self._check_progress_bar.visible = true
self._update_thread = Thread.new()
var http: HTTPRequest = HTTPRequest.new()
self.add_child(http)
self._update_thread.start(self._update_check.bind(http))

# thread function
func _update_check(http: HTTPRequest) -> void:
var upd := func upd() -> void: self._check_progress_bar.value += 1
for coll: Collection in self.db.collections():
coll.update_latest_version(http)
upd.call_deferred()
http.queue_free.call_deferred()
self._update_check_done.call_deferred()

func _update_check_done() -> void:
self._check_update_button.disabled = false
self._check_progress_bar.visible = false
self.update()

func _process(delta: float) -> void:
self._process_spinner_msec += delta
if self._process_spinner_msec > 0.2:
Expand Down
18 changes: 16 additions & 2 deletions addons/icon_explorer/internal/ui/options/options.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://bfmh2kaf2qbrx"]
[gd_scene load_steps=4 format=3 uid="uid://bfmh2kaf2qbrx"]

[ext_resource type="Script" path="res://addons/icon_explorer/internal/ui/options/options.gd" id="1_hdn86"]
[ext_resource type="Script" path="res://addons/icon_explorer/internal/ui/options/collection_management.gd" id="2_fsa3m"]

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_i38b2"]

[node name="control" type="PanelContainer" node_paths=PackedStringArray("_load_on_startup", "_show_main_screen", "_reload_current_project", "_collection_management", "_options_panel", "_options_label", "_collections_panel", "_collections_label")]
anchors_preset = 15
anchor_right = 1.0
Expand Down Expand Up @@ -62,11 +64,12 @@ layout_mode = 2
size_flags_horizontal = 0
text = "Reload the current project to apply changes."

[node name="collection_management" type="VBoxContainer" parent="options/options" node_paths=PackedStringArray("_check_update_button", "_tree")]
[node name="collection_management" type="VBoxContainer" parent="options/options" node_paths=PackedStringArray("_check_update_button", "_check_progress_bar", "_tree")]
layout_mode = 2
size_flags_vertical = 3
script = ExtResource("2_fsa3m")
_check_update_button = NodePath("collections_panel/h_box_container/update_check_button")
_check_progress_bar = NodePath("collections_panel/h_box_container/update_check_button/progress_bar")
_tree = NodePath("collection_management/tree")

[node name="collections_panel" type="PanelContainer" parent="options/options/collection_management"]
Expand All @@ -84,6 +87,17 @@ layout_mode = 2
size_flags_horizontal = 10
text = "Check for Updates"

[node name="progress_bar" type="ProgressBar" parent="options/options/collection_management/collections_panel/h_box_container/update_check_button"]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/background = SubResource("StyleBoxEmpty_i38b2")
show_percentage = false

[node name="collection_management" type="VBoxContainer" parent="options/options/collection_management"]
layout_mode = 2
size_flags_vertical = 3
Expand Down

0 comments on commit d1a9116

Please sign in to comment.