- Addresses #1828, Ensure any code that uses nsITimer directly maintains a global reference until callback executes
- Adds an optional runWhenWaiting argument to Zotero.setTimeout(), so that code can be set to run even if Zotero.wait() is in progress
This commit is contained in:
parent
5d32e800fc
commit
acfd317de9
3 changed files with 12 additions and 20 deletions
|
@ -78,10 +78,8 @@ Zotero.Translate.ItemSaver.prototype = {
|
|||
Zotero.debug("Translate: Beginning transaction");
|
||||
Zotero.DB.beginTransaction();
|
||||
|
||||
this._timer = Components.classes["@mozilla.org/timer;1"].
|
||||
createInstance(Components.interfaces.nsITimer);
|
||||
this._timer.initWithCallback(this, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||
|
||||
var me = this;
|
||||
Zotero.setTimeout(function() { me._closeTransaction() }, 0);
|
||||
Zotero.showZoteroPaneProgressMeter(Zotero.getString("ingester.scraping"), false);
|
||||
}
|
||||
|
||||
|
@ -514,15 +512,9 @@ Zotero.Translate.ItemSaver.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Implements nsITimer.notify, closing the transaction when the current code block finishes
|
||||
* executing.
|
||||
* Closes the transaction when the current code block finishes executing.
|
||||
*/
|
||||
"notify":function() {
|
||||
if(Zotero.waiting) {
|
||||
this._timer.initWithCallback(this, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||
return;
|
||||
}
|
||||
|
||||
"_closeTransaction":function() {
|
||||
Zotero.debug("Translate: Closing transaction");
|
||||
Zotero.hideZoteroPaneOverlay();
|
||||
Zotero.DB.commitTransaction();
|
||||
|
|
|
@ -1523,17 +1523,19 @@ if(appInfo.platformVersion[0] >= 2) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Emulates the behavior of window.setTimeout, but ensures that timeouts do not get called
|
||||
* Emulates the behavior of window.setTimeout, but ensures that callbacks do not get called
|
||||
* during Zotero.wait()
|
||||
*
|
||||
* @param {Function} func The function to be called
|
||||
* @param {Integer} ms The number of milliseconds to wait before calling func
|
||||
* @param {Function} func The function to be called
|
||||
* @param {Integer} ms The number of milliseconds to wait before calling func
|
||||
* @param {Boolean} runWhenWaiting True if the callback should be run even if Zotero.wait()
|
||||
* is executing
|
||||
*/
|
||||
this.setTimeout = function(func, ms) {
|
||||
this.setTimeout = function(func, ms, runWhenWaiting) {
|
||||
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||
createInstance(Components.interfaces.nsITimer);
|
||||
var timerCallback = {"notify":function() {
|
||||
if(_waiting) {
|
||||
if(_waiting && !runWhenWaiting) {
|
||||
// if our callback gets called during Zotero.wait(), queue it to be set again
|
||||
// when Zotero.wait() completes
|
||||
_waitTimers.push(timer);
|
||||
|
|
|
@ -62,9 +62,7 @@ ZoteroCommandLineHandler.prototype = {
|
|||
|
||||
// Not quite sure why this is necessary to get the appropriate scoping
|
||||
var Zotero = this.Zotero;
|
||||
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
|
||||
timer.initWithCallback({notify:function() { Zotero.Integration.execCommand(agent, command, docId) }}, 0,
|
||||
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||
Zotero.setTimeout(function() { Zotero.Integration.execCommand(agent, command, docId) }, 0);
|
||||
}
|
||||
|
||||
// handler for Windows IPC commands
|
||||
|
|
Loading…
Reference in a new issue