fix(desktop): check backend updates when the connection becomes remote

The poller starts at mount, before the gateway connects, so its initial
checkBackendUpdates() ran while mode was still unset and no-op'd via the
remote-mode guard — leaving the backend button empty until the user clicked it.
Subscribe to $connection and re-check the backend when mode resolves to remote.
This commit is contained in:
yoniebans 2026-06-06 21:31:39 +02:00 committed by Teknium
parent cfaa46fcae
commit 47518bc913

View file

@ -383,6 +383,8 @@ function ingestProgress(payload: DesktopUpdateProgress): void {
let pollerStarted = false
let backgroundTimer: ReturnType<typeof setInterval> | null = null
let lastFocusAt = 0
let connectionUnsub: (() => void) | null = null
let lastConnectionMode: string | undefined
/** Wire up background polling + progress streaming. Idempotent. */
export function startUpdatePoller(): void {
@ -402,6 +404,19 @@ export function startUpdatePoller(): void {
void refreshDesktopVersion()
bridge.onProgress(ingestProgress)
// The poller starts at mount, before the gateway connects — so the first
// backend check above sees mode≠remote and no-ops. Re-check once the
// connection resolves to remote.
connectionUnsub = $connection.subscribe(conn => {
if (conn?.mode === lastConnectionMode) {
return
}
lastConnectionMode = conn?.mode
if (conn?.mode === 'remote') {
void checkBackendUpdates()
}
})
window.addEventListener('focus', onFocus)
backgroundTimer = setInterval(() => {
void checkUpdates()
@ -415,6 +430,9 @@ export function stopUpdatePoller(): void {
backgroundTimer = null
}
connectionUnsub?.()
connectionUnsub = null
lastConnectionMode = undefined
window.removeEventListener('focus', onFocus)
pollerStarted = false
}