11diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs
2- index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254fd98c027 100644
2+ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..1562a49c47f934b3f4372ce8ca74d5c0559b8ae7 100644
33--- a/browser/components/sessionstore/SessionStore.sys.mjs
44+++ b/browser/components/sessionstore/SessionStore.sys.mjs
55@@ -127,6 +127,9 @@ const TAB_EVENTS = [
@@ -95,34 +95,34 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
9595
9696 TAB_EVENTS.forEach(function (aEvent) {
9797 tabbrowser.tabContainer.removeEventListener(aEvent, this, true);
98- @@ -2477 ,7 +2495,10 @@ var SessionStoreInternal = {
99-
100- // This window has the potential to be saved in the _closedWindows
101- // array (maybeSaveClosedWindows gets the final call on that) .
102- + if (!Services.prefs.getBoolPref("zen.session-store.allow-restoring-closed-synced-windows", false)
103- + && ( winData.isTaskbarTab || winData.isPrivate || winData. isZenUnsynced) ) {
104- this._saveableClosedWindowData.add (winData);
105- + }
98+ @@ -2491 ,7 +2509,7 @@ var SessionStoreInternal = {
99+ // 2) Flush the window.
100+ // 3) When the flush is complete, revisit our decision to store the window
101+ // in _closedWindows, and add/remove as necessary .
102+ - if (!winData.isPrivate && !winData.isTaskbarTab) {
103+ + if (!winData.isPrivate && ! winData.isTaskbarTab && ! winData.isZenUnsynced) {
104+ this.maybeSaveClosedWindow (winData, isLastWindow );
105+ }
106106
107- // Now we have to figure out if this window is worth saving in the _closedWindows
108- // Object.
109- @@ -2512,6 +2533,7 @@ var SessionStoreInternal = {
107+ @@ -2512,7 +2530,8 @@ var SessionStoreInternal = {
110108
111109 // Save non-private windows if they have at
112110 // least one saveable tab or are the last window.
111+ - if (!winData.isPrivate && !winData.isTaskbarTab) {
113112+ lazy.ZenWindowSync.on_WindowCloseAndBrowserFlushed(browsers);
114- if (!winData.isPrivate && !winData.isTaskbarTab) {
113+ + if (!winData.isPrivate && !winData.isTaskbarTab && !winData.isZenUnsynced ) {
115114 this.maybeSaveClosedWindow(winData, isLastWindow);
116115
117- @@ -2590,6 +2612,7 @@ var SessionStoreInternal = {
118- * a window flush).
119- */
120- maybeSaveClosedWindow(winData, isLastWindow) {
121- + lazy.ZenSessionStore.maybeSaveClosedWindow(winData, isLastWindow);
122- // Make sure SessionStore is still running, and make sure that we
123- // haven't chosen to forget this window.
124- if (
125- @@ -3408,7 +3431,7 @@ var SessionStoreInternal = {
116+ if (!isLastWindow && winData.closedId > -1) {
117+ @@ -2608,6 +2627,7 @@ var SessionStoreInternal = {
118+ let alreadyStored = winIndex != -1;
119+ // If sidebar command is truthy, i.e. sidebar is open, store sidebar settings
120+ let shouldStore = hasSaveableTabs || isLastWindow;
121+ + lazy.ZenSessionStore.maybeSaveClosedWindow(winData, isLastWindow);
122+
123+ if (shouldStore && !alreadyStored) {
124+ let index = this._closedWindows.findIndex(win => {
125+ @@ -3408,7 +3428,7 @@ var SessionStoreInternal = {
126126 if (!isPrivateWindow && tabState.isPrivate) {
127127 return;
128128 }
@@ -131,7 +131,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
131131 return;
132132 }
133133
134- @@ -4129,6 +4152 ,12 @@ var SessionStoreInternal = {
134+ @@ -4129,6 +4149 ,12 @@ var SessionStoreInternal = {
135135 Math.min(tabState.index, tabState.entries.length)
136136 );
137137 tabState.pinned = false;
@@ -144,7 +144,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
144144
145145 if (inBackground === false) {
146146 aWindow.gBrowser.selectedTab = newTab;
147- @@ -4565,6 +4594 ,8 @@ var SessionStoreInternal = {
147+ @@ -4565,6 +4591 ,8 @@ var SessionStoreInternal = {
148148 // Append the tab if we're opening into a different window,
149149 tabIndex: aSource == aTargetWindow ? pos : Infinity,
150150 pinned: state.pinned,
@@ -153,7 +153,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
153153 userContextId: state.userContextId,
154154 skipLoad: true,
155155 preferredRemoteType,
156- @@ -5414,7 +5445 ,7 @@ var SessionStoreInternal = {
156+ @@ -5414,7 +5442 ,7 @@ var SessionStoreInternal = {
157157
158158 for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) {
159159 let tab = tabbrowser.tabs[i];
@@ -162,7 +162,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
162162 removableTabs.push(tab);
163163 }
164164 }
165- @@ -5525,7 +5556 ,7 @@ var SessionStoreInternal = {
165+ @@ -5525,7 +5553 ,7 @@ var SessionStoreInternal = {
166166
167167 // collect the data for all windows
168168 for (ix in this._windows) {
@@ -171,7 +171,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
171171 // window data is still in _statesToRestore
172172 continue;
173173 }
174- @@ -5668,11 +5699 ,12 @@ var SessionStoreInternal = {
174+ @@ -5668,11 +5696 ,12 @@ var SessionStoreInternal = {
175175 }
176176
177177 let tabbrowser = aWindow.gBrowser;
@@ -185,7 +185,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
185185 // update the internal state data for this window
186186 for (let tab of tabs) {
187187 if (tab == aWindow.FirefoxViewHandler.tab) {
188- @@ -5683,6 +5715 ,9 @@ var SessionStoreInternal = {
188+ @@ -5683,6 +5712 ,9 @@ var SessionStoreInternal = {
189189 tabsData.push(tabData);
190190 }
191191
@@ -195,7 +195,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
195195 // update tab group state for this window
196196 winData.groups = [];
197197 for (let tabGroup of aWindow.gBrowser.tabGroups) {
198- @@ -5695,7 +5730 ,7 @@ var SessionStoreInternal = {
198+ @@ -5695,7 +5727 ,7 @@ var SessionStoreInternal = {
199199 // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab,
200200 // since it's only inserted into the tab strip after it's selected).
201201 if (aWindow.FirefoxViewHandler.tab?.selected) {
@@ -204,7 +204,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
204204 winData.title = tabbrowser.tabs[0].label;
205205 }
206206 winData.selected = selectedIndex;
207- @@ -5810,8 +5845 ,8 @@ var SessionStoreInternal = {
207+ @@ -5810,8 +5842 ,8 @@ var SessionStoreInternal = {
208208 // selectTab represents.
209209 let selectTab = 0;
210210 if (overwriteTabs) {
@@ -215,15 +215,15 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
215215 selectTab = Math.min(selectTab, winData.tabs.length);
216216 }
217217
218- @@ -5833,6 +5868 ,7 @@ var SessionStoreInternal = {
218+ @@ -5833,6 +5865 ,7 @@ var SessionStoreInternal = {
219219 if (overwriteTabs) {
220220 for (let i = tabbrowser.browsers.length - 1; i >= 0; i--) {
221221 if (!tabbrowser.tabs[i].selected) {
222222+ aWindow.gZenWorkspaces._shouldOverrideTabs = true;
223223 tabbrowser.removeTab(tabbrowser.tabs[i]);
224224 }
225225 }
226- @@ -5866,6 +5902 ,12 @@ var SessionStoreInternal = {
226+ @@ -5866,6 +5899 ,12 @@ var SessionStoreInternal = {
227227 savedTabGroup => !openTabGroupIdsInWindow.has(savedTabGroup.id)
228228 );
229229 }
@@ -236,7 +236,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
236236
237237 // Move the originally open tabs to the end.
238238 if (initialTabs) {
239- @@ -6419,6 +6461 ,25 @@ var SessionStoreInternal = {
239+ @@ -6419,6 +6458 ,25 @@ var SessionStoreInternal = {
240240
241241 // Most of tabData has been restored, now continue with restoring
242242 // attributes that may trigger external events.
@@ -262,7 +262,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
262262
263263 if (tabData.pinned) {
264264 tabbrowser.pinTab(tab);
265- @@ -7343,7 +7404 ,7 @@ var SessionStoreInternal = {
265+ @@ -7343,7 +7401 ,7 @@ var SessionStoreInternal = {
266266
267267 let groupsToSave = new Map();
268268 for (let tIndex = 0; tIndex < window.tabs.length; ) {
@@ -271,7 +271,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254
271271 // Adjust window.selected
272272 if (tIndex + 1 < window.selected) {
273273 window.selected -= 1;
274- @@ -7358,7 +7419 ,7 @@ var SessionStoreInternal = {
274+ @@ -7358,7 +7416 ,7 @@ var SessionStoreInternal = {
275275 );
276276 // We don't want to increment tIndex here.
277277 continue;
0 commit comments