mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 20:29:58 +02:00
Refactor ZenTabUnloader to optimize tab unloading and add context menu options
This commit is contained in:
parent
3681f71acf
commit
7147fd2dfc
1 changed files with 42 additions and 0 deletions
|
@ -149,6 +149,7 @@
|
||||||
if (!lazy.zenTabUnloaderEnabled) {
|
if (!lazy.zenTabUnloaderEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.insertIntoContextMenu();
|
||||||
this.observer = new ZenTabsObserver();
|
this.observer = new ZenTabsObserver();
|
||||||
this.intervalUnloader = new ZenTabsIntervalUnloader(this);
|
this.intervalUnloader = new ZenTabsIntervalUnloader(this);
|
||||||
this.observer.addTabsListener(this.onTabEvent.bind(this));
|
this.observer.addTabsListener(this.onTabEvent.bind(this));
|
||||||
|
@ -217,6 +218,47 @@
|
||||||
return gBrowser.tabs;
|
return gBrowser.tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insertIntoContextMenu() {
|
||||||
|
const element = window.MozXULElement.parseXULToFragment(`
|
||||||
|
<menuseparator/>
|
||||||
|
<menuitem id="context_zenUnloadTab"
|
||||||
|
data-lazy-l10n-id="tab-zen-unload"
|
||||||
|
oncommand="gZenTabUnloader.unloadTab();"/>
|
||||||
|
<menu data-lazy-l10n-id="zen-tabs-unloader-tab-actions" id="context_zenTabActions">
|
||||||
|
<menupopup>
|
||||||
|
<menuitem id="context_zenPreventUnloadTab"
|
||||||
|
data-lazy-l10n-id="tab-zen-prevent-unload"
|
||||||
|
oncommand="gZenTabUnloader.preventUnloadTab();"/>
|
||||||
|
<menuitem id="context_zenIgnoreUnloadTab"
|
||||||
|
data-lazy-l10n-id="tab-zen-ignore-unload"
|
||||||
|
oncommand="gZenTabUnloader.ignoreUnloadTab();"/>
|
||||||
|
</menupopup>
|
||||||
|
</menu>
|
||||||
|
`);
|
||||||
|
document.getElementById('context_closeDuplicateTabs').parentNode.appendChild(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
unloadTab() {
|
||||||
|
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||||
|
for (const tab of tabs) {
|
||||||
|
gBrowser.discardBrowser(tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
preventUnloadTab() {
|
||||||
|
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||||
|
for (const tab of tabs) {
|
||||||
|
tab.zenIgnoreUnload = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ignoreUnloadTab() {
|
||||||
|
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||||
|
for (const tab of tabs) {
|
||||||
|
tab.zenIgnoreUnload = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
canUnloadTab(tab, currentTimestamp, excludedUrls) {
|
canUnloadTab(tab, currentTimestamp, excludedUrls) {
|
||||||
if (tab.pinned || tab.selected || tab.multiselected
|
if (tab.pinned || tab.selected || tab.multiselected
|
||||||
|| tab.hasAttribute("busy") || tab.hasAttribute("pending")
|
|| tab.hasAttribute("busy") || tab.hasAttribute("pending")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue