feat(pinned-tab-manager): Add restore pinned tabs to pinned url option

This commit introduces a new option to the pinned tab manager that allows users to restore pinned tabs to their pinned URL and title, even if the current tab has a different URL.

- Adds a new preference `zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url` to control this behavior.
- Updates the tab browser, tab state, and preferences code to support the new option.
- Adds a new UI element in the settings to allow users to enable/disable this feature.

This feature enhances the pinned tab manager by providing more control over how pinned tabs are restored when the browser is restarted.
This commit is contained in:
Kristijan Ribarić
2024-10-07 20:03:29 +02:00
parent 6dcff571d2
commit 8c42614427
5 changed files with 46 additions and 13 deletions

View File

@@ -1,8 +1,8 @@
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b6835bdacdb 100644
index c89ae2cbb978d6218bd56a059c5ca1e371231607..6608e0d7df1092a7398979abb166895e0b4fb66b 100644
--- a/browser/components/tabbrowser/content/tabbrowser.js
+++ b/browser/components/tabbrowser/content/tabbrowser.js
@@ -452,11 +452,26 @@
@@ -456,11 +456,26 @@
return duplicateTabs;
},
@@ -31,7 +31,7 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
}
return i;
},
@@ -2704,6 +2719,11 @@
@@ -2705,6 +2720,11 @@
);
}
@@ -43,7 +43,7 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
if (!UserInteraction.running("browser.tabs.opening", window)) {
UserInteraction.start("browser.tabs.opening", "initting", window);
}
@@ -2771,6 +2791,9 @@
@@ -2773,6 +2793,9 @@
noInitialLabel,
skipBackgroundNotify,
});
@@ -53,7 +53,7 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
if (insertTab) {
// insert the tab into the tab container in the correct position
this._insertTabAtIndex(t, {
@@ -3248,6 +3271,14 @@
@@ -3262,6 +3285,14 @@
) {
tabWasReused = true;
tab = this.selectedTab;
@@ -68,7 +68,21 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
if (!tabData.pinned) {
this.unpinTab(tab);
} else {
@@ -3297,6 +3328,12 @@
@@ -3283,6 +3314,13 @@
url = tabData.entries[activeIndex].url;
}
+ if(Services.prefs.getBoolPref("zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url", false) && tabData.pinned && tabData.zenPinnedUrl) {
+ tabData.entries = [{url: tabData.zenPinnedUrl, title: tabData.zenPinnedTitle}];
+ tabData.image = tabData.zenPinnedIcon;
+ tabData.index = 0;
+ url = tabData.zenPinnedUrl;
+ }
+
let preferredRemoteType = E10SUtils.getRemoteTypeForURI(
url,
gMultiProcessBrowser,
@@ -3311,6 +3349,12 @@
preferredRemoteType,
});
@@ -81,7 +95,7 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
if (select) {
tabToSelect = tab;
}
@@ -3331,7 +3368,13 @@
@@ -3345,7 +3389,17 @@
this.tabContainer._invalidateCachedTabs();
}
}
@@ -91,11 +105,15 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
+ if (tabData.zenPinnedTitle) {
+ tab.setAttribute("zen-pinned-title", tabData.zenPinnedTitle);
+ }
+
+ if(tabData.zenPinnedIcon) {
+ tab.setAttribute("zen-pinned-icon", tabData.zenPinnedIcon);
+ }
tab.initialize();
}
@@ -4184,6 +4227,7 @@
@@ -4198,6 +4252,7 @@
isLastTab ||
aTab.pinned ||
aTab.hidden ||
@@ -103,7 +121,7 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
this._removingTabs.size >
3 /* don't want lots of concurrent animations */ ||
!aTab.hasAttribute(
@@ -5117,10 +5161,10 @@
@@ -5131,10 +5186,10 @@
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
},
@@ -116,7 +134,7 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
aTab.selected ||
aTab.closing ||
// Tabs that are sharing the screen, microphone or camera cannot be hidden.
@@ -7822,7 +7866,10 @@ var TabContextMenu = {
@@ -7870,7 +7925,14 @@ var TabContextMenu = {
);
contextUnpinSelectedTabs.hidden =
!this.contextTab.pinned || !multiselectionContext;
@@ -124,6 +142,10 @@ index ef857bd81f2cd7c163ecc74ac1cf81a0b63ce838..7ffa8f7d64f2ed13018e3f32f94e7b68
+ let contextResetPinnedTab = document.getElementById("context_zen-reset-pinned-tab");
+ if(contextResetPinnedTab) {
+ contextResetPinnedTab.hidden = !this.contextTab.pinned || !this.contextTab.getAttribute("zen-pinned-url") || multiselectionContext;
+ }
+ let contextReplacePinnedUrlWithCurrent = document.getElementById("context_zen-replace-pinned-url-with-current");
+ if(contextReplacePinnedUrlWithCurrent) {
+ contextReplacePinnedUrlWithCurrent.hidden = !this.contextTab.pinned || !this.contextTab.getAttribute("zen-pinned-url") || multiselectionContext;
+ }
// Move Tab items
let contextMoveTabOptions = document.getElementById(