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