From d74cf98f6f73dfad8f9596c3640004165393d537 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Thu, 25 Dec 2025 15:46:49 +0100 Subject: [PATCH] feat: Make sure to restore spaces even when restore is disabled, b=closes #11724, c=no-component --- .../sessionstore/SessionStartup-sys-mjs.patch | 16 ++++- .../sessionstore/SessionStore-sys-mjs.patch | 60 +++++++++++-------- .../sessionstore/ZenSessionManager.sys.mjs | 17 +++++- 3 files changed, 66 insertions(+), 27 deletions(-) diff --git a/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch b/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch index b106193cf..3cbbdd679 100644 --- a/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStartup.sys.mjs b/browser/components/sessionstore/SessionStartup.sys.mjs -index be23213ae9ec7e59358a17276c6c3764d38d9996..ca5a8ccc916ceeab5140f1278d15233cefbe5815 100644 +index be23213ae9ec7e59358a17276c6c3764d38d9996..b6a4110ee50e5977125feb7bd32e84e5e527adc6 100644 --- a/browser/components/sessionstore/SessionStartup.sys.mjs +++ b/browser/components/sessionstore/SessionStartup.sys.mjs @@ -40,6 +40,7 @@ ChromeUtils.defineESModuleGetters(lazy, { @@ -19,3 +19,17 @@ index be23213ae9ec7e59358a17276c6c3764d38d9996..ca5a8ccc916ceeab5140f1278d15233c if (this._initialState == null) { // No valid session found. this._sessionType = this.NO_SESSION; +@@ -335,12 +338,7 @@ export var SessionStartup = { + isAutomaticRestoreEnabled() { + if (this._resumeSessionEnabled === null) { + this._resumeSessionEnabled = +- !lazy.PrivateBrowsingUtils.permanentPrivateBrowsing && +- (Services.prefs.getBoolPref( +- "browser.sessionstore.resume_session_once" +- ) || +- Services.prefs.getIntPref("browser.startup.page") == +- BROWSER_STARTUP_RESUME_SESSION); ++ !lazy.PrivateBrowsingUtils.permanentPrivateBrowsing; + } + + return this._resumeSessionEnabled; diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index f9a69b9e2..9021801e8 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bcdd8a572f 100644 +index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..0deff2a0238fa3822387fddd44ddd21451b6e8eb 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -127,6 +127,8 @@ const TAB_EVENTS = [ @@ -19,7 +19,19 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc }); ChromeUtils.defineLazyGetter(lazy, "blankURI", () => { -@@ -1911,6 +1914,8 @@ var SessionStoreInternal = { +@@ -1238,10 +1241,7 @@ var SessionStoreInternal = { + */ + get willAutoRestore() { + return ( +- !PrivateBrowsingUtils.permanentPrivateBrowsing && +- (Services.prefs.getBoolPref("browser.sessionstore.resume_session_once") || +- Services.prefs.getIntPref("browser.startup.page") == +- BROWSER_STARTUP_RESUME_SESSION) ++ !PrivateBrowsingUtils.permanentPrivateBrowsing + ); + }, + +@@ -1911,6 +1911,8 @@ var SessionStoreInternal = { case "TabPinned": case "TabUnpinned": case "SwapDocShells": @@ -28,7 +40,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc this.saveStateDelayed(win); break; case "TabGroupCreate": -@@ -2020,6 +2025,10 @@ var SessionStoreInternal = { +@@ -2020,6 +2022,10 @@ var SessionStoreInternal = { this._windows[aWindow.__SSi].isTaskbarTab = true; } @@ -39,7 +51,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc let tabbrowser = aWindow.gBrowser; // add tab change listeners to all already existing tabs -@@ -2107,6 +2116,7 @@ var SessionStoreInternal = { +@@ -2107,6 +2113,7 @@ var SessionStoreInternal = { null, "sessionstore-one-or-no-tab-restored" ); @@ -47,7 +59,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc this._deferredAllWindowsRestored.resolve(); } // this window was opened by _openWindowWithState -@@ -2151,7 +2161,6 @@ var SessionStoreInternal = { +@@ -2151,7 +2158,6 @@ var SessionStoreInternal = { if (closedWindowState) { let newWindowState; if ( @@ -55,7 +67,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc !lazy.SessionStartup.willRestore() ) { // We want to split the window up into pinned tabs and unpinned tabs. -@@ -2215,6 +2224,15 @@ var SessionStoreInternal = { +@@ -2215,6 +2221,15 @@ var SessionStoreInternal = { }); this._shouldRestoreLastSession = false; } @@ -71,7 +83,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc if (this._restoreLastWindow && aWindow.toolbar.visible) { // always reset (if not a popup window) -@@ -2465,7 +2483,7 @@ var SessionStoreInternal = { +@@ -2465,7 +2480,7 @@ var SessionStoreInternal = { // 2) Flush the window. // 3) When the flush is complete, revisit our decision to store the window // in _closedWindows, and add/remove as necessary. @@ -80,7 +92,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc this.maybeSaveClosedWindow(winData, isLastWindow); } -@@ -2486,7 +2504,7 @@ var SessionStoreInternal = { +@@ -2486,7 +2501,7 @@ var SessionStoreInternal = { // Save non-private windows if they have at // least one saveable tab or are the last window. @@ -89,7 +101,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc this.maybeSaveClosedWindow(winData, isLastWindow); if (!isLastWindow && winData.closedId > -1) { -@@ -2582,6 +2600,7 @@ var SessionStoreInternal = { +@@ -2582,6 +2597,7 @@ var SessionStoreInternal = { let alreadyStored = winIndex != -1; // If sidebar command is truthy, i.e. sidebar is open, store sidebar settings let shouldStore = hasSaveableTabs || isLastWindow; @@ -97,7 +109,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc if (shouldStore && !alreadyStored) { let index = this._closedWindows.findIndex(win => { -@@ -3373,7 +3392,7 @@ var SessionStoreInternal = { +@@ -3373,7 +3389,7 @@ var SessionStoreInternal = { if (!isPrivateWindow && tabState.isPrivate) { return; } @@ -106,7 +118,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc return; } -@@ -4089,6 +4108,12 @@ var SessionStoreInternal = { +@@ -4089,6 +4105,12 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; @@ -119,7 +131,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -4525,6 +4550,7 @@ var SessionStoreInternal = { +@@ -4525,6 +4547,7 @@ var SessionStoreInternal = { // Append the tab if we're opening into a different window, tabIndex: aSource == aTargetWindow ? pos : Infinity, pinned: state.pinned, @@ -127,7 +139,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc userContextId: state.userContextId, skipLoad: true, preferredRemoteType, -@@ -5032,7 +5058,10 @@ var SessionStoreInternal = { +@@ -5032,7 +5055,10 @@ var SessionStoreInternal = { !activePageData || (activePageData && activePageData.url != "about:blank") ) { @@ -138,7 +150,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc } lazy.TabStateCache.update(browser.permanentKey, { image: null, -@@ -5374,7 +5403,7 @@ var SessionStoreInternal = { +@@ -5374,7 +5400,7 @@ var SessionStoreInternal = { for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) { let tab = tabbrowser.tabs[i]; @@ -147,7 +159,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc removableTabs.push(tab); } } -@@ -5483,7 +5512,7 @@ var SessionStoreInternal = { +@@ -5483,7 +5509,7 @@ var SessionStoreInternal = { // collect the data for all windows for (ix in this._windows) { @@ -156,7 +168,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc // window data is still in _statesToRestore continue; } -@@ -5625,11 +5654,12 @@ var SessionStoreInternal = { +@@ -5625,11 +5651,12 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -170,7 +182,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc // update the internal state data for this window for (let tab of tabs) { if (tab == aWindow.FirefoxViewHandler.tab) { -@@ -5640,6 +5670,9 @@ var SessionStoreInternal = { +@@ -5640,6 +5667,9 @@ var SessionStoreInternal = { tabsData.push(tabData); } @@ -180,7 +192,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc // update tab group state for this window winData.groups = []; for (let tabGroup of aWindow.gBrowser.tabGroups) { -@@ -5652,7 +5685,7 @@ var SessionStoreInternal = { +@@ -5652,7 +5682,7 @@ var SessionStoreInternal = { // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). if (aWindow.FirefoxViewHandler.tab?.selected) { @@ -189,7 +201,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc winData.title = tabbrowser.tabs[0].label; } winData.selected = selectedIndex; -@@ -5765,8 +5798,8 @@ var SessionStoreInternal = { +@@ -5765,8 +5795,8 @@ var SessionStoreInternal = { // selectTab represents. let selectTab = 0; if (overwriteTabs) { @@ -200,7 +212,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc selectTab = Math.min(selectTab, winData.tabs.length); } -@@ -5788,6 +5821,7 @@ var SessionStoreInternal = { +@@ -5788,6 +5818,7 @@ var SessionStoreInternal = { if (overwriteTabs) { for (let i = tabbrowser.browsers.length - 1; i >= 0; i--) { if (!tabbrowser.tabs[i].selected) { @@ -208,7 +220,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc tabbrowser.removeTab(tabbrowser.tabs[i]); } } -@@ -5821,6 +5855,9 @@ var SessionStoreInternal = { +@@ -5821,6 +5852,9 @@ var SessionStoreInternal = { savedTabGroup => !openTabGroupIdsInWindow.has(savedTabGroup.id) ); } @@ -218,7 +230,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc // Move the originally open tabs to the end. if (initialTabs) { -@@ -6372,6 +6409,25 @@ var SessionStoreInternal = { +@@ -6372,6 +6406,25 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -244,7 +256,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc if (tabData.pinned) { tabbrowser.pinTab(tab); -@@ -7290,7 +7346,7 @@ var SessionStoreInternal = { +@@ -7290,7 +7343,7 @@ var SessionStoreInternal = { let groupsToSave = new Map(); for (let tIndex = 0; tIndex < window.tabs.length; ) { @@ -253,7 +265,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..4e54fb8ae1a4735a4437c469f2d974bc // Adjust window.selected if (tIndex + 1 < window.selected) { window.selected -= 1; -@@ -7305,7 +7361,7 @@ var SessionStoreInternal = { +@@ -7305,7 +7358,7 @@ var SessionStoreInternal = { ); // We don't want to increment tIndex here. continue; diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index d6a31eec3..07605d741 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -26,6 +26,9 @@ const SHOULD_BACKUP_FILE = Services.prefs.getBoolPref('zen.session-store.backup- const FILE_NAME = SHOULD_COMPRESS_FILE ? 'zen-sessions.jsonlz4' : 'zen-sessions.json'; const MIGRATION_PREF = 'zen.ui.migration.session-manager-restore'; +// 'browser.startup.page' preference value to resume the previous session. +const BROWSER_STARTUP_RESUME_SESSION = 3; + /** * Class representing the sidebar object stored in the session file. * This object holds all the data related to tabs, groups, folders @@ -168,6 +171,17 @@ export class nsZenSessionManager { if (!initialState.windows?.length) { initialState.windows = [{}]; } + // When we don't have browser.startup.page set to resume session, + // we only want to restore the pinned tabs into the new windows. + if ( + Services.prefs.getIntPref('browser.startup.page', 1) !== BROWSER_STARTUP_RESUME_SESSION && + this.#sidebar?.tabs + ) { + this.log('Restoring only pinned tabs into windows'); + const sidebar = this.#sidebar; + sidebar.tabs = (sidebar.tabs || []).filter((tab) => tab.pinned); + this.#sidebar = sidebar; + } // Restore all windows with the same sidebar object, this will // guarantee that all tabs, groups, folders and split view data // are properly synced across all windows. @@ -283,8 +297,7 @@ export class nsZenSessionManager { * We do this in order to make sure all new window objects * have the same sidebar data. * - * @param aWindowData - * The window data object to restore into. + * @param aWindowData The window data object to restore into. */ #restoreWindowData(aWindowData) { const sidebar = this.#sidebar;