Remove reader events when plugin is disabled

This commit is contained in:
windingwind 2023-09-14 12:00:44 +08:00 committed by Martynas Bagdonas
parent 96652ea9e8
commit 78fe68164f

View file

@ -1229,6 +1229,12 @@ class Reader {
} }
this._setSidebarState(); this._setSidebarState();
}, 500); }, 500);
Zotero.Plugins.addObserver({
shutdown: ({ id: pluginID }) => {
this._unregisterEventListenerByPluginID(pluginID);
}
});
} }
_dispatchEvent(event) { _dispatchEvent(event) {
@ -1269,13 +1275,17 @@ class Reader {
* }); * });
* }); * });
*/ */
registerEventListener(type, handler) { registerEventListener(type, handler, pluginID = undefined) {
this._registeredListeners.push({ type, handler }); this._registeredListeners.push({ pluginID, type, handler });
} }
unregisterEventListener(type, handler) { unregisterEventListener(type, handler) {
this._registeredListeners = this._registeredListeners.filter(x => x.type === type && x.handler === handler); this._registeredListeners = this._registeredListeners.filter(x => x.type === type && x.handler === handler);
} }
_unregisterEventListenerByPluginID(pluginID) {
this._registeredListeners = this._registeredListeners.filter(x => x.pluginID !== pluginID);
}
getSidebarWidth() { getSidebarWidth() {
return this._sidebarWidth; return this._sidebarWidth;