Skip to content

Commit

Permalink
Merge pull request #5 from myyk/skip-update
Browse files Browse the repository at this point in the history
Skip update
  • Loading branch information
myyk authored Apr 30, 2024
2 parents 3d22bc7 + 9ffe763 commit ee1b009
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 48 deletions.
23 changes: 17 additions & 6 deletions addons/plugin_updater/core/download_update_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TEMP_FILE_NAME = "user://temp.zip"
@onready var _content: RichTextLabel = $Panel/GridContainer/PanelContainer2/ScrollContainer/MarginContainer/content
@onready var _update_button: Button = $Panel/GridContainer/Panel/HBoxContainer/update

var _latest_version: SemVer
var _download_zip_url: String

func _ready():
Expand All @@ -43,13 +44,19 @@ func _check_for_updater():
if response.code() != 200:
push_warning("Update information cannot be retrieved from GitHub! \n %s" % response.response())
return
var latest_version := extract_latest_version(response)
_latest_version = extract_latest_version(response)
var current_version := extract_current_version()

# if the current version is less than the skip version, skip the update
if "ignore_updates_before_version" in config:
var skip_version = SemVer.parse(config.ignore_updates_before_version)
if current_version.is_less_than(skip_version):
return

# if same version exit here no update need
if latest_version.is_greater(current_version):
if _latest_version.is_greater(current_version):
_download_zip_url = extract_zip_url(response)
_header.text = "Current version '%s'. A new version '%s' is available" % [current_version, latest_version]
_header.text = "Current version '%s'. A new version '%s' is available" % [current_version, _latest_version]
await show_update()

func show_update() -> void:
Expand Down Expand Up @@ -126,9 +133,11 @@ func progress_bar(p_progress :int, p_color :Color = Color.POWDER_BLUE):
func _colored(message :String, color :Color) -> String:
return "[color=#%s]%s[/color]" % [color.to_html(), message]

func _on_disable_updates_toggled(toggled_on):
# TODO: Store a setting somewhere
pass
func _skip_update():
# Store a setting in the config.
config.ignore_updates_before_version = str(_latest_version)
# Write the config into the addons dir so it gets removed on update
UpdaterConfig.save_user_config(config)

