Emit install/update/uninstall completion and forward install progress to the base Library contract so OGPU's InstallManager and launch menu stop hanging at 0%
This commit is contained in:
parent
b19903e682
commit
e48a0b501d
3 changed files with 46 additions and 25 deletions
|
|
@ -5,6 +5,11 @@ const _apps_cache_file: String = "apps.json"
|
|||
|
||||
@onready var itch: ItchClient = get_tree().get_first_node_in_group("itch_client")
|
||||
|
||||
## The item currently being installed/updated/uninstalled. OGPU's InstallManager
|
||||
## only runs one install at a time, so a single slot is enough to map butlerd's
|
||||
## install_progressed/app_* signals back to the LibraryLaunchItem.
|
||||
var _active_item: LibraryLaunchItem
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super()
|
||||
|
|
@ -22,16 +27,28 @@ func get_library_launch_items() -> Array[LibraryLaunchItem]:
|
|||
|
||||
func install_to(item: LibraryLaunchItem, _location: InstallLocation = null, _options: Dictionary = {}) -> void:
|
||||
var game := (item.metadata.get("game", {}) as Dictionary)
|
||||
itch.install(game)
|
||||
_active_item = item
|
||||
var success: bool = await itch.install(game)
|
||||
_active_item = null
|
||||
install_completed.emit(item, success)
|
||||
logger.info("Install of '" + item.name + "' completed with status: " + str(success))
|
||||
|
||||
|
||||
func update(item: LibraryLaunchItem) -> void:
|
||||
var game := (item.metadata.get("game", {}) as Dictionary)
|
||||
itch.install(game, item.provider_app_id)
|
||||
_active_item = item
|
||||
var success: bool = await itch.install(game, item.provider_app_id)
|
||||
_active_item = null
|
||||
update_completed.emit(item, success)
|
||||
logger.info("Update of '" + item.name + "' completed with status: " + str(success))
|
||||
|
||||
|
||||
func uninstall(item: LibraryLaunchItem) -> void:
|
||||
itch.uninstall(item.provider_app_id)
|
||||
_active_item = item
|
||||
var success: bool = await itch.uninstall(item.provider_app_id)
|
||||
_active_item = null
|
||||
uninstall_completed.emit(item, success)
|
||||
logger.info("Uninstall of '" + item.name + "' completed with status: " + str(success))
|
||||
|
||||
|
||||
## itch.io's CheckUpdate call is async (and rate-limited), so we don't poll it
|
||||
|
|
@ -54,16 +71,17 @@ func _on_logged_in(status: ItchClient.LOGIN_STATUS, _profile: Dictionary) -> voi
|
|||
return
|
||||
|
||||
|
||||
## Re-emits itch.io's raw (id, current, total) install progress under the
|
||||
## base [Library] signal contract (item, percent_completed) so the UI's
|
||||
## generic install-progress widgets pick it up regardless of provider.
|
||||
## TODO: verify the exact LibraryManager lookup method/key for resolving a
|
||||
## provider_app_id back to its LibraryLaunchItem (this plugin was written
|
||||
## against the public Library/LibraryLaunchItem API, but LibraryManager's
|
||||
## internals weren't available while writing this) and wire the emit below
|
||||
## through it instead of dropping the notification.
|
||||
func _on_install_progressed(_id: String, _current: int, _total: int) -> void:
|
||||
pass
|
||||
## Forwards butlerd's install progress (current/total are percentage points,
|
||||
## 0-100) to the base [Library] install_progressed contract (a fraction,
|
||||
## 0.0-1.0) that OGPU's InstallManager and launch menu render as a progress
|
||||
## bar.
|
||||
func _on_install_progressed(_id: String, current: int, total: int) -> void:
|
||||
if _active_item == null:
|
||||
return
|
||||
if total <= 0:
|
||||
return
|
||||
logger.info("Install progressing: " + str(current) + "/" + str(total))
|
||||
install_progressed.emit(_active_item, float(current) / float(total))
|
||||
|
||||
|
||||
## Builds a LibraryLaunchItem for a game, or null when the entry isn't an
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue