Fixed workspaces syncing across windows

This commit is contained in:
mr. M 2024-10-14 17:45:09 +02:00
parent 41193b2050
commit b645656e6f
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB

View file

@ -622,22 +622,21 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
Services.prefs.setStringPref('zen.workspaces.active', window.uuid); Services.prefs.setStringPref('zen.workspaces.active', window.uuid);
const shouldAllowPinnedTabs = this._shouldAllowPinTab; const shouldAllowPinnedTabs = this._shouldAllowPinTab;
await this.foreachWindowAsActive(async (browser) => { this.tabContainer._invalidateCachedTabs();
browser.ZenWorkspaces.tabContainer._invalidateCachedTabs();
let firstTab = undefined; let firstTab = undefined;
console.info('ZenWorkspaces: Changing workspace to', window.uuid); console.info('ZenWorkspaces: Changing workspace to', window.uuid);
for (let tab of browser.gBrowser.tabs) { for (let tab of gBrowser.tabs) {
if ( if (
(tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) || (tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) ||
!tab.hasAttribute('zen-workspace-id') !tab.hasAttribute('zen-workspace-id')
) { ) {
if (!firstTab) { if (!firstTab) {
firstTab = tab; firstTab = tab;
} else if (browser.gBrowser.selectedTab === tab) { } else if (gBrowser.selectedTab === tab) {
// If the selected tab is already in the workspace, we don't want to change it // If the selected tab is already in the workspace, we don't want to change it
firstTab = null; // note: Do not add "undefined" here, a new tab would be created firstTab = null; // note: Do not add "undefined" here, a new tab would be created
} }
browser.gBrowser.showTab(tab); gBrowser.showTab(tab);
if (!tab.hasAttribute('zen-workspace-id')) { if (!tab.hasAttribute('zen-workspace-id')) {
// We add the id to those tabs that got inserted before we initialize the workspaces // We add the id to those tabs that got inserted before we initialize the workspaces
// example use case: opening a link from an external app // example use case: opening a link from an external app
@ -646,24 +645,21 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
} }
if (firstTab) { if (firstTab) {
browser.gBrowser.selectedTab = browser.ZenWorkspaces._lastSelectedWorkspaceTabs[window.uuid] ?? firstTab; gBrowser.selectedTab = this._lastSelectedWorkspaceTabs[window.uuid] ?? firstTab;
} }
if (typeof firstTab === 'undefined' && !onInit) { if (typeof firstTab === 'undefined' && !onInit) {
browser.ZenWorkspaces._createNewTabForWorkspace(window); this._createNewTabForWorkspace(window);
} }
for (let tab of browser.gBrowser.tabs) { for (let tab of gBrowser.tabs) {
if (tab.getAttribute('zen-workspace-id') !== window.uuid) { if (tab.getAttribute('zen-workspace-id') !== window.uuid) {
// FOR UNLOADING TABS: gBrowser.hideTab(tab, undefined, shouldAllowPinnedTabs);
// gBrowser.discardBrowser(tab, true);
browser.gBrowser.hideTab(tab, undefined, shouldAllowPinnedTabs);
} }
} }
browser.ZenWorkspaces.tabContainer._invalidateCachedTabs(); this.tabContainer._invalidateCachedTabs();
browser.document.documentElement.setAttribute('zen-workspace-id', window.uuid); document.documentElement.setAttribute('zen-workspace-id', window.uuid);
await browser.ZenWorkspaces._updateWorkspacesChangeContextMenu(); await this._updateWorkspacesChangeContextMenu();
browser.document.getElementById('tabbrowser-tabs')._positionPinnedTabs(); document.getElementById('tabbrowser-tabs')._positionPinnedTabs();
});
await this._propagateWorkspaceData(); await this._propagateWorkspaceData();
this._inChangingWorkspace = false; this._inChangingWorkspace = false;