From b66af853f29928e77433a317dac8650222a02de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Mon, 14 Oct 2024 10:33:09 +0200 Subject: [PATCH 1/3] feat(workspaces): Force container tab to open in workspace where it's assigned as default This commit introduces a new preference, `zen.workspaces.force-container-workspace`, which allows users to automatically switch to the workspace associated with a specific tab's container. --- src/ZenWorkspaces.mjs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 3989481..b4b4375 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -879,6 +879,17 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { return [userContextId, false]; } + if(Services.prefs.getBoolPref('zen.workspaces.force-container-workspace', false) && typeof userContextId !== 'undefined' && this._workspaceCache?.workspaces) { + const workspace = this._workspaceCache.workspaces.find((workspace) => workspace.containerTabId === userContextId); + if(workspace && workspace.uuid !== this.getActiveWorkspaceFromCache().uuid) { + this.changeWorkspace(workspace).then(() => { + + return [userContextId, true]; + + }); + } + } + const activeWorkspace = this.getActiveWorkspaceFromCache(); const activeWorkspaceUserContextId = activeWorkspace?.containerTabId; From 74bd43f9c9039efff128e8ff3a5fd3e306c3de01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Mon, 14 Oct 2024 10:43:14 +0200 Subject: [PATCH 2/3] Add lazy pref getter for `zen.workspaces.force-container-workspace` --- src/ZenWorkspaces.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index b4b4375..85ff34e 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -18,6 +18,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { true, this._expandWorkspacesStrip.bind(this) ); + XPCOMUtils.defineLazyPreferenceGetter( + this, + 'shouldForceContainerTabsToWorkspace', + 'zen.workspaces.force-container-workspace', + true + ); ChromeUtils.defineLazyGetter(this, 'tabContainer', () => document.getElementById('tabbrowser-tabs')); await ZenWorkspacesStorage.init(); if(!Weave.Service.engineManager.get("workspaces")) { @@ -879,7 +885,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { return [userContextId, false]; } - if(Services.prefs.getBoolPref('zen.workspaces.force-container-workspace', false) && typeof userContextId !== 'undefined' && this._workspaceCache?.workspaces) { + if(this.shouldForceContainerTabsToWorkspace && typeof userContextId !== 'undefined' && this._workspaceCache?.workspaces) { const workspace = this._workspaceCache.workspaces.find((workspace) => workspace.containerTabId === userContextId); if(workspace && workspace.uuid !== this.getActiveWorkspaceFromCache().uuid) { this.changeWorkspace(workspace).then(() => { From c9adec30cbd02d8a68209af6df5b019a9aea4e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Mon, 14 Oct 2024 16:21:40 +0200 Subject: [PATCH 3/3] Fix: Remove unnecessary `then` call in `ZenWorkspaces` and return an array. --- src/ZenWorkspaces.mjs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 85ff34e..d74d849 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -888,11 +888,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { if(this.shouldForceContainerTabsToWorkspace && typeof userContextId !== 'undefined' && this._workspaceCache?.workspaces) { const workspace = this._workspaceCache.workspaces.find((workspace) => workspace.containerTabId === userContextId); if(workspace && workspace.uuid !== this.getActiveWorkspaceFromCache().uuid) { - this.changeWorkspace(workspace).then(() => { - - return [userContextId, true]; - - }); + this.changeWorkspace(workspace); + return [userContextId, true]; } }