From 831801add39ac953e3550d83a69ff1807e6faeb0 Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Wed, 11 Sep 2024 20:59:02 +0200 Subject: [PATCH] Refactor tab navigation logic and add contextChangeContainerTab method --- src/ZenWorkspaces.mjs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 2c91f9f..f23375e 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -20,6 +20,10 @@ var ZenWorkspaces = { return Services.prefs.getBoolPref('zen.workspaces.enabled', false); }, + getActiveWorkspaceFromCache() { + return this._workspaceCache.workspaces.find((workspace) => workspace.used); + }, + // Wrorkspaces saving/loading get _storeFile() { return PathUtils.join(PathUtils.profileDir, 'zen-workspaces', 'Workspaces.json'); @@ -96,7 +100,7 @@ var ZenWorkspaces = { } }, - _kIcons: ['🏠', '📄', '💹', '💼', '📧', '✅', '👥'], + _kIcons: JSON.parse(Services-prefs.getStringPref("zen.workspaces.icons", '["🌐", "📁", "📎", "📝", "📅", "📊"]')), _initializeWorkspaceCreationIcons() { let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container'); @@ -575,6 +579,16 @@ var ZenWorkspaces = { } }, + async contextChangeContainerTab(event) { + let workspaces = await this._workspaces(); + let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId); + let userContextId = parseInt( + event.target.getAttribute("data-usercontextid") + ); + workspace.containerTabId = userContextId; + await this.saveWorkspace(workspace); + }, + onContextMenuClose() { let target = document.querySelector( `#PanelUI-zen-workspaces [zen-workspace-id="${this._contextMenuId}"] .zen-workspace-actions` @@ -643,6 +657,15 @@ var ZenWorkspaces = { const workspaces = await this._workspaces(); await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID)); }, + + // Tab browser utilities + getContextIdIfNeeded(userContextId) { + if (typeof userContextId !== "undefined" || !this.workspaceEnabled) { + return userContextId; + } + const activeWorkspace = this.getActiveWorkspaceFromCache(); + return activeWorkspace?.containerTabId; + }, }; ZenWorkspaces.init();