From dd9cc40c16ef9171b645a2fd021a5ac586714678 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 17 May 2016 11:50:26 -0400 Subject: [PATCH] Cancel pending feed update check on Zotero shutdown This avoids errors for a missing 'feeds' table during tests, when the callback started in Zotero.Feeds.init() runs but the Zotero object has been torn down and the database hasn't yet been reinitialized. --- chrome/content/zotero/xpcom/data/feeds.js | 14 ++++++++++++-- chrome/content/zotero/xpcom/zotero.js | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/feeds.js b/chrome/content/zotero/xpcom/data/feeds.js index f3f94df3eb..d341736834 100644 --- a/chrome/content/zotero/xpcom/data/feeds.js +++ b/chrome/content/zotero/xpcom/data/feeds.js @@ -26,8 +26,18 @@ // Mimics Zotero.Libraries Zotero.Feeds = new function() { this.init = function () { - setTimeout(() => this.scheduleNextFeedCheck(), 5000); - } + this._timeoutID = setTimeout(() => { + this.scheduleNextFeedCheck(); + this._timeoutID = null; + }, 5000); + }; + + this.uninit = function () { + if (this._timeoutID) { + clearTimeout(this._timeoutID); + this._timeoutID = null + } + }; this._cache = null; diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index d187706e86..b23906b7a6 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -736,6 +736,7 @@ Components.utils.import("resource://gre/modules/osfile.jsm"); Zotero.Items.startEmptyTrashTimer(); Zotero.Feeds.init(); + Zotero.addShutdownListener(() => Zotero.Feeds.uninit()); return true; }