Refactor Zen tab management to improve performance and enable conditional functionality

This commit is contained in:
mr. M
2024-11-10 18:50:10 +01:00
parent 33ac29f269
commit c3fc7d792e
3 changed files with 25 additions and 6 deletions

View File

@@ -184,8 +184,6 @@
#vertical-pinned-tabs-container {
padding-inline-end: 0 !important;
max-height: unset !important;
overflow: visible !important;
display: flex !important;
flex-direction: column;

View File

@@ -39,6 +39,9 @@
class ZenPinnedTabManager extends ZenPreloadedFeature {
init() {
if (!this.enabled) {
return;
}
this.observer = new ZenPinnedTabsObserver();
this._initClosePinnedTabShortcut();
this._insertItemsIntoTabContextMenu();
@@ -48,9 +51,23 @@
}
async initTabs() {
if (!this.enabled) {
return;
}
await ZenPinnedTabsStorage.init();
}
get enabled() {
if (!this._enabled) {
this._enabled = !(
docElement.hasAttribute('privatebrowsingmode') ||
docElement.getAttribute('chromehidden').includes('toolbar') ||
docElement.getAttribute('chromehidden').includes('menubar')
);
}
return this._enabled;
}
async _refreshPinnedTabs() {
await this._initializePinsCache();
this._initializePinnedTabs();
@@ -161,6 +178,7 @@
}
_onPinnedTabEvent(action, event) {
if (!this.enabled) return;
const tab = event.target;
switch (action) {
case "TabPinned":
@@ -449,6 +467,9 @@
}
updatePinnedTabContextMenu(contextTab) {
if (!this.enabled) {
return;
}
const isVisible = contextTab.pinned && !contextTab.multiselected;
document.getElementById("context_zen-reset-pinned-tab").hidden = !isVisible || !contextTab.getAttribute("zen-pin-id");
document.getElementById("context_zen-replace-pinned-url-with-current").hidden = !isVisible;

View File

@@ -250,7 +250,7 @@
canUnloadTab(tab, currentTimestamp, excludedUrls, ignoreTimestamp = false) {
if (
tab.pinned ||
(tab.pinned && !ignoreTimestamp) ||
tab.selected ||
tab.multiselected ||
tab.hasAttribute('busy') ||
@@ -259,9 +259,9 @@
tab.splitView ||
tab.attention ||
tab.linkedBrowser?.zenModeActive ||
tab.pictureinpicture ||
tab.soundPlaying ||
tab.zenIgnoreUnload ||
(tab.pictureinpicture && !ignoreTimestamp) ||
(tab.soundPlaying && !ignoreTimestamp) ||
(tab.zenIgnoreUnload && !ignoreTimestamp) ||
excludedUrls.some((url) => url.test(tab.linkedBrowser.currentURI.spec))
) {
return false;