From 1ede4240e05f397b945d75339add83cba3d72a4c Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 17 Mar 2021 17:53:16 +0200 Subject: [PATCH] Close all tabs and unregister tabs observer when destroying main window #2005 --- chrome/content/zotero/standalone/standalone.js | 3 ++- chrome/content/zotero/tabs.js | 7 +++++++ chrome/content/zotero/zoteroPane.js | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js index 4c0df56ecf..6eb5958f06 100644 --- a/chrome/content/zotero/standalone/standalone.js +++ b/chrome/content/zotero/standalone/standalone.js @@ -50,7 +50,7 @@ const ZoteroStandalone = new function() { } this.switchMenuType('library'); - Zotero.Notifier.registerObserver( + this._notifierID = Zotero.Notifier.registerObserver( { notify: async (action, type, ids, extraData) => { if (action == 'select') { @@ -586,6 +586,7 @@ const ZoteroStandalone = new function() { * Called before standalone window is closed */ this.onUnload = function() { + Zotero.Notifier.unregisterObserver(this._notifierID); ZoteroPane.destroy(); } } diff --git a/chrome/content/zotero/tabs.js b/chrome/content/zotero/tabs.js index 670f9f5b9d..a6f853696b 100644 --- a/chrome/content/zotero/tabs.js +++ b/chrome/content/zotero/tabs.js @@ -169,6 +169,13 @@ var Zotero_Tabs = new function () { }*/ }; + /** + * Close all tabs except the first one + */ + this.closeAll = function () { + this._tabs.slice(1).map(tab => this.close(tab.id)); + }; + /** * Move a tab to the specified index * diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index a539211cf6..92a9946b9c 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -370,6 +370,8 @@ var ZoteroPane = new function() if(this.itemsView) this.itemsView.unregister(); observerService.removeObserver(_reloadObserver, "zotero-reloaded"); + + Zotero_Tabs.closeAll(); } /**