Add password login and collection visibility settings
All checks were successful
Build plugin / build (push) Successful in 1m10s

This commit is contained in:
Jose Falanga 2026-08-17 02:00:39 -03:00
parent 173aa94ea9
commit e2a4464d0d
5 changed files with 218 additions and 26 deletions

View file

@ -16,21 +16,34 @@ const icon := preload("res://plugins/itch/assets/itch.svg")
@onready var status_label: Label = $%StatusLabel
@onready var api_key_box: LineEdit = $%ApiKeyInput
@onready var username_box: LineEdit = $%UsernameInput
@onready var password_box: LineEdit = $%PasswordInput
@onready var login_method: OptionButton = $%LoginMethod
@onready var save_button: Button = $%SaveButton
@onready var help_label: Label = $%HelpLabel
@onready var filter_check: CheckBox = $%FilterUnsupported
@onready var show_purchases_check: CheckBox = $%ShowPurchases
@onready var collections_container: VBoxContainer = $%CollectionsContainer
@onready var itch: ItchClient = get_tree().get_first_node_in_group("itch_client")
var _collection_checks: Dictionary = {}
func _ready() -> void:
var api_key := settings_manager.get_value("plugin.itch", "api_key", "") as String
api_key_box.text = api_key
api_key_box.secret = true
filter_check.button_pressed = settings_manager.get_value("plugin.itch", "filter_unsupported", true) as bool
var saved_method: int = settings_manager.get_value("plugin.itch", "login_method", 0) as int
login_method.selected = saved_method
_on_login_method_changed(saved_method)
help_label.text = "Get an API key from https://itch.io/user/settings/api-keys"
var username := settings_manager.get_value("plugin.itch", "username", "") as String
username_box.text = username
filter_check.button_pressed = settings_manager.get_value("plugin.itch", "filter_unsupported", true) as bool
show_purchases_check.button_pressed = settings_manager.get_value("plugin.itch", "show_purchases", true) as bool
_update_status()
itch.client_ready.connect(_update_status)
@ -38,6 +51,11 @@ func _ready() -> void:
save_button.pressed.connect(_on_save_button)
filter_check.toggled.connect(_on_filter_toggled)
login_method.item_selected.connect(_on_login_method_changed)
show_purchases_check.toggled.connect(_on_show_purchases_toggled)
# Build collection checkboxes once we're logged in.
itch.logged_in.connect(_populate_collections.bind(), CONNECT_ONE_SHOT)
func _update_status() -> void:
@ -62,16 +80,82 @@ func _on_login(status: ItchClient.LOGIN_STATUS, _profile: Dictionary) -> void:
if status == ItchClient.LOGIN_STATUS.OK:
notify.text = "Successfully logged in to itch.io"
else:
notify.text = "itch.io login failed. Double check your API key."
notify.text = "itch.io login failed. Double check your credentials."
notification_manager.show(notify)
func _on_login_method_changed(idx: int) -> void:
# API key mode: show API key input, hide user/pass.
# Password mode: show user/pass, hide API key.
var is_api := idx == 0
api_key_box.visible = is_api
username_box.visible = not is_api
password_box.visible = not is_api
help_label.visible = is_api
func _on_save_button() -> void:
var api_key: String = api_key_box.text.strip_edges()
settings_manager.set_value("plugin.itch", "api_key", api_key)
if api_key == "":
var method: int = login_method.selected
settings_manager.set_value("plugin.itch", "login_method", method)
if method == 0:
# API key login
var api_key: String = api_key_box.text.strip_edges()
settings_manager.set_value("plugin.itch", "api_key", api_key)
if api_key == "":
return
itch.login_with_api_key(api_key)
else:
# Username/password login
var username: String = username_box.text.strip_edges()
var password: String = password_box.text
settings_manager.set_value("plugin.itch", "username", username)
if username == "" or password == "":
return
itch.login_with_password(username, password)
## Fetches the user's collections and builds a checkbox for each one.
func _populate_collections(_status: ItchClient.LOGIN_STATUS, _profile: Dictionary) -> void:
if not itch.is_logged_in:
return
itch.login_with_api_key(api_key)
var profile_id: int = itch.profile.get("user", {}).get("id", itch.profile.get("id", 0))
var res := await itch._rpc_call("Fetch.ProfileCollections", {"profileId": profile_id})
if "error" in res:
return
var collections: Array = res.get("items", [])
# Load saved visibility state.
var hidden: Dictionary = settings_manager.get_value("plugin.itch", "hidden_collections", {}) as Dictionary
# Clear old checkboxes.
for child in collections_container.get_children():
child.queue_free()
_collection_checks.clear()
for c in collections:
var collection: Dictionary = c
var col_name: String = collection.get("title", "Collection " + str(collection.get("id", "")))
var col_id: String = str(collection.get("id", 0))
var check := CheckBox.new()
check.text = col_name
check.button_pressed = not hidden.has(col_id)
check.toggled.connect(_on_collection_toggled.bind(col_id))
collections_container.add_child(check)
_collection_checks[col_id] = check
func _on_collection_toggled(pressed: bool, col_id: String) -> void:
var hidden: Dictionary = settings_manager.get_value("plugin.itch", "hidden_collections", {}) as Dictionary
if pressed:
hidden.erase(col_id)
else:
hidden[col_id] = true
settings_manager.set_value("plugin.itch", "hidden_collections", hidden)
func _on_show_purchases_toggled(pressed: bool) -> void:
settings_manager.set_value("plugin.itch", "show_purchases", pressed)
## Persists the platform filter and reloads the itch.io library so the