From 5333e92c42a50a6048d8ca3df3901b84aa59a14c Mon Sep 17 00:00:00 2001 From: Slowlife01 Date: Sat, 5 Apr 2025 16:58:49 +0700 Subject: [PATCH 1/6] fix: unable to unload tab with auto tab unloader disabled --- src/browser/base/zen-components/ZenTabUnloader.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/base/zen-components/ZenTabUnloader.mjs b/src/browser/base/zen-components/ZenTabUnloader.mjs index 9fe8dab20..6902e868f 100644 --- a/src/browser/base/zen-components/ZenTabUnloader.mjs +++ b/src/browser/base/zen-components/ZenTabUnloader.mjs @@ -229,7 +229,7 @@ explicitUnloadTabs(tabs, extraArgs = {}) { for (let i = 0; i < tabs.length; i++) { - if (this.canUnloadTab(tabs[i], Date.now(), this.intervalUnloader.excludedUrls, true, extraArgs)) { + if (this.canUnloadTab(tabs[i], Date.now(), this.intervalUnloader?.excludedUrls || [], true, extraArgs)) { this.unload(tabs[i], true); } } From 9d3382d773b8f6b9d7fae71f8749c21a8fde3c68 Mon Sep 17 00:00:00 2001 From: Slowlife01 Date: Sat, 5 Apr 2025 18:01:18 +0700 Subject: [PATCH 2/6] fix: add default excluded URLs --- src/browser/base/zen-components/ZenTabUnloader.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/browser/base/zen-components/ZenTabUnloader.mjs b/src/browser/base/zen-components/ZenTabUnloader.mjs index 6902e868f..4bf3f1620 100644 --- a/src/browser/base/zen-components/ZenTabUnloader.mjs +++ b/src/browser/base/zen-components/ZenTabUnloader.mjs @@ -125,6 +125,7 @@ class ZenTabUnloader extends ZenDOMOperatedFeature { static ACTIVITY_MODIFIERS = ['muted', 'soundplaying', 'label', 'attention']; + static DEFAULT_EXCLUDED_URLS = ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS.map((url) => new RegExp(url)); constructor() { super(); @@ -227,9 +228,17 @@ this.explicitUnloadTabs(tabs); } + getExcludedUrls() { + if (!this.intervalUnloader) { + return ZenTabUnloader.DEFAULT_EXCLUDED_URLS; + } + + return this.intervalUnloader.excludedUrls; + } + explicitUnloadTabs(tabs, extraArgs = {}) { for (let i = 0; i < tabs.length; i++) { - if (this.canUnloadTab(tabs[i], Date.now(), this.intervalUnloader?.excludedUrls || [], true, extraArgs)) { + if (this.canUnloadTab(tabs[i], Date.now(), this.getExcludedUrls(), true, extraArgs)) { this.unload(tabs[i], true); } } From 87c62b43197261508da35b788f82f30d00314abd Mon Sep 17 00:00:00 2001 From: W Wilja Wiklund Date: Sun, 6 Apr 2025 00:32:29 +0200 Subject: [PATCH 3/6] Update Firefox version to 137.0 in README.md Signed-off-by: W Wilja Wiklund --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd43bbb45..0075e4c95 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,9 @@ ## 🖥️ Compatibility -Zen is currently built using Firefox version `136.0.2`! 🚀 +Zen is currently built using Firefox version `137.0`! 🚀 -- [`Zen Twilight`](https://zen-browser.app/download?twilight) - Is currently built using Firefox version `RC 136.0`! +- [`Zen Twilight`](https://zen-browser.app/download?twilight) - Is currently built using Firefox version `137.0`! - Check out the latest [release notes](https://zen-browser.app/release-notes)! - Part of our mission is to keep Zen up-to-date with the latest version of Firefox, so you can enjoy the latest features and security updates! From 7025efa6f8d9a79117208483e16965a20ad661e8 Mon Sep 17 00:00:00 2001 From: Slowlife01 Date: Sun, 6 Apr 2025 08:42:40 +0700 Subject: [PATCH 4/6] refactor: move over excludedUrls --- .../base/zen-components/ZenTabUnloader.mjs | 94 +++++++++---------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/src/browser/base/zen-components/ZenTabUnloader.mjs b/src/browser/base/zen-components/ZenTabUnloader.mjs index 4bf3f1620..9cec014fa 100644 --- a/src/browser/base/zen-components/ZenTabUnloader.mjs +++ b/src/browser/base/zen-components/ZenTabUnloader.mjs @@ -63,48 +63,12 @@ static INTERVAL = 1000 * 60; // 1 minute interval = null; + /** @type {ZenTabUnloader} */ unloader = null; - #excludedUrls = []; - #compiledExcludedUrls = []; - constructor(unloader) { this.unloader = unloader; this.interval = setInterval(this.intervalListener.bind(this), ZenTabsIntervalUnloader.INTERVAL); - this.#excludedUrls = this.lazyExcludeUrls; - } - - get lazyExcludeUrls() { - return [ - ...ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS, - ...lazy.zenTabUnloaderExcludedUrls.split(',').map((url) => url.trim()), - ]; - } - - arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length !== b.length) return false; - - // If you don't care about the order of the elements inside - // the array, you should sort both arrays here. - // Please note that calling sort on an array will modify that array. - // you might want to clone your array first. - - for (var i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - return true; - } - - get excludedUrls() { - // Check if excludedrls is the same as the pref value - const excludedUrls = this.lazyExcludeUrls; - if (!this.arraysEqual(this.#excludedUrls, excludedUrls) || !this.#compiledExcludedUrls.length) { - this.#excludedUrls = excludedUrls; - this.#compiledExcludedUrls = excludedUrls.map((url) => new RegExp(url)); - } - return this.#compiledExcludedUrls; } intervalListener() { @@ -112,11 +76,10 @@ return; } const currentTimestamp = Date.now(); - const excludedUrls = this.excludedUrls; const tabs = ZenWorkspaces.allStoredTabs; for (let i = 0; i < tabs.length; i++) { const tab = tabs[i]; - if (this.unloader.canUnloadTab(tab, currentTimestamp, excludedUrls)) { + if (this.unloader.canUnloadTab(tab, currentTimestamp)) { this.unloader.unload(tab); } } @@ -125,10 +88,14 @@ class ZenTabUnloader extends ZenDOMOperatedFeature { static ACTIVITY_MODIFIERS = ['muted', 'soundplaying', 'label', 'attention']; - static DEFAULT_EXCLUDED_URLS = ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS.map((url) => new RegExp(url)); + + #excludedUrls = []; + #compiledExcludedUrls = []; constructor() { super(); + + this.#excludedUrls = this.lazyExcludeUrls; if (!lazy.zenTabUnloaderEnabled) { return; } @@ -218,6 +185,39 @@ document.getElementById('context_closeDuplicateTabs').parentNode.appendChild(element); } + get lazyExcludeUrls() { + return [ + ...ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS, + ...lazy.zenTabUnloaderExcludedUrls.split(',').map((url) => url.trim()), + ]; + } + + arraysEqual(a, b) { + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length !== b.length) return false; + + // If you don't care about the order of the elements inside + // the array, you should sort both arrays here. + // Please note that calling sort on an array will modify that array. + // you might want to clone your array first. + + for (var i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + return true; + } + + get excludedUrls() { + // Check if excludedrls is the same as the pref value + const excludedUrls = this.lazyExcludeUrls; + if (!this.arraysEqual(this.#excludedUrls, excludedUrls) || !this.#compiledExcludedUrls.length) { + this.#excludedUrls = excludedUrls; + this.#compiledExcludedUrls = excludedUrls.map((url) => new RegExp(url)); + } + return this.#compiledExcludedUrls; + } + unload(tab, skipPermitUnload = false) { gBrowser.explicitUnloadTabs([tab], skipPermitUnload); tab.removeAttribute('linkedpanel'); @@ -228,17 +228,9 @@ this.explicitUnloadTabs(tabs); } - getExcludedUrls() { - if (!this.intervalUnloader) { - return ZenTabUnloader.DEFAULT_EXCLUDED_URLS; - } - - return this.intervalUnloader.excludedUrls; - } - explicitUnloadTabs(tabs, extraArgs = {}) { for (let i = 0; i < tabs.length; i++) { - if (this.canUnloadTab(tabs[i], Date.now(), this.getExcludedUrls(), true, extraArgs)) { + if (this.canUnloadTab(tabs[i], Date.now(), true, extraArgs)) { this.unload(tabs[i], true); } } @@ -260,7 +252,7 @@ } } - canUnloadTab(tab, currentTimestamp, excludedUrls, ignoreTimestamp = false, extraArgs = {}) { + canUnloadTab(tab, currentTimestamp, ignoreTimestamp = false, extraArgs = {}) { if ( (tab.pinned && !ignoreTimestamp) || tab.selected || @@ -275,7 +267,7 @@ (tab.pictureinpicture && !ignoreTimestamp) || (tab.soundPlaying && !ignoreTimestamp) || (tab.zenIgnoreUnload && !ignoreTimestamp) || - (excludedUrls.some((url) => url.test(tab.linkedBrowser?.currentURI.spec)) && + (this.excludedUrls.some((url) => url.test(tab.linkedBrowser?.currentURI.spec)) && tab.linkedBrowser?.currentURI.spec !== 'about:blank') ) { return false; From d6c30caf1b1f36b86fbd4ce5fe4324b7765fbf8e Mon Sep 17 00:00:00 2001 From: Slowlife01 Date: Sun, 6 Apr 2025 09:22:49 +0700 Subject: [PATCH 5/6] fix: add timestamp check to prevent frequent array comparisons in arraysEqual --- src/browser/base/zen-components/ZenTabUnloader.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/browser/base/zen-components/ZenTabUnloader.mjs b/src/browser/base/zen-components/ZenTabUnloader.mjs index 9cec014fa..295013d44 100644 --- a/src/browser/base/zen-components/ZenTabUnloader.mjs +++ b/src/browser/base/zen-components/ZenTabUnloader.mjs @@ -91,6 +91,7 @@ #excludedUrls = []; #compiledExcludedUrls = []; + #lastCheckedUrlTimestamp = 0; constructor() { super(); @@ -197,12 +198,18 @@ if (a == null || b == null) return false; if (a.length !== b.length) return false; + const currentTimestamp = Date.now(); + if (currentTimestamp - this.#lastCheckedUrlTimestamp < 5 * 1000) { + return true; + } + + this.#lastCheckedUrlTimestamp = currentTimestamp; // If you don't care about the order of the elements inside // the array, you should sort both arrays here. // Please note that calling sort on an array will modify that array. // you might want to clone your array first. - for (var i = 0; i < a.length; ++i) { + for (const i = 0; i < a.length; ++i) { if (a[i] !== b[i]) return false; } return true; From 4ecccd67bddf31a5c9d49e1391251b159de79c9f Mon Sep 17 00:00:00 2001 From: Slowlife Date: Sun, 6 Apr 2025 16:12:14 +0700 Subject: [PATCH 6/6] fix: change const to let Signed-off-by: Slowlife --- src/browser/base/zen-components/ZenTabUnloader.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/base/zen-components/ZenTabUnloader.mjs b/src/browser/base/zen-components/ZenTabUnloader.mjs index 295013d44..78ca84cdf 100644 --- a/src/browser/base/zen-components/ZenTabUnloader.mjs +++ b/src/browser/base/zen-components/ZenTabUnloader.mjs @@ -209,7 +209,7 @@ // Please note that calling sort on an array will modify that array. // you might want to clone your array first. - for (const i = 0; i < a.length; ++i) { + for (let i = 0; i < a.length; ++i) { if (a[i] !== b[i]) return false; } return true;