mirror of
https://github.com/zen-browser/desktop.git
synced 2026-03-30 04:11:51 +00:00
fix: Fixed race conditions when syncing views through windows desktops, b=bug #12390, c=no-component
This commit is contained in:
@@ -1259,11 +1259,10 @@ class nsZenWindowSync {
|
||||
});
|
||||
}
|
||||
|
||||
async on_focus(aEvent) {
|
||||
on_focus(aEvent) {
|
||||
if (typeof aEvent.target !== "object") {
|
||||
return;
|
||||
}
|
||||
await this.#docShellSwitchPromise;
|
||||
const window = Services.focus.activeWindow;
|
||||
if (
|
||||
!window?.gBrowser ||
|
||||
@@ -1273,23 +1272,31 @@ class nsZenWindowSync {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let promise = this.#docShellSwitchPromise;
|
||||
this.#lastFocusedWindow = new WeakRef(window);
|
||||
this.#lastSelectedTab = new WeakRef(window.gBrowser.selectedTab);
|
||||
return (this.#docShellSwitchPromise = this.#onTabSwitchOrWindowFocus(window));
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
this.#docShellSwitchPromise = new Promise(async (resolve) => {
|
||||
await promise;
|
||||
await this.#onTabSwitchOrWindowFocus(window);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
async on_TabSelect(aEvent) {
|
||||
await this.#docShellSwitchPromise;
|
||||
on_TabSelect(aEvent) {
|
||||
const tab = aEvent.target;
|
||||
if (this.#lastSelectedTab?.deref() === tab) {
|
||||
return;
|
||||
}
|
||||
this.#lastSelectedTab = new WeakRef(tab);
|
||||
const previousTab = aEvent.detail.previousTab;
|
||||
return (this.#docShellSwitchPromise = this.#onTabSwitchOrWindowFocus(
|
||||
aEvent.target.ownerGlobal,
|
||||
previousTab
|
||||
));
|
||||
let promise = this.#docShellSwitchPromise;
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
this.#docShellSwitchPromise = new Promise(async (resolve) => {
|
||||
await promise;
|
||||
await this.#onTabSwitchOrWindowFocus(tab.ownerGlobal, previousTab);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
on_SSWindowClosing(aEvent) {
|
||||
|
||||
Reference in New Issue
Block a user