Added a pref to make essentials container specific, i.e. if a workspace has a container assigned to it, on that workspace only essentials opened in that container will be visible.

This commit is contained in:
Kristijan Ribarić
2024-11-12 10:44:12 +01:00
parent 3277e06740
commit bc45092e03
3 changed files with 38 additions and 4 deletions

View File

@@ -177,6 +177,7 @@ pref('zen.workspaces.icons', '["⌚","⌛","⏪","⏫","⏬","⏰","⏳","⚽","
pref('services.sync.prefs.sync.zen.workspaces.icons', true); pref('services.sync.prefs.sync.zen.workspaces.icons', true);
pref('services.sync.engine.workspaces', false); pref('services.sync.engine.workspaces', false);
pref('zen.essentials.enabled', true); pref('zen.essentials.enabled', true);
pref('zen.workspaces.container-specific-essentials-enabled', false);
// Zen Watermark // Zen Watermark
pref('zen.watermark.enabled', true, sticky); pref('zen.watermark.enabled', true, sticky);

View File

@@ -40,6 +40,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
'zen.workspaces.open-new-tab-if-last-unpinned-tab-is-closed', 'zen.workspaces.open-new-tab-if-last-unpinned-tab-is-closed',
false false
); );
XPCOMUtils.defineLazyPreferenceGetter(
this,
'containerSpecificEssentials',
'zen.workspaces.container-specific-essentials-enabled',
false
);
ChromeUtils.defineLazyGetter(this, 'tabContainer', () => document.getElementById('tabbrowser-tabs')); ChromeUtils.defineLazyGetter(this, 'tabContainer', () => document.getElementById('tabbrowser-tabs'));
this._activeWorkspace = Services.prefs.getStringPref('zen.workspaces.active', ''); this._activeWorkspace = Services.prefs.getStringPref('zen.workspaces.active', '');
await ZenWorkspacesStorage.init(); await ZenWorkspacesStorage.init();
@@ -1092,6 +1098,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._inChangingWorkspace = true; this._inChangingWorkspace = true;
this.activeWorkspace = window.uuid; this.activeWorkspace = window.uuid;
const containerId = window.containerTabId?.toString();
const workspaces = await this._workspaces();
this.tabContainer._invalidateCachedTabs(); this.tabContainer._invalidateCachedTabs();
let firstTab = undefined; let firstTab = undefined;
@@ -1105,8 +1113,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
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
} }
gBrowser.showTab(tab); gBrowser.showTab(tab);
if (!tab.hasAttribute('zen-workspace-id') && !tab.pinned) { if (!tab.hasAttribute('zen-workspace-id') && tab.getAttribute('zen-essential') !== 'true') {
// 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 or those who lost the id for any reason
// example use case: opening a link from an external app // example use case: opening a link from an external app
tab.setAttribute('zen-workspace-id', window.uuid); tab.setAttribute('zen-workspace-id', window.uuid);
} }
@@ -1119,8 +1127,28 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._createNewTabForWorkspace(window); this._createNewTabForWorkspace(window);
} }
for (let tab of gBrowser.tabs) { for (let tab of gBrowser.tabs) {
if (tab.getAttribute('zen-workspace-id') !== window.uuid && !(tab.pinned && !tab.hasAttribute('zen-workspace-id')) // Skip tabs that are in the current workspace
&& !tab.hasAttribute("zen-essential")) { if (tab.getAttribute('zen-workspace-id') === window.uuid) {
continue;
}
// Handle essentials
if (tab.getAttribute("zen-essential") === "true") {
if(this.containerSpecificEssentials) {
if (containerId) {
// In workspaces with default container: Hide essentials that don't match the container
if (tab.getAttribute("usercontextid") !== containerId) {
gBrowser.hideTab(tab, undefined, true);
}
} else {
// In workspaces without a default container: Hide essentials that are opened in a container and some workspace has that container as default
if (tab.hasAttribute("usercontextid") && workspaces.workspaces.some((workspace) => workspace.containerTabId === parseInt(tab.getAttribute("usercontextid") || "0" , 10))) {
gBrowser.hideTab(tab, undefined, true);
}
}
}
} else {
// For non-pinned tabs: Hide if they're not in the current workspace
gBrowser.hideTab(tab, undefined, true); gBrowser.hideTab(tab, undefined, true);
} }
} }

View File

@@ -1105,6 +1105,11 @@ Preferences.addAll([
type: "bool", type: "bool",
default: true, default: true,
}, },
{
id: 'zen.workspaces.container-specific-essentials-enabled',
type: 'bool',
default: false,
},
{ {
id: "zen.tabs.show-newtab-vertical", id: "zen.tabs.show-newtab-vertical",
type: "bool", type: "bool",