fix: workspace restore crash — defer to setTimeout, wrap all imports
All checks were successful
Build & Sign Wraith / Build Windows + Sign (push) Successful in 3m17s

Workspace restore was running synchronously in onMounted which could
crash if saved connection IDs were stale. The import of
@tauri-apps/api/window for onCloseRequested could also fail in
certain contexts.

Fix: defer restore to setTimeout(500ms) so the app renders first,
wrap each reconnect in individual try/catch, wrap the window close
listener setup in try/catch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vantz Stockwell 2026-03-25 12:06:34 -04:00
parent 1b74527a62
commit 10e0a6b196

View File

@ -438,24 +438,29 @@ onMounted(async () => {
document.addEventListener("keydown", handleKeydown); document.addEventListener("keydown", handleKeydown);
await connectionStore.loadAll(); await connectionStore.loadAll();
// Restore workspace reconnect saved tabs // Restore workspace reconnect saved tabs (non-blocking, non-fatal)
try { setTimeout(async () => {
const workspace = await invoke<{ tabs: { connectionId: number; protocol: string; position: number }[] } | null>("load_workspace"); try {
if (workspace?.tabs?.length) { const workspace = await invoke<{ tabs: { connectionId: number; protocol: string; position: number }[] } | null>("load_workspace");
for (const tab of workspace.tabs.sort((a, b) => a.position - b.position)) { if (workspace?.tabs?.length) {
sessionStore.connect(tab.connectionId).catch(() => {}); for (const tab of workspace.tabs.sort((a, b) => a.position - b.position)) {
try { await sessionStore.connect(tab.connectionId); } catch {}
}
} }
} } catch {}
} catch {} }, 500);
// Save workspace on window close // Save workspace on window close (non-fatal)
const appWindow = await import("@tauri-apps/api/window").then(m => m.getCurrentWindow()); try {
appWindow.onCloseRequested(async () => { const { getCurrentWindow } = await import("@tauri-apps/api/window");
const tabs = sessionStore.sessions const appWindow = getCurrentWindow();
.filter(s => s.protocol === "ssh" || s.protocol === "rdp") appWindow.onCloseRequested(async () => {
.map((s, i) => ({ connectionId: s.connectionId, protocol: s.protocol, position: i })); const tabs = sessionStore.sessions
await invoke("save_workspace", { tabs }).catch(() => {}); .filter(s => s.protocol === "ssh" || s.protocol === "rdp")
}); .map((s, i) => ({ connectionId: s.connectionId, protocol: s.protocol, position: i }));
await invoke("save_workspace", { tabs }).catch(() => {});
});
} catch {}
// Check for updates on startup (non-blocking) // Check for updates on startup (non-blocking)
invoke<{ currentVersion: string; latestVersion: string; updateAvailable: boolean; downloadUrl: string }>("check_for_updates") invoke<{ currentVersion: string; latestVersion: string; updateAvailable: boolean; downloadUrl: string }>("check_for_updates")