Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace change refactoring #3121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/browser/base/content/ZenStartup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
// Disable smooth scroll
gBrowser.tabContainer.arrowScrollbox.smoothScroll = false;

gZenPinnedTabManager.initTabs();
ZenWorkspaces.init();
gZenUIManager.init();
gZenVerticalTabsManager.init();
Expand Down
75 changes: 60 additions & 15 deletions src/browser/base/zen-components/ZenPinnedTabManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@
this.observer.addPinnedTabListener(this._onPinnedTabEvent.bind(this));

this._zenClickEventListener = this._onTabClick.bind(this);
ZenWorkspaces.addChangeListeners(this.onWorkspaceChange.bind(this));

}

async initTabs() {
if (!this.enabled) {
async onWorkspaceChange(newWorkspace, onInit) {
if (!this.enabled || PrivateBrowsingUtils.isWindowPrivate(window)) {
return;
}
await ZenPinnedTabsStorage.init();

await this._refreshPinnedTabs(newWorkspace,{ init: onInit });
}

get enabled() {
Expand All @@ -68,9 +71,12 @@
return this._enabled;
}

async _refreshPinnedTabs({ init = false } = {}) {
async _refreshPinnedTabs(currentWorkspace,{ init = false } = {}) {
if(init) {
await ZenPinnedTabsStorage.init();
}
await this._initializePinsCache();
this._initializePinnedTabs(init);
await this._initializePinnedTabs(init,currentWorkspace);
}

async _initializePinsCache() {
Expand Down Expand Up @@ -109,12 +115,14 @@
return this._pinsCache;
}

_initializePinnedTabs(init = false) {
async _initializePinnedTabs(init = false, currentWorkspace) {
const pins = this._pinsCache;
if (!pins?.length) {
return;
}

const workspaces = await ZenWorkspaces._workspaces();

const activeTab = gBrowser.selectedTab;
const pinnedTabsByUUID = new Map();
const pinsToCreate = new Set(pins.map(p => p.uuid));
Expand All @@ -131,7 +139,7 @@
pinnedTabsByUUID.set(pinId, tab);
pinsToCreate.delete(pinId);

if(lazy.zenPinnedTabRestorePinnedTabsToPinnedUrl && init) {
if (lazy.zenPinnedTabRestorePinnedTabsToPinnedUrl && init) {
this._resetTabToStoredState(tab);
}
} else {
Expand All @@ -146,6 +154,10 @@
continue; // Skip pins that already have tabs
}

if (!this._shouldShowPin(pin, currentWorkspace, workspaces)) {
continue; // Skip pins not relevant to current workspace
}

let params = {
skipAnimation: true,
allowInheritPrincipal: false,
Expand Down Expand Up @@ -196,9 +208,6 @@

gBrowser.pinTab(newTab);

if(newTab.getAttribute("zen-workspace-id") !== ZenWorkspaces.activeWorkspace && newTab.getAttribute("zen-essential") !== "true") {
gBrowser.hideTab(newTab, undefined, true);
}

newTab.initialize();
}
Expand All @@ -211,6 +220,41 @@
gBrowser._updateTabBarForPinnedTabs();
}

_shouldShowPin(pin, currentWorkspace, workspaces) {
const isEssential = pin.isEssential;
const pinWorkspaceUuid = pin.workspaceUuid;
const pinContextId = pin.containerTabId ? pin.containerTabId.toString() : "0";
const workspaceContextId = currentWorkspace.containerTabId?.toString() || "0";
const containerSpecificEssentials = ZenWorkspaces.containerSpecificEssentials;

// Handle essential pins
if (isEssential) {
if (!containerSpecificEssentials) {
return true; // Show all essential pins when containerSpecificEssentials is false
}

if (workspaceContextId !== "0") {
// In workspaces with default container: Show essentials that match the container
return pinContextId === workspaceContextId;
} else {
// In workspaces without a default container: Show essentials that aren't in container-specific workspaces
// or have userContextId="0" or no userContextId
return !pinContextId || pinContextId === "0" || !workspaces.workspaces.some(
workspace => workspace.containerTabId === parseInt(pinContextId, 10)
);
}
}

// For non-essential pins
if (!pinWorkspaceUuid) {
// Pins without a workspace belong to all workspaces (if that's your desired behavior)
return true;
}

// Show if pin belongs to current workspace
return pinWorkspaceUuid === currentWorkspace.uuid;
}

_onPinnedTabEvent(action, event) {
if (!this.enabled) return;
const tab = event.target;
Expand Down Expand Up @@ -275,7 +319,8 @@
pin.userContextId = userContextId ? parseInt(userContextId, 10) : 0;

await ZenPinnedTabsStorage.savePin(pin);
await this._refreshPinnedTabs();
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
await this._refreshPinnedTabs(currentWorkspace);
}

async _setPinnedAttributes(tab) {
Expand Down Expand Up @@ -311,8 +356,8 @@
tab.removeAttribute("zen-pinned-entry");
return;
}

await this._refreshPinnedTabs();
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
await this._refreshPinnedTabs(currentWorkspace);
}

async _removePinnedAttributes(tab, isClosing = false) {
Expand All @@ -330,8 +375,8 @@
tab.setAttribute("zen-workspace-id", workspace.uuid);
}
}

await this._refreshPinnedTabs();
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
await this._refreshPinnedTabs(currentWorkspace);
}

_initClosePinnedTabShortcut() {
Expand Down
2 changes: 0 additions & 2 deletions src/browser/base/zen-components/ZenPinnedTabsStorage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ var ZenPinnedTabsStorage = {
await db.execute(`
CREATE INDEX IF NOT EXISTS idx_zen_pins_changes_uuid ON zen_pins_changes(uuid)
`);

await gZenPinnedTabManager._refreshPinnedTabs({init: true});
});
},

Expand Down
Loading
Loading