Refactor ZenWorkspaces to handle changing workspaces and update context menu

This commit is contained in:
mr. M 2024-10-12 17:53:49 +02:00
parent 0a23df721e
commit 9a1beadc03
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB

View file

@ -3,6 +3,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
* Stores workspace IDs and their last selected tabs. * Stores workspace IDs and their last selected tabs.
*/ */
_lastSelectedWorkspaceTabs = {}; _lastSelectedWorkspaceTabs = {};
_inChangingWorkspace = false;
async init() { async init() {
if (!this.shouldHaveWorkspaces) { if (!this.shouldHaveWorkspaces) {
@ -606,10 +607,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
async changeWorkspace(window, onInit = false) { async changeWorkspace(window, onInit = false) {
if (!this.workspaceEnabled) { if (!this.workspaceEnabled || this._inChangingWorkspace) {
return; return;
} }
this._inChangingWorkspace = true;
Services.prefs.setStringPref('zen.workspaces.active', window.uuid); Services.prefs.setStringPref('zen.workspaces.active', window.uuid);
const shouldAllowPinnedTabs = this._shouldAllowPinTab; const shouldAllowPinnedTabs = this._shouldAllowPinTab;
@ -657,13 +659,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}); });
await this._propagateWorkspaceData(); await this._propagateWorkspaceData();
this._inChangingWorkspace = false;
} }
async _updateWorkspacesChangeContextMenu() { async _updateWorkspacesChangeContextMenu() {
const workspaces = await this._workspaces(); const workspaces = await this._workspaces();
const menuPopup = document.getElementById('context-zen-change-workspace-tab-menu-popup'); const menuPopup = document.getElementById('context-zen-change-workspace-tab-menu-popup');
if (!menuPopup) {
return;
}
menuPopup.innerHTML = ''; menuPopup.innerHTML = '';
const activeWorkspace = await this.getActiveWorkspace(); const activeWorkspace = await this.getActiveWorkspace();
@ -715,17 +720,18 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
async onLocationChange(browser) { async onLocationChange(browser) {
if (!this.workspaceEnabled || this._inChangingWorkspace) {
return;
}
const parent = browser.ownerGlobal;
let tab = gBrowser.getTabForBrowser(browser); let tab = gBrowser.getTabForBrowser(browser);
let workspaceID = tab.getAttribute('zen-workspace-id'); let workspaceID = tab.getAttribute('zen-workspace-id');
if (!workspaceID) { let activeWorkspace = await parent.ZenWorkspaces.getActiveWorkspace();
let activeWorkspace = await this.getActiveWorkspace(); if (workspaceID === activeWorkspace.uuid) {
if (!activeWorkspace || tab.hasAttribute('hidden')) { return;
return;
}
tab.setAttribute('zen-workspace-id', activeWorkspace.uuid);
workspaceID = activeWorkspace.uuid;
} }
this._lastSelectedWorkspaceTabs[workspaceID] = tab; this._lastSelectedWorkspaceTabs[workspaceID] = tab;
await parent.ZenWorkspaces.changeWorkspace({ uuid: workspaceID });
} }
// Context menu management // Context menu management