mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:39:58 +02:00
feat: Separate pinned tab initialization and handling
This commit refactors the `ZenPinnedTabManager` class to separate the initialization of pinned tabs from the handling of pinned tab events. - **Initialization:** The `initTabs()` method is now responsible for initializing the pinned tab storage, waiting for the session store to be initialized, and then refreshing the pinned tabs. - **Event handling:** The `init()` method focuses on setting up the event listeners and observers for pinned tabs. This separation improves the code structure and allows for better handling of pinned tab initialization, which was previously problematic due to the asynchronous nature of the process. Additionally, this commit includes minor fixes and improvements: - Removed the `TabClose` event handler, as it is currently causing issues with the tab deletion process. - Added a check to prevent duplicate pinned tab attributes. - Improved the way favicons are set for pinned tabs.
This commit is contained in:
parent
2adc19bc21
commit
af5f4f97d7
1 changed files with 21 additions and 11 deletions
|
@ -36,13 +36,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ZenPinnedTabManager extends ZenMultiWindowFeature {
|
class ZenPinnedTabManager extends ZenDOMOperatedFeature {
|
||||||
|
|
||||||
async init() {
|
init() {
|
||||||
this.observer = new ZenPinnedTabsObserver();
|
this.observer = new ZenPinnedTabsObserver();
|
||||||
await ZenPinnedTabsStorage.init();
|
|
||||||
await SessionStore.promiseInitialized;
|
|
||||||
await this._refreshPinnedTabs();
|
|
||||||
this._initClosePinnedTabShortcut();
|
this._initClosePinnedTabShortcut();
|
||||||
this._insertItemsIntoTabContextMenu();
|
this._insertItemsIntoTabContextMenu();
|
||||||
this.observer.addPinnedTabListener(this._onPinnedTabEvent.bind(this));
|
this.observer.addPinnedTabListener(this._onPinnedTabEvent.bind(this));
|
||||||
|
@ -50,6 +47,12 @@
|
||||||
this._zenClickEventListener = this._onTabClick.bind(this);
|
this._zenClickEventListener = this._onTabClick.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async initTabs() {
|
||||||
|
await ZenPinnedTabsStorage.init();
|
||||||
|
await SessionStore.promiseInitialized;
|
||||||
|
await this._refreshPinnedTabs();
|
||||||
|
}
|
||||||
|
|
||||||
async _refreshPinnedTabs() {
|
async _refreshPinnedTabs() {
|
||||||
await this._initializePinsCache();
|
await this._initializePinsCache();
|
||||||
this._initializePinnedTabs();
|
this._initializePinnedTabs();
|
||||||
|
@ -139,9 +142,10 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set the favicon from cache
|
// Set the favicon from cache
|
||||||
if (pin.iconUrl) {
|
if (!!pin.iconUrl) {
|
||||||
gBrowser.setIcon(newTab, pin.iconUrl, null,
|
// TODO: Figure out if there is a better way -
|
||||||
Services.scriptSecurityManager.getSystemPrincipal());
|
// calling gBrowser.setIcon messes shit up and should be avoided. I think this works for now.
|
||||||
|
newTab.setAttribute("image", pin.iconUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
newTab.setAttribute("zen-pin-id", pin.uuid);
|
newTab.setAttribute("zen-pin-id", pin.uuid);
|
||||||
|
@ -175,9 +179,10 @@
|
||||||
delete tab._zenClickEventListener;
|
delete tab._zenClickEventListener;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "TabClose":
|
// TODO: Do this in a better way. Closing a second window could trigger remove tab and delete it from db
|
||||||
this._removePinnedAttributes(tab);
|
// case "TabClose":
|
||||||
break;
|
// this._removePinnedAttributes(tab);
|
||||||
|
// break;
|
||||||
default:
|
default:
|
||||||
console.warn('ZenPinnedTabManager: Unhandled tab event', action);
|
console.warn('ZenPinnedTabManager: Unhandled tab event', action);
|
||||||
break;
|
break;
|
||||||
|
@ -228,6 +233,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async _setPinnedAttributes(tab) {
|
async _setPinnedAttributes(tab) {
|
||||||
|
|
||||||
|
if (tab.hasAttribute("zen-pin-id")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const browser = tab.linkedBrowser;
|
const browser = tab.linkedBrowser;
|
||||||
|
|
||||||
const uuid = gZenUIManager.generateUuidv4();
|
const uuid = gZenUIManager.generateUuidv4();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue