- 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.debug("Translate: Beginning transaction");
|
||||||
Zotero.DB.beginTransaction();
|
Zotero.DB.beginTransaction();
|
||||||
|
|
||||||
this._timer = Components.classes["@mozilla.org/timer;1"].
|
var me = this;
|
||||||
createInstance(Components.interfaces.nsITimer);
|
Zotero.setTimeout(function() { me._closeTransaction() }, 0);
|
||||||
this._timer.initWithCallback(this, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
|
||||||
|
|
||||||
Zotero.showZoteroPaneProgressMeter(Zotero.getString("ingester.scraping"), false);
|
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
|
* Closes the transaction when the current code block finishes executing.
|
||||||
* executing.
|
|
||||||
*/
|
*/
|
||||||
"notify":function() {
|
"_closeTransaction":function() {
|
||||||
if(Zotero.waiting) {
|
|
||||||
this._timer.initWithCallback(this, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.debug("Translate: Closing transaction");
|
Zotero.debug("Translate: Closing transaction");
|
||||||
Zotero.hideZoteroPaneOverlay();
|
Zotero.hideZoteroPaneOverlay();
|
||||||
Zotero.DB.commitTransaction();
|
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()
|
* during Zotero.wait()
|
||||||
*
|
*
|
||||||
* @param {Function} func The function to be called
|
* @param {Function} func The function to be called
|
||||||
* @param {Integer} ms The number of milliseconds to wait before calling func
|
* @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"].
|
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||||
createInstance(Components.interfaces.nsITimer);
|
createInstance(Components.interfaces.nsITimer);
|
||||||
var timerCallback = {"notify":function() {
|
var timerCallback = {"notify":function() {
|
||||||
if(_waiting) {
|
if(_waiting && !runWhenWaiting) {
|
||||||
// if our callback gets called during Zotero.wait(), queue it to be set again
|
// if our callback gets called during Zotero.wait(), queue it to be set again
|
||||||
// when Zotero.wait() completes
|
// when Zotero.wait() completes
|
||||||
_waitTimers.push(timer);
|
_waitTimers.push(timer);
|
||||||
|
|
|
@ -62,9 +62,7 @@ ZoteroCommandLineHandler.prototype = {
|
||||||
|
|
||||||
// Not quite sure why this is necessary to get the appropriate scoping
|
// Not quite sure why this is necessary to get the appropriate scoping
|
||||||
var Zotero = this.Zotero;
|
var Zotero = this.Zotero;
|
||||||
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
|
Zotero.setTimeout(function() { Zotero.Integration.execCommand(agent, command, docId) }, 0);
|
||||||
timer.initWithCallback({notify:function() { Zotero.Integration.execCommand(agent, command, docId) }}, 0,
|
|
||||||
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler for Windows IPC commands
|
// handler for Windows IPC commands
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue