Init screen: loading bar + version check hang fix
Replace the sync card count with a ProgressBar that pulses indeterminately during version check, then fills 5→85% during content sync, 90% during active-session check, 100% on done. Add an 8-second timeout on version.check so a silent server-side hang (server receives packet but never replies) auto-proceeds to sync instead of freezing the init screen indefinitely. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -48,6 +48,13 @@ autowrap_mode = 3
|
|||||||
modulate = Color(0.75, 0.75, 0.8, 1.0)
|
modulate = Color(0.75, 0.75, 0.8, 1.0)
|
||||||
theme_override_font_sizes/font_size = 14
|
theme_override_font_sizes/font_size = 14
|
||||||
|
|
||||||
|
[node name="ProgressBar" type="ProgressBar" parent="Center/VBox"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
custom_minimum_size = Vector2(0, 8)
|
||||||
|
show_percentage = false
|
||||||
|
value = 0.0
|
||||||
|
|
||||||
[node name="UpdatePanel" type="VBoxContainer" parent="Center/VBox"]
|
[node name="UpdatePanel" type="VBoxContainer" parent="Center/VBox"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|||||||
@@ -12,16 +12,30 @@ extends Control
|
|||||||
const CLIENT_VERSION := "0.1.0"
|
const CLIENT_VERSION := "0.1.0"
|
||||||
const PLATFORM := "web" # TODO: detect at runtime for native builds.
|
const PLATFORM := "web" # TODO: detect at runtime for native builds.
|
||||||
|
|
||||||
@onready var status_label : Label = %StatusLabel
|
## Seconds before we give up waiting for version.check and proceed to sync.
|
||||||
@onready var update_panel : Control = %UpdatePanel
|
const VERSION_CHECK_TIMEOUT_SEC := 8.0
|
||||||
@onready var update_msg : Label = %UpdateMsg
|
|
||||||
@onready var retry_btn : Button = %RetryBtn
|
@onready var status_label : Label = %StatusLabel
|
||||||
|
@onready var progress_bar : ProgressBar = %ProgressBar
|
||||||
|
@onready var update_panel : Control = %UpdatePanel
|
||||||
|
@onready var update_msg : Label = %UpdateMsg
|
||||||
|
@onready var retry_btn : Button = %RetryBtn
|
||||||
|
|
||||||
|
# ── State ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
## Incremented each time _start() runs so stale timeout callbacks are ignored.
|
||||||
|
var _version_gen : int = 0
|
||||||
|
## Upper bound on expected total definitions; tracks running max across pages.
|
||||||
|
var _expected_total : int = 1
|
||||||
|
## Tween used for the indeterminate pulse while checking for updates.
|
||||||
|
var _pulse_tween : Tween = null
|
||||||
|
|
||||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
update_panel.visible = false
|
update_panel.visible = false
|
||||||
retry_btn.visible = false
|
retry_btn.visible = false
|
||||||
|
progress_bar.value = 0.0
|
||||||
|
|
||||||
ContentCache.sync_progress.connect(_on_sync_progress)
|
ContentCache.sync_progress.connect(_on_sync_progress)
|
||||||
ContentCache.sync_complete.connect(_on_sync_complete)
|
ContentCache.sync_complete.connect(_on_sync_complete)
|
||||||
@@ -48,7 +62,12 @@ func _exit_tree() -> void:
|
|||||||
func _start() -> void:
|
func _start() -> void:
|
||||||
update_panel.visible = false
|
update_panel.visible = false
|
||||||
retry_btn.visible = false
|
retry_btn.visible = false
|
||||||
|
_version_gen += 1
|
||||||
|
var gen := _version_gen
|
||||||
|
|
||||||
_set_status("Checking for updates…")
|
_set_status("Checking for updates…")
|
||||||
|
_start_pulse()
|
||||||
|
|
||||||
Network.request(
|
Network.request(
|
||||||
"version.check",
|
"version.check",
|
||||||
{ "clientVersion": CLIENT_VERSION, "platform": PLATFORM },
|
{ "clientVersion": CLIENT_VERSION, "platform": PLATFORM },
|
||||||
@@ -56,13 +75,25 @@ func _start() -> void:
|
|||||||
func(code: String, _msg: String): _on_version_error(code)
|
func(code: String, _msg: String): _on_version_error(code)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Fallback: if the server receives the request but never replies, don't hang.
|
||||||
|
get_tree().create_timer(VERSION_CHECK_TIMEOUT_SEC).timeout.connect(
|
||||||
|
func() -> void:
|
||||||
|
if _version_gen != gen or not is_inside_tree():
|
||||||
|
return
|
||||||
|
push_warning("InitScreen: version.check timed out — proceeding to sync")
|
||||||
|
_version_gen += 1 # invalidate further timeout callbacks from this gen
|
||||||
|
_do_sync(),
|
||||||
|
CONNECT_ONE_SHOT)
|
||||||
|
|
||||||
|
|
||||||
func _on_version_ok(payload: Variant) -> void:
|
func _on_version_ok(payload: Variant) -> void:
|
||||||
|
_version_gen += 1 # disarm timeout
|
||||||
var p := payload as Dictionary
|
var p := payload as Dictionary
|
||||||
var status := p.get("status", "Ok") as String
|
var status := p.get("status", "Ok") as String
|
||||||
|
|
||||||
match status:
|
match status:
|
||||||
"UpdateRequired":
|
"UpdateRequired":
|
||||||
|
_stop_pulse()
|
||||||
var url : String = p.get("downloadUrl", "") as String
|
var url : String = p.get("downloadUrl", "") as String
|
||||||
var notes: String = p.get("releaseNotes", "") as String
|
var notes: String = p.get("releaseNotes", "") as String
|
||||||
update_panel.visible = true
|
update_panel.visible = true
|
||||||
@@ -88,8 +119,10 @@ func _on_version_ok(payload: Variant) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_version_error(code: String) -> void:
|
func _on_version_error(code: String) -> void:
|
||||||
|
_version_gen += 1 # disarm timeout
|
||||||
if code == "DISCONNECTED":
|
if code == "DISCONNECTED":
|
||||||
# Lost connection before we got a reply — wait for reconnect and retry.
|
# Lost connection before we got a reply — wait for reconnect and retry.
|
||||||
|
_stop_pulse()
|
||||||
_set_status("Connection lost. Waiting to reconnect…")
|
_set_status("Connection lost. Waiting to reconnect…")
|
||||||
Network.connected.connect(_start, CONNECT_ONE_SHOT)
|
Network.connected.connect(_start, CONNECT_ONE_SHOT)
|
||||||
return
|
return
|
||||||
@@ -99,20 +132,26 @@ func _on_version_error(code: String) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _do_sync() -> void:
|
func _do_sync() -> void:
|
||||||
|
_stop_pulse()
|
||||||
|
_expected_total = max(ContentCache.definition_count(), 1)
|
||||||
var cached := ContentCache.definition_count()
|
var cached := ContentCache.definition_count()
|
||||||
if cached > 0:
|
if cached > 0:
|
||||||
_set_status("Syncing card database… (%d cached)" % cached)
|
_set_status("Syncing card database…")
|
||||||
else:
|
else:
|
||||||
_set_status("Downloading card database…")
|
_set_status("Downloading card database…")
|
||||||
|
progress_bar.value = 5.0
|
||||||
ContentCache.start_sync()
|
ContentCache.start_sync()
|
||||||
|
|
||||||
# ── ContentCache signal handlers ──────────────────────────────────────────────
|
# ── ContentCache signal handlers ──────────────────────────────────────────────
|
||||||
|
|
||||||
func _on_sync_progress(fetched_total: int) -> void:
|
func _on_sync_progress(fetched_total: int) -> void:
|
||||||
_set_status("Syncing card database… (%d cards)" % fetched_total)
|
_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)
|
||||||
|
|
||||||
|
|
||||||
func _on_sync_complete(_total: int) -> void:
|
func _on_sync_complete(_total: int) -> void:
|
||||||
|
progress_bar.value = 90.0
|
||||||
_check_active_session()
|
_check_active_session()
|
||||||
|
|
||||||
|
|
||||||
@@ -164,10 +203,12 @@ func _on_active_session(payload: Variant) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _go_to_main() -> void:
|
func _go_to_main() -> void:
|
||||||
|
progress_bar.value = 100.0
|
||||||
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
|
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
|
||||||
|
|
||||||
|
|
||||||
func _on_sync_failed(error: String) -> void:
|
func _on_sync_failed(error: String) -> void:
|
||||||
|
_stop_pulse()
|
||||||
_set_status("Sync failed: %s" % error)
|
_set_status("Sync failed: %s" % error)
|
||||||
retry_btn.visible = true
|
retry_btn.visible = true
|
||||||
|
|
||||||
@@ -175,3 +216,20 @@ func _on_sync_failed(error: String) -> void:
|
|||||||
|
|
||||||
func _set_status(text: String) -> void:
|
func _set_status(text: String) -> void:
|
||||||
status_label.text = text
|
status_label.text = text
|
||||||
|
|
||||||
|
|
||||||
|
## Pulse the progress bar back and forth to signal indeterminate activity.
|
||||||
|
func _start_pulse() -> void:
|
||||||
|
_stop_pulse()
|
||||||
|
progress_bar.value = 0.0
|
||||||
|
_pulse_tween = create_tween().set_loops()
|
||||||
|
_pulse_tween.tween_property(progress_bar, "value", 12.0, 0.8) \
|
||||||
|
.set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_SINE)
|
||||||
|
_pulse_tween.tween_property(progress_bar, "value", 0.0, 0.8) \
|
||||||
|
.set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_SINE)
|
||||||
|
|
||||||
|
|
||||||
|
func _stop_pulse() -> void:
|
||||||
|
if _pulse_tween:
|
||||||
|
_pulse_tween.kill()
|
||||||
|
_pulse_tween = null
|
||||||
|
|||||||
Reference in New Issue
Block a user