mirror of
https://github.com/zen-browser/desktop.git
synced 2026-08-12 17:55:19 +00:00
feat: Always make sure to save the last closed window to the sidebar object, 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 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520bd2b354b8 100644
|
||||
index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..cc9185308c83abfa173041a10edbcb9bbfa3d264 100644
|
||||
--- a/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
+++ b/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
@@ -127,6 +127,8 @@ const TAB_EVENTS = [
|
||||
@@ -81,7 +81,15 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
this.maybeSaveClosedWindow(winData, isLastWindow);
|
||||
|
||||
if (!isLastWindow && winData.closedId > -1) {
|
||||
@@ -3373,7 +3390,7 @@ var SessionStoreInternal = {
|
||||
@@ -2582,6 +2599,7 @@ 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);
|
||||
|
||||
if (shouldStore && !alreadyStored) {
|
||||
let index = this._closedWindows.findIndex(win => {
|
||||
@@ -3373,7 +3391,7 @@ var SessionStoreInternal = {
|
||||
if (!isPrivateWindow && tabState.isPrivate) {
|
||||
return;
|
||||
}
|
||||
@@ -90,7 +98,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4089,6 +4106,12 @@ var SessionStoreInternal = {
|
||||
@@ -4089,6 +4107,12 @@ var SessionStoreInternal = {
|
||||
Math.min(tabState.index, tabState.entries.length)
|
||||
);
|
||||
tabState.pinned = false;
|
||||
@@ -103,7 +111,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
|
||||
if (inBackground === false) {
|
||||
aWindow.gBrowser.selectedTab = newTab;
|
||||
@@ -4525,6 +4548,7 @@ var SessionStoreInternal = {
|
||||
@@ -4525,6 +4549,7 @@ var SessionStoreInternal = {
|
||||
// Append the tab if we're opening into a different window,
|
||||
tabIndex: aSource == aTargetWindow ? pos : Infinity,
|
||||
pinned: state.pinned,
|
||||
@@ -111,7 +119,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
userContextId: state.userContextId,
|
||||
skipLoad: true,
|
||||
preferredRemoteType,
|
||||
@@ -5374,7 +5398,7 @@ var SessionStoreInternal = {
|
||||
@@ -5374,7 +5399,7 @@ var SessionStoreInternal = {
|
||||
|
||||
for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) {
|
||||
let tab = tabbrowser.tabs[i];
|
||||
@@ -120,7 +128,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
removableTabs.push(tab);
|
||||
}
|
||||
}
|
||||
@@ -5483,7 +5507,7 @@ var SessionStoreInternal = {
|
||||
@@ -5483,7 +5508,7 @@ var SessionStoreInternal = {
|
||||
|
||||
// collect the data for all windows
|
||||
for (ix in this._windows) {
|
||||
@@ -129,7 +137,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
// window data is still in _statesToRestore
|
||||
continue;
|
||||
}
|
||||
@@ -5625,11 +5649,15 @@ var SessionStoreInternal = {
|
||||
@@ -5625,11 +5650,15 @@ var SessionStoreInternal = {
|
||||
}
|
||||
|
||||
let tabbrowser = aWindow.gBrowser;
|
||||
@@ -146,7 +154,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
// update the internal state data for this window
|
||||
for (let tab of tabs) {
|
||||
if (tab == aWindow.FirefoxViewHandler.tab) {
|
||||
@@ -5652,7 +5680,7 @@ var SessionStoreInternal = {
|
||||
@@ -5652,7 +5681,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) {
|
||||
@@ -155,7 +163,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
winData.title = tabbrowser.tabs[0].label;
|
||||
}
|
||||
winData.selected = selectedIndex;
|
||||
@@ -5765,8 +5793,8 @@ var SessionStoreInternal = {
|
||||
@@ -5765,8 +5794,8 @@ var SessionStoreInternal = {
|
||||
// selectTab represents.
|
||||
let selectTab = 0;
|
||||
if (overwriteTabs) {
|
||||
@@ -166,7 +174,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
selectTab = Math.min(selectTab, winData.tabs.length);
|
||||
}
|
||||
|
||||
@@ -5809,6 +5837,9 @@ var SessionStoreInternal = {
|
||||
@@ -5809,6 +5838,9 @@ var SessionStoreInternal = {
|
||||
winData.tabs,
|
||||
winData.groups ?? []
|
||||
);
|
||||
@@ -176,7 +184,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
this._log.debug(
|
||||
`restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs`
|
||||
);
|
||||
@@ -6372,6 +6403,25 @@ var SessionStoreInternal = {
|
||||
@@ -6372,6 +6404,25 @@ var SessionStoreInternal = {
|
||||
|
||||
// Most of tabData has been restored, now continue with restoring
|
||||
// attributes that may trigger external events.
|
||||
@@ -202,7 +210,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
|
||||
if (tabData.pinned) {
|
||||
tabbrowser.pinTab(tab);
|
||||
@@ -7290,7 +7340,7 @@ var SessionStoreInternal = {
|
||||
@@ -7290,7 +7341,7 @@ var SessionStoreInternal = {
|
||||
|
||||
let groupsToSave = new Map();
|
||||
for (let tIndex = 0; tIndex < window.tabs.length; ) {
|
||||
@@ -211,7 +219,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520b
|
||||
// Adjust window.selected
|
||||
if (tIndex + 1 < window.selected) {
|
||||
window.selected -= 1;
|
||||
@@ -7305,7 +7355,7 @@ var SessionStoreInternal = {
|
||||
@@ -7305,7 +7356,7 @@ var SessionStoreInternal = {
|
||||
);
|
||||
// We don't want to increment tIndex here.
|
||||
continue;
|
||||
|
||||
@@ -156,6 +156,24 @@ export class nsZenSessionManager {
|
||||
this.log(`Saving Zen session data with ${this.#sidebar.tabs?.length || 0} tabs`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the session data for a closed window if it meets the criteria.
|
||||
* See SessionStoreInternal.maybeSaveClosedWindow for more details.
|
||||
*
|
||||
* @param aWinData - The window data object to save.
|
||||
* @param isLastWindow - Whether this is the last saveable window.
|
||||
*/
|
||||
maybeSaveClosedWindow(aWinData, isLastWindow) {
|
||||
// We only want to save the *last* normal window that is closed.
|
||||
// If its not the last window, we can still update the sidebar object
|
||||
// based on other open windows.
|
||||
if (aWinData.isPopup || aWinData.isTaskbarTab || aWinData.isZenUnsynced || !isLastWindow) {
|
||||
return;
|
||||
}
|
||||
this.log('Saving closed window session data into Zen session store');
|
||||
this.saveState({ windows: [aWinData] });
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects session data for a given window.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user