From 9afbd1befd0a27c14cceb48723a4229611d9cdb6 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Mon, 26 Jan 2026 17:24:12 +0100 Subject: [PATCH] feat: Make sure to run a migration for deferred sessions as well, b=no-bug, c=tabs, workspaces --- .../sessionstore/ZenSessionManager.sys.mjs | 30 ++++++++++--------- src/zen/tabs/ZenPinnedTabManager.mjs | 2 +- src/zen/workspaces/ZenWorkspaces.mjs | 13 ++++++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index 60af2824b..15e410856 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -84,6 +84,7 @@ export class nsZenSessionManager { compression: "lz4", backupFile, }); + this.log("Session file path:", this.#file.path); this.#deferredBackupTask = new lazy.DeferredTask(async () => { await this.#createBackupsIfNeeded(); }, REGENERATION_DEBOUNCE_RATE_MS); @@ -206,6 +207,13 @@ export class nsZenSessionManager { * The initial session state read from the session file. */ onFileRead(initialState) { + // For the first time after migration, we restore the tabs + // That where going to be restored by SessionStore. The sidebar + // object will always be empty after migration because we haven't + // gotten the opportunity to save the session yet. + if (this._shouldRunMigration) { + initialState = this.#runStateMigration(initialState); + } if (!lazy.gWindowSyncEnabled) { if (initialState?.windows?.length && this.#shouldRestoreOnlyPinned) { this.log("Window sync disabled, restoring only pinned tabs"); @@ -216,13 +224,6 @@ export class nsZenSessionManager { } return initialState; } - // For the first time after migration, we restore the tabs - // That where going to be restored by SessionStore. The sidebar - // object will always be empty after migration because we haven't - // gotten the opportunity to save the session yet. - if (this._shouldRunMigration) { - initialState = this.#runStateMigration(initialState); - } // If there are no windows, we create an empty one. By default, // firefox would create simply a new empty window, but we want // to make sure that the sidebar object is properly initialized. @@ -266,9 +267,9 @@ export class nsZenSessionManager { } this.#restoreWindowData(winData); } - } else { + } else if (initialState) { this.log("Saving windata state after migration"); - this.saveState(initialState); + this.saveState(Cu.cloneInto(initialState, {})); } delete this._shouldRunMigration; return initialState; @@ -289,6 +290,7 @@ export class nsZenSessionManager { * @param {object} initialState * The initial session state read from the session file. */ + // eslint-disable-next-line complexity #runStateMigration(initialState) { this.log( "Restoring tabs from Places DB after migration", @@ -304,8 +306,11 @@ export class nsZenSessionManager { spaces: this._migrationData?.spaces || [], }; } - if (!initialState?.windows?.length && initialState?.lastSessionState) { - initialState = { ...initialState.lastSessionState }; + if ( + !initialState?.windows?.length && + (initialState?.lastSessionState || initialState?.deferredInitialState) + ) { + initialState = { ...(initialState.lastSessionState || initialState.deferredInitialState) }; } // There might be cases where there are no windows in the // initial state, for example if the user had 'restore previous @@ -342,9 +347,6 @@ export class nsZenSessionManager { } } } - // Save the state to the sidebar object so that it gets written - // to the session file. - delete this._migrationData; return initialState; } diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index ebe9b04b5..2803445ea 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -162,7 +162,7 @@ class nsZenPinnedTabManager extends nsZenDOMOperatedFeature { this._resetTabToStoredState(tab); } - async replacePinnedUrlWithCurrent(tab = undefined) { + replacePinnedUrlWithCurrent(tab = undefined) { tab ??= TabContextMenu.contextTab; if (!tab || !tab.pinned) { return; diff --git a/src/zen/workspaces/ZenWorkspaces.mjs b/src/zen/workspaces/ZenWorkspaces.mjs index 1502fccba..84727cdfb 100644 --- a/src/zen/workspaces/ZenWorkspaces.mjs +++ b/src/zen/workspaces/ZenWorkspaces.mjs @@ -6,6 +6,12 @@ import { nsZenThemePicker } from "chrome://browser/content/zen-components/ZenGradientGenerator.mjs"; +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs", +}); + /** * Zen Spaces manager. This class is mainly responsible for the UI * and user interactions but it also contains some logic to manage @@ -888,6 +894,13 @@ class nsZenWorkspaces { return Promise.resolve(); } const spacesFromStore = aWinData.spaces || []; + if ( + !this.privateWindowOrDisabled && + spacesFromStore.length === 0 && + lazy.ZenSessionStore._migrationData + ) { + spacesFromStore.push(...lazy.ZenSessionStore._migrationData.spaces); + } this._workspaceCache = spacesFromStore.length ? [...spacesFromStore] : [this.#createWorkspaceData("Space", undefined)];