feat(desktop): enhance error handling and logging for session synchronization and window mode transitions
Desktop Client Build / Resolve Build Metadata (push) Successful in 24s
Desktop Client Build / Build Desktop Client (push) Successful in 22m50s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 27s

This commit is contained in:
2026-06-04 16:39:30 +08:00
parent ae455ea21c
commit b40434018a
6 changed files with 85 additions and 22 deletions
+13 -2
View File
@@ -30,7 +30,14 @@ function getModeBridge(): WindowModeBridge | undefined {
}
function syncWindowMode(authenticated: boolean): void {
void getModeBridge()?.setWindowMode?.(authenticated ? 'main' : 'login', { source: 'auth-state' })
void getModeBridge()
?.setWindowMode?.(authenticated ? 'main' : 'login', { source: 'auth-state' })
.catch((err) => {
console.warn('[desktop-app] window mode sync failed', {
authenticated,
message: err instanceof Error ? err.message : String(err),
})
})
}
const rendererWindowMode = resolveRendererWindowMode()
@@ -62,7 +69,11 @@ if (rendererWindowMode === 'main') {
onMounted(() => {
if (rendererWindowMode !== 'login') {
void syncRuntimeSession()
void syncRuntimeSession().catch((err) => {
console.warn('[desktop-app] runtime session sync failed', {
message: err instanceof Error ? err.message : String(err),
})
})
}
if (usesAutomaticWindowMode) {
syncWindowMode(isAuthenticated.value)
@@ -55,6 +55,13 @@ let logoutPromise: Promise<void> | null = null
let renewPromise: Promise<void> | null = null
let tokenRenewTimer: ReturnType<typeof setInterval> | null = null
function logRuntimeSessionSyncFailure(reason: string, err: unknown): void {
console.warn('[desktop-session] runtime session sync failed', {
reason,
message: err instanceof Error ? err.message : String(err),
})
}
function readStoredSession(): DesktopSession | null {
if (typeof window === 'undefined') {
return null
@@ -117,7 +124,9 @@ function persistSession(next: DesktopSession | null): void {
window.localStorage.setItem(sessionStorageKey, JSON.stringify(next))
}
void syncRuntimeSessionToMain(next)
void syncRuntimeSessionToMain(next).catch((err) => {
logRuntimeSessionSyncFailure('persist-session', err)
})
}
function readStoredApiBaseURL(): string {
@@ -141,7 +150,9 @@ function persistApiBaseURL(value: string): void {
window.localStorage.setItem(apiBaseURLStorageKey, normalized)
}
void syncRuntimeSessionToMain()
void syncRuntimeSessionToMain().catch((err) => {
logRuntimeSessionSyncFailure('api-base-url-change', err)
})
}
function createPublicClient() {
@@ -753,7 +764,9 @@ if (typeof window !== 'undefined') {
window.addEventListener('storage', (event) => {
if (event.key === apiBaseURLStorageKey) {
apiBaseURL.value = normalizeDesktopApiBaseURL(event.newValue, normalizedDefaultApiBaseURL)
void syncRuntimeSessionToMain()
void syncRuntimeSessionToMain().catch((err) => {
logRuntimeSessionSyncFailure('storage-api-base-url-change', err)
})
}
})
void syncStoredDesktopClientDeviceInfo()
@@ -62,7 +62,13 @@ async function submitLogin() {
password: form.password,
})
await persistCredentialsPreference()
await window.desktopBridge?.app?.setWindowMode?.('main', { source: 'login' })
try {
await window.desktopBridge?.app?.setWindowMode?.('main', { source: 'login' })
} catch (err) {
console.warn('[login-view] switch to main window failed', {
message: err instanceof Error ? err.message : String(err),
})
}
}
async function hydrateSavedCredentials() {