This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

workspace-manager: save tabs before closing windows in ensureAnchorWindow

+21 -9
+21 -9
tools/workspace-manager/firefox-extension/background.js
··· 422 422 // ── Init ──────────────────────────────────────────────────── 423 423 424 424 async function init() { 425 - // Create anchor window immediately — doesn't need native messaging 426 - try { 427 - await ensureAnchorWindow(); 428 - } catch (e) { 429 - console.error("Failed to create anchor window:", e); 430 - } 431 - 432 - // Connect to native host for workspace integration 425 + // Connect to native host first — we need it to save existing tabs 433 426 connectNative(); 434 427 await new Promise((r) => setTimeout(r, 500)); 435 428 ··· 437 430 lastWorkspace = await getCurrentWorkspace(); 438 431 } catch (e) { 439 432 console.warn("Failed to get current workspace:", e); 433 + } 434 + 435 + const hadExistingWindows = (await browser.windows.getAll()).length > 0; 436 + 437 + // Save all existing tabs before creating the anchor window 438 + // (ensureAnchorWindow closes all windows, so save first) 439 + if (hadExistingWindows) { 440 + try { 441 + await saveAllTabs(); 442 + } catch (e) { 443 + console.error("Failed to save existing tabs before anchor creation:", e); 444 + } 445 + } 446 + 447 + // Create anchor window — closes existing windows via the for_window rule 448 + try { 449 + await ensureAnchorWindow(); 450 + } catch (e) { 451 + console.error("Failed to create anchor window:", e); 440 452 } 441 453 442 454 try { ··· 448 460 // Mark init complete — workspace changes from now on will restore tabs 449 461 initialized = true; 450 462 451 - // Restore tabs for the initial workspace if it has saved tabs 463 + // Restore tabs for the initial workspace if it has saved tabs from a previous session 452 464 if (lastWorkspace) { 453 465 const withFirefox = await getWorkspacesWithFirefox(); 454 466 if (!withFirefox.has(lastWorkspace)) {