Skip to content

Commit

Permalink
Merge pull request #2947 from kristijanribaric/feature/add-option-to-…
Browse files Browse the repository at this point in the history
…make-essentials-container-specific

Feature: container specific Essentials
  • Loading branch information
mr-cheff authored Nov 13, 2024
2 parents bc7d0c7 + bc45092 commit 693963b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/browser/app/profile/zen-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pref('zen.workspaces.icons', '["⌚","⌛","⏪","⏫","⏬","⏰","⏳","⚽","
pref('services.sync.prefs.sync.zen.workspaces.icons', true);
pref('services.sync.engine.workspaces', false);
pref('zen.essentials.enabled', true);
pref('zen.workspaces.container-specific-essentials-enabled', false);

// Zen Watermark
pref('zen.watermark.enabled', true, sticky);
Expand Down
36 changes: 32 additions & 4 deletions src/browser/base/zen-components/ZenWorkspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
'zen.workspaces.open-new-tab-if-last-unpinned-tab-is-closed',
false
);
XPCOMUtils.defineLazyPreferenceGetter(
this,
'containerSpecificEssentials',
'zen.workspaces.container-specific-essentials-enabled',
false
);
ChromeUtils.defineLazyGetter(this, 'tabContainer', () => document.getElementById('tabbrowser-tabs'));
this._activeWorkspace = Services.prefs.getStringPref('zen.workspaces.active', '');
await ZenWorkspacesStorage.init();
Expand Down Expand Up @@ -1092,6 +1098,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {

this._inChangingWorkspace = true;
this.activeWorkspace = window.uuid;
const containerId = window.containerTabId?.toString();
const workspaces = await this._workspaces();

this.tabContainer._invalidateCachedTabs();
let firstTab = undefined;
Expand All @@ -1105,8 +1113,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
firstTab = null; // note: Do not add "undefined" here, a new tab would be created
}
gBrowser.showTab(tab);
if (!tab.hasAttribute('zen-workspace-id') && !tab.pinned) {
// We add the id to those tabs that got inserted before we initialize the workspaces
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 or those who lost the id for any reason
// example use case: opening a link from an external app
tab.setAttribute('zen-workspace-id', window.uuid);
}
Expand All @@ -1119,8 +1127,28 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._createNewTabForWorkspace(window);
}
for (let tab of gBrowser.tabs) {
if (tab.getAttribute('zen-workspace-id') !== window.uuid && !(tab.pinned && !tab.hasAttribute('zen-workspace-id'))
&& !tab.hasAttribute("zen-essential")) {
// Skip tabs that are in the current workspace
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);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/browser/components/preferences/zen-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,11 @@ Preferences.addAll([
type: "bool",
default: true,
},
{
id: 'zen.workspaces.container-specific-essentials-enabled',
type: 'bool',
default: false,
},
{
id: "zen.tabs.show-newtab-vertical",
type: "bool",
Expand Down

0 comments on commit 693963b

Please sign in to comment.