chore: Improved and cleaned workspace fetching from cache, b=(no-bug), c=workspaces

This commit is contained in:
Mr. M 2025-04-27 16:21:23 +02:00
parent 69405bda0f
commit 6b6339867d
No known key found for this signature in database
GPG key ID: 6292C4C8F8652B18

View file

@ -684,8 +684,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
getActiveWorkspaceFromCache() { getActiveWorkspaceFromCache() {
return this.getWoekspaceFromId(this.activeWorkspace);
}
getWoekspaceFromId(id) {
try { try {
return this._workspaceCache.workspaces.find((workspace) => workspace.uuid === this.activeWorkspace); return this._workspaceCache.workspaces.find((workspace) => workspace.uuid === id);
} catch (e) { } catch (e) {
return null; return null;
} }
@ -706,7 +710,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const activeWorkspaceId = this.activeWorkspace; const activeWorkspaceId = this.activeWorkspace;
if (activeWorkspaceId) { if (activeWorkspaceId) {
const activeWorkspace = this._workspaceCache.workspaces.find((w) => w.uuid === activeWorkspaceId); const activeWorkspace = this.getWoekspaceFromId(activeWorkspaceId);
// Set the active workspace ID to the first one if the one with selected id doesn't exist // Set the active workspace ID to the first one if the one with selected id doesn't exist
if (!activeWorkspace) { if (!activeWorkspace) {
this.activeWorkspace = this._workspaceCache.workspaces[0]?.uuid; this.activeWorkspace = this._workspaceCache.workspaces[0]?.uuid;
@ -2370,7 +2374,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const workspaceIndicator = document.querySelector( const workspaceIndicator = document.querySelector(
`#zen-current-workspace-indicator-container .zen-workspace-tabs-section[zen-workspace-id="${workspaceId}"]` `#zen-current-workspace-indicator-container .zen-workspace-tabs-section[zen-workspace-id="${workspaceId}"]`
); );
const workspaceObject = this._workspaceCache.workspaces.find((w) => w.uuid === workspaceId); const workspaceObject = this.getWoekspaceFromId(workspaceId);
const essentialContainer = this.getEssentialsSection(workspaceObject.containerTabId); const essentialContainer = this.getEssentialsSection(workspaceObject.containerTabId);
this._updateMarginTopPinnedTabs(arrowScrollbox, pinnedContainer, essentialContainer, workspaceIndicator, forAnimation); this._updateMarginTopPinnedTabs(arrowScrollbox, pinnedContainer, essentialContainer, workspaceIndicator, forAnimation);
this.updateShouldHideSeparator(arrowScrollbox, pinnedContainer); this.updateShouldHideSeparator(arrowScrollbox, pinnedContainer);
@ -2435,7 +2439,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// Switch workspace if needed // Switch workspace if needed
if (workspaceID && workspaceID !== activeWorkspace.uuid && this._hasInitializedTabsStrip) { if (workspaceID && workspaceID !== activeWorkspace.uuid && this._hasInitializedTabsStrip) {
await this.changeWorkspace({ uuid: workspaceID }); const workspaceToChange = this.getWoekspaceFromId(workspaceID);
await this.changeWorkspace(workspaceToChange);
} }
} }
} }
@ -2619,7 +2624,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// Tab browser utilities // Tab browser utilities
createContainerTabMenu(event) { createContainerTabMenu(event) {
let window = event.target.ownerGlobal; let window = event.target.ownerGlobal;
const workspace = this._workspaceCache.workspaces.find((workspace) => this._contextMenuId === workspace.uuid); const workspace = this.getWoekspaceFromId(this._contextMenuId);
let containerTabId = workspace.containerTabId; let containerTabId = workspace.containerTabId;
return window.createUserContextMenu(event, { return window.createUserContextMenu(event, {
isContextMenu: true, isContextMenu: true,
@ -2811,11 +2816,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
if (tab.hasAttribute('zen-essential')) { if (tab.hasAttribute('zen-essential')) {
// Find first workspace with the same container // Find first workspace with the same container
const containerTabId = parseInt(tab.parentNode.getAttribute('container')); const containerTabId = parseInt(tab.parentNode.getAttribute('container'));
workspaceToSwitch = this._workspaceCache.workspaces.find((workspace) => workspace.containerTabId === containerTabId); workspaceToSwitch = this.getWoekspaceFromId(containerTabId);
} else { } else {
workspaceToSwitch = this._workspaceCache.workspaces.find( workspaceToSwitch = this.getWoekspaceFromId(tab.getAttribute('zen-workspace-id'));
(workspace) => workspace.uuid === tab.getAttribute('zen-workspace-id')
);
} }
if (!workspaceToSwitch) { if (!workspaceToSwitch) {
console.error('No workspace found for tab, cannot switch'); console.error('No workspace found for tab, cannot switch');