This repository has no description
0

Configure Feed

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

workspace-manager: don't save a workspace holding several Firefox windows

+19
+19
tools/workspace-manager/firefox-extension/background.js
··· 99 99 // Throws on query failure so callers can distinguish "no Firefox windows" 100 100 // from "we don't know" — a silent empty result here under load caused 101 101 // duplicate window restoration. 102 + // 103 + // A workspace holding more than one Firefox window is ambiguous and is left 104 + // out of the map. This happens after every Firefox restart: session restore 105 + // reopens all windows on the focused workspace, and mapping any one of them to 106 + // that workspace would overwrite its file with another workspace's tabs. 102 107 async function getFirefoxWindowMappings() { 103 108 const resp = await sendNative("map_windows"); 104 109 if (resp.error) throw new Error(resp.error); 105 110 if (!resp.windows) throw new Error("map_windows: no windows field"); 111 + 112 + const perWorkspace = new Map(); 113 + for (const mapping of resp.windows) { 114 + perWorkspace.set( 115 + mapping.workspace, 116 + (perWorkspace.get(mapping.workspace) || 0) + 1, 117 + ); 118 + } 106 119 107 120 const allWindows = await browser.windows.getAll({ populate: true }); 108 121 const result = new Map(); 109 122 const matched = new Set(); 110 123 111 124 for (const mapping of resp.windows) { 125 + if (perWorkspace.get(mapping.workspace) > 1) { 126 + console.warn( 127 + `Workspace ${mapping.workspace} has several Firefox windows — not mapping it`, 128 + ); 129 + continue; 130 + } 112 131 const swayTitle = mapping.windowTitle || ""; 113 132 for (const win of allWindows) { 114 133 if (matched.has(win.id) || win.id === anchorWindowId) continue;