mirror of
https://github.com/zen-browser/desktop.git
synced 2026-01-25 06:06:10 +00:00
fix: Make sure to save the state of the last restored 'normal' window, b=no-bug, c=no-component
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
index 2a055f0c5f34f0a2667f659185120c07d38f4e41..cd350d9e787c1ef0d1dffcb7d872b9c2e8fe19ff 100644
|
||||
index 2a055f0c5f34f0a2667f659185120c07d38f4e41..5b16b12fb02799b12543294a9fccceef47067d53 100644
|
||||
--- a/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
+++ b/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
@@ -127,6 +127,9 @@ const TAB_EVENTS = [
|
||||
@@ -95,15 +95,26 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..cd350d9e787c1ef0d1dffcb7d872b9c2
|
||||
|
||||
TAB_EVENTS.forEach(function (aEvent) {
|
||||
tabbrowser.tabContainer.removeEventListener(aEvent, this, true);
|
||||
@@ -2491,7 +2509,7 @@ var SessionStoreInternal = {
|
||||
@@ -2434,7 +2452,7 @@ var SessionStoreInternal = {
|
||||
|
||||
let isLastRegularWindow =
|
||||
Object.values(this._windows).filter(
|
||||
- wData => !wData.isPrivate && !wData.isTaskbarTab
|
||||
+ wData => !wData.isPrivate && !wData.isTaskbarTab && !wData.isZenUnsynced
|
||||
).length == 1;
|
||||
this._log.debug(
|
||||
`onClose, closing window isLastRegularWindow? ${isLastRegularWindow}`
|
||||
@@ -2491,8 +2509,8 @@ 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.
|
||||
- if (!winData.isPrivate && !winData.isTaskbarTab) {
|
||||
- this.maybeSaveClosedWindow(winData, isLastWindow);
|
||||
+ if (!winData.isPrivate && !winData.isTaskbarTab && !winData.isZenUnsynced) {
|
||||
this.maybeSaveClosedWindow(winData, isLastWindow);
|
||||
+ this.maybeSaveClosedWindow(winData, isLastWindow, isLastRegularWindow);
|
||||
}
|
||||
|
||||
completionPromise = lazy.TabStateFlusher.flushWindow(aWindow).then(() => {
|
||||
@@ -2512,7 +2530,8 @@ var SessionStoreInternal = {
|
||||
|
||||
// Save non-private windows if they have at
|
||||
@@ -114,11 +125,20 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..cd350d9e787c1ef0d1dffcb7d872b9c2
|
||||
this.maybeSaveClosedWindow(winData, isLastWindow);
|
||||
|
||||
if (!isLastWindow && winData.closedId > -1) {
|
||||
@@ -2589,7 +2608,7 @@ var SessionStoreInternal = {
|
||||
* to call this method again asynchronously (for example, after
|
||||
* a window flush).
|
||||
*/
|
||||
- maybeSaveClosedWindow(winData, isLastWindow) {
|
||||
+ maybeSaveClosedWindow(winData, isLastWindow, isLastRegularWindow = false) {
|
||||
// Make sure SessionStore is still running, and make sure that we
|
||||
// haven't chosen to forget this window.
|
||||
if (
|
||||
@@ -2608,6 +2627,9 @@ var SessionStoreInternal = {
|
||||
let alreadyStored = winIndex != -1;
|
||||
// If sidebar command is truthy, i.e. sidebar is open, store sidebar settings
|
||||
let shouldStore = hasSaveableTabs || isLastWindow;
|
||||
+ lazy.ZenSessionStore.maybeSaveClosedWindow(winData, isLastWindow);
|
||||
+ lazy.ZenSessionStore.maybeSaveClosedWindow(winData, isLastRegularWindow);
|
||||
+ // TODO: Do we want to store closed Zen windows? All of them are synced anyways
|
||||
+ shouldStore = false;
|
||||
|
||||
|
||||
@@ -577,7 +577,7 @@ class nsZenWindowSync {
|
||||
* @param {object} aOtherTab - The tab in the other window.
|
||||
*/
|
||||
async #swapBrowserDocShellsAsync(aOurTab, aOtherTab) {
|
||||
let promise = this.#maybeFlushTabState(aOurTab);
|
||||
let promise = this.#maybeFlushTabState(aOtherTab);
|
||||
await this.#styleSwapedBrowsers(
|
||||
aOurTab,
|
||||
aOtherTab,
|
||||
@@ -644,13 +644,23 @@ class nsZenWindowSync {
|
||||
// See https://github.com/zen-browser/desktop/issues/11851, swapping the browsers
|
||||
// don't seem to update the state's cache properly, leading to issues when restoring
|
||||
// the session later on.
|
||||
let tabStateEntries = this.#getTabEntriesFromCache(aOurTab);
|
||||
let tabStateEntries = this.#getTabEntriesFromCache(aOtherTab);
|
||||
const setStateToTab = () => {
|
||||
if (!tabStateEntries?.entries.length) {
|
||||
this.log(`Error: No tab state entries found for tab ${aOurTab.id} during swap`);
|
||||
return;
|
||||
}
|
||||
lazy.TabStateCache.update(aOurTab.linkedBrowser.permanentKey, {
|
||||
history: tabStateEntries,
|
||||
});
|
||||
};
|
||||
// Running `swapBrowsersAndCloseOther` doesn't expect us to use the tab after
|
||||
// the operation, so it doesn't really care about cleaning up the other tab.
|
||||
// We need to make a new tab progress listener for the other tab after the swap.
|
||||
this.#withRestoreTabProgressListener(
|
||||
aOtherTab,
|
||||
() => {
|
||||
setStateToTab();
|
||||
this.log(`Swapping docshells between windows for tab ${aOurTab.id}`);
|
||||
aOurTab.ownerGlobal.gBrowser.swapBrowsersAndCloseOther(aOurTab, aOtherTab, false);
|
||||
// Since we are moving progress listeners around, there's a chance that we
|
||||
@@ -701,13 +711,7 @@ class nsZenWindowSync {
|
||||
// we would start receiving invalid history changes from the the incorrect
|
||||
// browser view that was just swapped out.
|
||||
return this.#maybeFlushTabState(aOurTab).finally(() => {
|
||||
if (!tabStateEntries?.entries.length) {
|
||||
this.log(`Error: No tab state entries found for tab ${aOtherTab.id} during swap`);
|
||||
return;
|
||||
}
|
||||
lazy.TabStateCache.update(aOurTab.linkedBrowser.permanentKey, {
|
||||
history: tabStateEntries,
|
||||
});
|
||||
setStateToTab();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -905,7 +909,7 @@ class nsZenWindowSync {
|
||||
if (aTab.linkedBrowser) {
|
||||
cachedState = lazy.TabStateCache.get(aTab.linkedBrowser.permanentKey);
|
||||
}
|
||||
return cachedState?.history?.entries ? cachedState.history : { entries: [] };
|
||||
return cachedState?.history?.entries ? Cu.cloneInto(cachedState.history, {}) : { entries: [] };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user