func _on_update_pressed():
hide()
Expand Down Expand Up @@ -183,6 +192,8 @@ func _on_http_request_request_completed(result: int, response_code: int, headers

func _on_close_pressed():
hide()
if $Panel/GridContainer/Panel/HBoxContainer/close.toggled:
_skip_update()

func _on_content_meta_clicked(meta :String):
var properties = str_to_var(meta)
Expand Down
62 changes: 47 additions & 15 deletions addons/plugin_updater/core/download_update_panel.tscn

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion addons/plugin_updater/core/updater_config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extends RefCounted
## "editor_plugin_meta": "PluginUpdaterEditorPlugin"
## }

const PLUGIN_NAME: String = "PLUGIN_NAME_PLACEHOLDER" # This is replaced when code is generated
static var PLUGIN_NAME: String = "PLUGIN_NAME_PLACEHOLDER" # This is replaced when code is generated
const PLUGIN_MAKER_CONFIG_PATH = "res://plugin-updater.json"
const PLUGIN_USER_CONFIG_PATH_FORMAT = "res://addons/%s/generated/updater/plugin-updater.json"

Expand All @@ -30,3 +30,15 @@ static func _get_config(path: String) -> Dictionary:
config.merge(JSON.parse_string(file.get_as_text()), true)

return config

static func save_user_config(config: Dictionary) -> Error:
return _save_config(PLUGIN_USER_CONFIG_PATH_FORMAT % PLUGIN_NAME, config)

static func _save_config(path: String, config: Dictionary) -> Error:
var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
if file == null:
push_error("plugin-updater: Could not open file at " + path)
return FileAccess.get_open_error()
file.store_string(JSON.stringify(config, "\t"))
file.close()
return OK
23 changes: 17 additions & 6 deletions addons/plugin_updater/generated/updater/download_update_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TEMP_FILE_NAME = "user://temp.zip"
@onready var _content: RichTextLabel = $Panel/GridContainer/PanelContainer2/ScrollContainer/MarginContainer/content
@onready var _update_button: Button = $Panel/GridContainer/Panel/HBoxContainer/update

var _latest_version: SemVer
var _download_zip_url: String

func _ready():
Expand All @@ -43,13 +44,19 @@ func _check_for_updater():
if response.code() != 200:
push_warning("Update information cannot be retrieved from GitHub! \n %s" % response.response())
return
var latest_version := extract_latest_version(response)
_latest_version = extract_latest_version(response)
var current_version := extract_current_version()

# if the current version is less than the skip version, skip the update
if "ignore_updates_before_version" in config:
var skip_version = SemVer.parse(config.ignore_updates_before_version)
if current_version.is_less_than(skip_version):
return

# if same version exit here no update need
if latest_version.is_greater(current_version):
if _latest_version.is_greater(current_version):
_download_zip_url = extract_zip_url(response)
_header.text = "Current version '%s'. A new version '%s' is available" % [current_version, latest_version]
_header.text = "Current version '%s'. A new version '%s' is available" % [current_version, _latest_version]
await show_update()

func show_update() -> void:
Expand Down Expand Up @@ -126,9 +133,11 @@ func progress_bar(p_progress :int, p_color :Color = Color.POWDER_BLUE):
func _colored(message :String, color :Color) -> String:
return "[color=#%s]%s[/color]" % [color.to_html(), message]

func _on_disable_updates_toggled(toggled_on):
# TODO: Store a setting somewhere
pass
func _skip_update():
# Store a setting in the config.
config.ignore_updates_before_version = str(_latest_version)
# Write the config into the addons dir so it gets removed on update
UpdaterConfig.save_user_config(config)

func _on_update_pressed():
hide()
Expand Down Expand Up @@ -183,6 +192,8 @@ func _on_http_request_request_completed(result: int, response_code: int, headers

func _on_close_pressed():
hide()
if $Panel/GridContainer/Panel/HBoxContainer/close.toggled:
_skip_update()

func _on_content_meta_clicked(meta :String):
var properties = str_to_var(meta)
Expand Down
62 changes: 47 additions & 15 deletions addons/plugin_updater/generated/updater/download_update_panel.tscn

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions addons/plugin_updater/generated/updater/updater_config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ static func _get_config(path: String) -> Dictionary:
config.merge(JSON.parse_string(file.get_as_text()), true)

return config

static func save_user_config(config: Dictionary) -> Error:
return _save_config(PLUGIN_USER_CONFIG_PATH_FORMAT % PLUGIN_NAME, config)

static func _save_config(path: String, config: Dictionary) -> Error:
var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
if file == null:
push_error("plugin-updater: Could not open file at " + path)
return FileAccess.get_open_error()
file.store_string(JSON.stringify(config, "\t"))
file.close()
return OK
2 changes: 1 addition & 1 deletion addons/plugin_updater/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="plugin_updater"
description="A plugin for plugin makers to give their plugins an easy in-editor updating."
author="myyk"
version="1.0.0"
version="1.1.0"
script="plugin_updater.gd"
9 changes: 5 additions & 4 deletions addons/plugin_updater/plugin_updater.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@tool
extends EditorPlugin

const UpdaterConfig = preload("res://addons/plugin_updater/core/updater_config.gd")
const DEBUG_MODE = false

const UpdaterConfig = preload("res://addons/plugin_updater/core/updater_config.gd")

func _enter_tree():
var config = UpdaterConfig.get_repo_config()
_install_to_plugin(config.plugin_name)
UpdaterConfig.PLUGIN_NAME = "plugin_updater"
_install_to_plugin(UpdaterConfig.PLUGIN_NAME)

# Add auto-update functionality for plugin_updater itself (not the plugin being updated, that needs similar code)
if Engine.is_editor_hint():
Expand Down Expand Up @@ -45,6 +45,7 @@ func _install_to_plugin(plugin_name: String):

# Copy in plugin name so we can use relative paths
replace_string_in_file(target_path + "updater_config.gd", "PLUGIN_NAME_PLACEHOLDER", plugin_name)
replace_string_in_file(target_path + "updater_config.gd", "static var", "const")

func _recursive_copy(from: String, to: String, chmod_flags: int = -1) -> Error:
var from_dir = DirAccess.open(from)
Expand Down

0 comments on commit ee1b009

Please sign in to comment.