mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 06:09:58 +02:00
Store all pinned tab data in single attribute
This commit updates the pinned tab manager to store all relevant data (URL, title, triggering principal, and icon) in a single JSON string attribute (`zen-pinned-entry`). This simplifies the code by eliminating the need for multiple individual attributes and provides a more robust and organized approach to storing the pinned tab's state. The following changes were made: - Removed redundant attributes (`zen-pinned-url`, `zen-pinned-title`, `zen-pinned-triggering-principal`) - Updated the pinned tab data structure to store all information in a single `zen-pinned-entry` attribute - Adjusted the `resetPinnedTabData` function to handle the new data structure - Modified the pinned tab context menu to reflect the changes in the attribute handling This change provides a more efficient and streamlined way to manage pinned tab data, enhancing the overall maintainability and clarity of the codebase.
This commit is contained in:
parent
1396523f3b
commit
7d8dde9269
1 changed files with 24 additions and 22 deletions
|
@ -94,17 +94,17 @@
|
|||
}
|
||||
|
||||
_setPinnedAttributes(tab) {
|
||||
tab.setAttribute("zen-pinned-url", tab.linkedBrowser.currentURI.spec);
|
||||
tab.setAttribute("zen-pinned-title", tab.getAttribute("label"));
|
||||
tab.setAttribute("zen-pinned-icon", tab.linkedBrowser.mIconURL);
|
||||
tab.setAttribute("zen-pinned-triggering-principal", lazy.E10SUtils.serializePrincipal(tab.linkedBrowser.contentPrincipal));
|
||||
const browser = tab.linkedBrowser;
|
||||
const tabState = JSON.parse(SessionStore.getTabState(tab));
|
||||
const activeEntry = tabState.entries[tabState.index - 1];
|
||||
|
||||
tab.setAttribute("zen-pinned-entry", JSON.stringify(activeEntry));
|
||||
tab.setAttribute("zen-pinned-icon", browser.mIconURL);
|
||||
}
|
||||
|
||||
_removePinnedAttributes(tab) {
|
||||
tab.removeAttribute("zen-pinned-url");
|
||||
tab.removeAttribute("zen-pinned-title");
|
||||
tab.removeAttribute("zen-pinned-entry");
|
||||
tab.removeAttribute("zen-pinned-icon");
|
||||
tab.removeAttribute("zen-pinned-triggering-principal");
|
||||
}
|
||||
|
||||
_initClosePinnedTabShortcut() {
|
||||
|
@ -116,17 +116,21 @@
|
|||
}
|
||||
|
||||
setPinnedTabState(tabData, tab) {
|
||||
tabData.zenPinnedUrl = tab.getAttribute("zen-pinned-url");
|
||||
tabData.zenPinnedTitle = tab.getAttribute("zen-pinned-title");
|
||||
tabData.zenPinnedEntry = tab.getAttribute("zen-pinned-entry");
|
||||
tabData.zenPinnedIcon = tab.getAttribute("zen-pinned-icon");
|
||||
tabData.zenPinnedTriggeringPrincipal = tab.getAttribute("zen-pinned-triggering-principal");
|
||||
}
|
||||
|
||||
updatePinnedTabForSessionRestore(tabData, tab) {
|
||||
!!tabData.zenPinnedUrl ? tab.setAttribute("zen-pinned-url", tabData.zenPinnedUrl) : tab.removeAttribute("zen-pinned-url");
|
||||
!!tabData.zenPinnedTitle ? tab.setAttribute("zen-pinned-title", tabData.zenPinnedTitle) : tab.removeAttribute("zen-pinned-title");
|
||||
!!tabData.zenPinnedIcon ? tab.setAttribute("zen-pinned-icon", tabData.zenPinnedIcon) : tab.removeAttribute("zen-pinned-icon");
|
||||
!!tabData.zenPinnedTriggeringPrincipal ? tab.setAttribute("zen-pinned-triggering-principal", tabData.zenPinnedTriggeringPrincipal) : tab.removeAttribute("zen-pinned-triggering-principal");
|
||||
if (tabData.zenPinnedEntry) {
|
||||
tab.setAttribute("zen-pinned-entry", tabData.zenPinnedEntry);
|
||||
} else {
|
||||
tab.removeAttribute("zen-pinned-entry");
|
||||
}
|
||||
if (tabData.zenPinnedIcon) {
|
||||
tab.setAttribute("zen-pinned-icon", tabData.zenPinnedIcon);
|
||||
} else {
|
||||
tab.removeAttribute("zen-pinned-icon");
|
||||
}
|
||||
}
|
||||
|
||||
_onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab) {
|
||||
|
@ -184,16 +188,14 @@
|
|||
}
|
||||
|
||||
_resetTabToStoredState(tab) {
|
||||
const url = tab.getAttribute("zen-pinned-url");
|
||||
const title = tab.getAttribute("zen-pinned-title");
|
||||
const entry = tab.getAttribute("zen-pinned-entry");
|
||||
const icon = tab.getAttribute("zen-pinned-icon");
|
||||
const triggeringPrincipal_base64 = tab.getAttribute("zen-pinned-triggering-principal");
|
||||
|
||||
if (url) {
|
||||
if (entry) {
|
||||
const tabState = SessionStore.getTabState(tab);
|
||||
const state = JSON.parse(tabState);
|
||||
|
||||
state.entries = [{url, title, triggeringPrincipal_base64}];
|
||||
state.entries = [JSON.parse(entry)];
|
||||
state.image = icon;
|
||||
state.index = 0;
|
||||
|
||||
|
@ -216,8 +218,8 @@
|
|||
}
|
||||
|
||||
resetPinnedTabData(tabData) {
|
||||
if (lazy.zenPinnedTabRestorePinnedTabsToPinnedUrl && tabData.pinned && tabData.zenPinnedUrl) {
|
||||
tabData.entries = [{url: tabData.zenPinnedUrl, title: tabData.zenPinnedTitle, triggeringPrincipal_base64: tabData.zenPinnedTriggeringPrincipal}];
|
||||
if (lazy.zenPinnedTabRestorePinnedTabsToPinnedUrl && tabData.pinned && tabData.zenPinnedEntry) {
|
||||
tabData.entries = [JSON.parse(tabData.zenPinnedEntry)];
|
||||
tabData.image = tabData.zenPinnedIcon;
|
||||
tabData.index = 0;
|
||||
}
|
||||
|
@ -225,7 +227,7 @@
|
|||
|
||||
updatePinnedTabContextMenu(contextTab) {
|
||||
const isVisible = contextTab.pinned && !contextTab.multiselected;
|
||||
document.getElementById("context_zen-reset-pinned-tab").hidden = !isVisible || !contextTab.getAttribute("zen-pinned-url");
|
||||
document.getElementById("context_zen-reset-pinned-tab").hidden = !isVisible || !contextTab.getAttribute("zen-pinned-entry");
|
||||
document.getElementById("context_zen-replace-pinned-url-with-current").hidden = !isVisible;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue