readability: extract magic constants, fix Go jargon

- goos/goarch -> os_name/arch_name (Go ecosystem jargon)
- BUTLER_USER_AGENT now reads version from plugin.json at runtime
- Added named constants: CONNECTION_TIMEOUT_ITERATIONS,
  CONNECTION_POLL_DELAY_MS, PERCENTAGE_SCALE, LAUNCH_WATCH_INTERVAL_SEC,
  UPDATE_CHECK_INTERVAL_SEC, BUTLERD_BOOT_MAX_ATTEMPTS,
  BUTLERD_BOOT_RETRY_DELAY_SEC, LAUNCH_WATCH_TIMEOUT_MS,
  EXECUTE_PERMISSION_BIT
- Removed BYTES_PER_MB (inline 1024 * 1024 is clearer)
This commit is contained in:
Jose Falanga 2026-08-19 16:20:20 -03:00
parent 18f674c00b
commit 7ee08ac571
2 changed files with 38 additions and 18 deletions

View file

@ -2,6 +2,13 @@ extends Library
const ItchClient := preload("res://plugins/itch/core/itch_client.gd")
const _apps_cache_file: String = "apps.json"
const LAUNCH_WATCH_INTERVAL_SEC := 2.0
const UPDATE_CHECK_INTERVAL_SEC := 600.0
const BUTLERD_BOOT_MAX_ATTEMPTS := 10
const BUTLERD_BOOT_RETRY_DELAY_SEC := 0.5
const LAUNCH_WATCH_TIMEOUT_MS := 5000
## 0o111 — execute bit set for any of owner/group/others.
const EXECUTE_PERMISSION_BIT := 73
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
@ -35,14 +42,14 @@ func _ready() -> void:
# instead of leaving the user stuck on a black in-game screen.
if load("res://core/global/launch_manager.tres") != null:
var watch_timer := Timer.new()
watch_timer.wait_time = 2.0
watch_timer.wait_time = LAUNCH_WATCH_INTERVAL_SEC
watch_timer.autostart = true
watch_timer.timeout.connect(_check_failed_launches)
add_child(watch_timer)
# Keep the has_update() flags fresh in the background (CheckUpdate hits the
# itch.io API, so it must never run on the UI thread or per-library-load).
var update_timer := Timer.new()
update_timer.wait_time = 600.0
update_timer.wait_time = UPDATE_CHECK_INTERVAL_SEC
update_timer.autostart = true
update_timer.timeout.connect(_refresh_update_flags)
add_child(update_timer)
@ -502,8 +509,8 @@ func _load_library(caching_flags: int = Cache.FLAGS.LOAD | Cache.FLAGS.SAVE) ->
cached_installed = true
break
var attempts := 0
while cached_installed and attempts < 10 and (caves == null or (caves.is_empty() and itch.state != ItchClient.STATE.CONNECTED)):
await get_tree().create_timer(0.5).timeout
while cached_installed and attempts < BUTLERD_BOOT_MAX_ATTEMPTS and (caves == null or (caves.is_empty() and itch.state != ItchClient.STATE.CONNECTED)):
await get_tree().create_timer(BUTLERD_BOOT_RETRY_DELAY_SEC).timeout
caves = await itch.get_caves()
attempts += 1
var caves_by_game_id := {}
@ -792,8 +799,7 @@ func _candidate_is_game_binary(path: String) -> bool:
func _is_runnable_file(path: String) -> bool:
if path == "" or not FileAccess.file_exists(path):
return false
# 0o111 = execute bit set for any of owner/group/others.
return FileAccess.get_unix_permissions(path) & 73 != 0
return FileAccess.get_unix_permissions(path) & EXECUTE_PERMISSION_BIT != 0
## Looks up a runtime binary (love, java, ...). Checks the persistent runtime
@ -839,7 +845,7 @@ func _check_failed_launches() -> void:
continue
if app.is_running():
continue
if now - int(_launch_watch[app.pid]) < 5000:
if now - int(_launch_watch[app.pid]) < LAUNCH_WATCH_TIMEOUT_MS:
continue
if app.pid in _diagnosed_pids:
continue