diff --git a/Client/origin-client/scenes/init/init_screen.gd b/Client/origin-client/scenes/init/init_screen.gd index 39065e1..537a1aa 100644 --- a/Client/origin-client/scenes/init/init_screen.gd +++ b/Client/origin-client/scenes/init/init_screen.gd @@ -14,6 +14,8 @@ const PLATFORM := "web" # TODO: detect at runtime for native builds. ## Seconds before we give up waiting for version.check and proceed to sync. const VERSION_CHECK_TIMEOUT_SEC := 8.0 +## Seconds of no sync progress before we give up and show the retry button. +const SYNC_TIMEOUT_SEC := 20.0 @onready var status_label : Label = %StatusLabel @onready var progress_bar : ProgressBar = %ProgressBar @@ -29,6 +31,8 @@ var _version_gen : int = 0 var _expected_total : int = 1 ## Tween used for the indeterminate pulse while checking for updates. var _pulse_tween : Tween = null +## SceneTree timer that fires if the sync hangs with no progress. +var _sync_timeout : SceneTreeTimer = null # ── Lifecycle ───────────────────────────────────────────────────────────────── @@ -141,6 +145,7 @@ func _do_sync() -> void: else: _set_status("Downloading card database…") progress_bar.value = 5.0 + _start_sync_timeout() ContentCache.start_sync() BoardTemplateCache.fetch() # parallel fire-and-forget; ready before lobby screen opens @@ -150,9 +155,11 @@ func _on_sync_progress(fetched_total: int) -> void: _expected_total = max(_expected_total, fetched_total) var pct := 5.0 + 80.0 * float(fetched_total) / float(_expected_total) progress_bar.value = clampf(pct, 5.0, 85.0) + _start_sync_timeout() # reset on each page received so we time out from last activity func _on_sync_complete(_total: int) -> void: + _sync_timeout = null progress_bar.value = 90.0 _check_active_session() @@ -217,6 +224,7 @@ func _go_to_main() -> void: func _on_sync_failed(error: String) -> void: + _sync_timeout = null _stop_pulse() _set_status("Sync failed: %s" % error) retry_btn.visible = true @@ -242,3 +250,16 @@ func _stop_pulse() -> void: if _pulse_tween: _pulse_tween.kill() _pulse_tween = null + + +## Start (or restart) the sync watchdog. If no progress arrives within +## SYNC_TIMEOUT_SEC, surface the retry button so the user isn't stranded. +func _start_sync_timeout() -> void: + _sync_timeout = get_tree().create_timer(SYNC_TIMEOUT_SEC) + _sync_timeout.timeout.connect(func() -> void: + if not is_inside_tree() or _sync_timeout == null: + return + _sync_timeout = null + push_warning("InitScreen: sync timed out — showing retry") + _on_sync_failed("Timed out — tap Retry to try again."), + CONNECT_ONE_SHOT)