feat: Fixed closing windows on macos not returning to the original views, b=no-bug, c=no-component

This commit is contained in:
mr. m
2025-12-12 16:12:18 +01:00
parent 097c7ed17b
commit 38aad02d07
2 changed files with 16 additions and 6 deletions

View File

@@ -255,7 +255,7 @@ export class nsZenSessionManager {
const windows = (state.windows || []).filter(
(win) => !win.isPrivate && !win.isPopup && !win.isTaskbarTab && !win.isZenUnsynced
);
let windowToClone = windows[0] || {};
let windowToClone = windows.length > 1 ? windows[windows.length - 2] : {};
let newWindow = Cu.cloneInto(windowToClone, {});
if (windows.length < 2) {
// We only want to restore the sidebar object if we found
@@ -286,7 +286,7 @@ export class nsZenSessionManager {
firstWindow: true,
});
resolvePromise();
lazy.setTimeout(resolvePromise);
});
}
}

View File

@@ -17,7 +17,7 @@ XPCOMUtils.defineLazyPreferenceGetter(lazy, 'gWindowSyncEnabled', 'zen.window-sy
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'gShouldLog', 'zen.window-sync.log', true);
const OBSERVING = ['browser-window-before-show'];
const INSTANT_EVENTS = ['unload'];
const INSTANT_EVENTS = ['SSWindowClosing'];
const EVENTS = [
'TabOpen',
'TabClose',
@@ -203,7 +203,7 @@ class nsZenWindowSync {
*/
#runOnAllWindows(aWindow, aCallback) {
for (let window of this.#browserWindows) {
if (window !== aWindow) {
if (window !== aWindow && !window._zenClosingWindow) {
let value = aCallback(window);
if (value) {
return value;
@@ -224,7 +224,11 @@ class nsZenWindowSync {
handleEvent(aEvent) {
const window = aEvent.currentTarget.ownerGlobal;
if (!window.gZenStartup.isReady || window.gZenWorkspaces?.privateWindowOrDisabled) {
if (
!window.gZenStartup.isReady ||
window.gZenWorkspaces?.privateWindowOrDisabled ||
window._zenClosingWindow
) {
return;
}
if (INSTANT_EVENTS.includes(aEvent.type)) {
@@ -658,6 +662,11 @@ class nsZenWindowSync {
*/
#onTabSwitchOrWindowFocus(aWindow, aPreviousTab = null) {
const selectedTab = aWindow.gBrowser.selectedTab;
// On some occasions, such as when closing a window, this
// function might be called multiple times for the same tab.
if (selectedTab === this.#lastSelectedTab) {
return;
}
if (aPreviousTab?._zenContentsVisible) {
const otherTabToShow = this.#getActiveTabFromOtherWindows(
aWindow,
@@ -853,8 +862,9 @@ class nsZenWindowSync {
this.#onTabSwitchOrWindowFocus(aEvent.target.ownerGlobal, previousTab);
}
on_unload(aEvent) {
on_SSWindowClosing(aEvent) {
const window = aEvent.target.ownerGlobal;
window._zenClosingWindow = true;
for (let eventName of EVENTS) {
window.removeEventListener(eventName, this);
}