Cancel delayed quickCopy initialization when resetting DB during tests
And improve cancellation of scheduled feed checks
This commit is contained in:
parent
511222bcaf
commit
6a523347b2
|
@ -23,12 +23,17 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
// Mimics Zotero.Libraries
|
||||
Zotero.Feeds = new function() {
|
||||
var _initTimeoutID;
|
||||
var _initPromise;
|
||||
|
||||
this.init = function () {
|
||||
this._timeoutID = setTimeout(() => {
|
||||
this.scheduleNextFeedCheck();
|
||||
this._timeoutID = null;
|
||||
_initTimeoutID = setTimeout(() => {
|
||||
_initTimeoutID = null;
|
||||
_initPromise = this.scheduleNextFeedCheck().then(() => _initPromise = null);
|
||||
}, 5000);
|
||||
|
||||
Zotero.SyncedSettings.onSyncDownload.addListener(Zotero.Libraries.userLibraryID, 'feeds',
|
||||
|
@ -45,9 +50,14 @@ Zotero.Feeds = new function() {
|
|||
};
|
||||
|
||||
this.uninit = function () {
|
||||
if (this._timeoutID) {
|
||||
clearTimeout(this._timeoutID);
|
||||
this._timeoutID = null
|
||||
// Cancel feed check if not yet run
|
||||
if (_initTimeoutID) {
|
||||
clearTimeout(_initTimeoutID);
|
||||
_initTimeoutID = null
|
||||
}
|
||||
// Cancel feed check if in progress
|
||||
if (_initPromise) {
|
||||
_initPromise.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -23,18 +23,25 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
Zotero.QuickCopy = new function() {
|
||||
var _initTimeoutID
|
||||
var _initPromise;
|
||||
var _initialized = false;
|
||||
var _siteSettings;
|
||||
var _formattedNames;
|
||||
var _initialized = false;
|
||||
|
||||
this.init = Zotero.Promise.coroutine(function* () {
|
||||
yield this.loadSiteSettings();
|
||||
|
||||
// Load code for selected export translator ahead of time
|
||||
// (in the background, because it requires translator initialization)
|
||||
setTimeout(_loadOutputFormat, 5000);
|
||||
_initTimeoutID = setTimeout(() => {
|
||||
_initTimeoutID = null;
|
||||
_initPromise = _loadOutputFormat().then(() => _initPromise = null);
|
||||
}, 5000);
|
||||
|
||||
if (!_initialized) {
|
||||
Zotero.Prefs.registerObserver("export.quickCopy.setting", () => _loadOutputFormat());
|
||||
_initialized = true;
|
||||
|
@ -42,6 +49,19 @@ Zotero.QuickCopy = new function() {
|
|||
});
|
||||
|
||||
|
||||
this.uninit = function () {
|
||||
// Cancel load if not yet done
|
||||
if (_initTimeoutID) {
|
||||
clearTimeout(_initTimeoutID);
|
||||
_initTimeoutID = null
|
||||
}
|
||||
// Cancel load if in progress
|
||||
if (_initPromise) {
|
||||
_initPromise.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.loadSiteSettings = Zotero.Promise.coroutine(function* () {
|
||||
var sql = "SELECT key AS domainPath, value AS format FROM settings "
|
||||
+ "WHERE setting='quickCopySite'";
|
||||
|
|
|
@ -633,8 +633,6 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
|||
yield Zotero.Searches.loadAll(library.libraryID);
|
||||
})()
|
||||
);
|
||||
|
||||
yield Zotero.QuickCopy.init();
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.logError(e);
|
||||
|
@ -735,6 +733,10 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
|||
};
|
||||
|
||||
Zotero.Items.startEmptyTrashTimer();
|
||||
|
||||
yield Zotero.QuickCopy.init();
|
||||
Zotero.addShutdownListener(() => Zotero.QuickCopy.uninit());
|
||||
|
||||
Zotero.Feeds.init();
|
||||
Zotero.addShutdownListener(() => Zotero.Feeds.uninit());
|
||||
|
||||
|
|
|
@ -40,10 +40,16 @@ describe("Zotero.QuickCopy", function() {
|
|||
var content = "";
|
||||
var worked = false;
|
||||
|
||||
var format = 'export=9cb70025-a888-4a29-a210-93ec52da40d4'; // BibTeX
|
||||
yield Zotero.Translators.init();
|
||||
|
||||
var translatorID = '9cb70025-a888-4a29-a210-93ec52da40d4'; // BibTeX
|
||||
var format = 'export=' + translatorID;
|
||||
Zotero.Prefs.set('export.quickCopy.setting', format);
|
||||
// The translator code is loaded automatically on pref change, but let's not wait for it
|
||||
yield Zotero.QuickCopy.init();
|
||||
// Translator code for selected format is loaded automatically, so wait for it
|
||||
var translator = Zotero.Translators.get(translatorID);
|
||||
while (!translator.code) {
|
||||
yield Zotero.Promise.delay(50);
|
||||
}
|
||||
|
||||
Zotero.QuickCopy.getContentFromItems(
|
||||
[item],
|
||||
|
|
Loading…
Reference in New Issue
Block a user