commit 3ad15f7b59482d1f0fb26665ba2a55c6450b1360
parent 77f12527aad5bcc5214e2a8b06a62162e6cc8c6c
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 2 Jun 2015 14:55:29 -0400
Use Zotero.Utilities.Internal.exec() for PDF tool calls
Diffstat:
2 files changed, 10 insertions(+), 27 deletions(-)
diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js
@@ -624,17 +624,10 @@ Zotero.Fulltext = new function(){
// Modified 3.02 version that can output a text file directly
if (_pdfInfo && _pdfInfoVersion.startsWith('3.02')) {
- var args = [filePath, infoFilePath];
-
- Zotero.debug("Running " + _pdfInfo.path + ' '
- + args.map(arg => "'" + arg + "'").join(' '));
-
- var proc = Components.classes["@mozilla.org/process/util;1"]
- .createInstance(Components.interfaces.nsIProcess);
- proc.init(_pdfInfo);
+ let args = [filePath, infoFilePath];
try {
- proc.runw(true, args, args.length);
+ yield Zotero.Utilities.Internal.exec(_pdfInfo, args);
var totalPages = yield getTotalPagesFromFile(itemID);
}
catch (e) {
@@ -643,17 +636,10 @@ Zotero.Fulltext = new function(){
}
// Use redirection script
else if (_pdfInfoScript) {
- var args = [_pdfInfo.path, filePath, infoFilePath];
-
- Zotero.debug("Running " + _pdfInfoScript.path + ' '
- + args.map(arg => "'" + arg + "'").join(' '));
-
- var proc = Components.classes["@mozilla.org/process/util;1"]
- .createInstance(Components.interfaces.nsIProcess);
- proc.init(_pdfInfoScript);
+ let args = [_pdfInfo.path, filePath, infoFilePath];
try {
- proc.runw(true, args, args.length);
+ yield Zotero.Utilities.Internal.exec(_pdfInfoScript, args);
var totalPages = yield getTotalPagesFromFile(itemID);
}
catch (e) {
@@ -666,8 +652,6 @@ Zotero.Fulltext = new function(){
Zotero.debug(this.pdfInfoName + " is not available");
}
- var proc = Components.classes["@mozilla.org/process/util;1"]
- .createInstance(Components.interfaces.nsIProcess);
var {exec, args} = this.getPDFConverterExecAndArgs();
args.push('-enc', 'UTF-8', '-nopgbrk');
@@ -682,11 +666,8 @@ Zotero.Fulltext = new function(){
}
args.push(filePath, cacheFilePath);
- Zotero.debug("Running " + exec.path + " " + args.map(arg => "'" + arg + "'").join(" "));
-
try {
- proc.init(exec);
- proc.runw(true, args, args.length);
+ yield Zotero.Utilities.Internal.exec(exec, args);
}
catch (e) {
Components.utils.reportError(e);
diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js
@@ -334,20 +334,22 @@ Zotero.Utilities.Internal = {
* @param {String[]} args Arguments given
* @return {Promise} Promise resolved to true if command succeeds, or an error otherwise
*/
- "exec":function(cmd, args) {
+ "exec": Zotero.Promise.method(function (cmd, args) {
if (typeof cmd == 'string') {
Components.utils.import("resource://gre/modules/FileUtils.jsm");
cmd = new FileUtils.File(cmd);
}
if(!cmd.isExecutable()) {
- return Zotero.Promise.reject(cmd.path+" is not an executable");
+ throw new Error(cmd.path + " is not an executable");
}
var proc = Components.classes["@mozilla.org/process/util;1"].
createInstance(Components.interfaces.nsIProcess);
proc.init(cmd);
+ Zotero.debug("Running " + cmd.path + " " + args.map(arg => "'" + arg + "'").join(" "));
+
var deferred = Zotero.Promise.defer();
proc.runwAsync(args, args.length, {"observe":function(subject, topic) {
if(topic !== "process-finished") {
@@ -360,7 +362,7 @@ Zotero.Utilities.Internal = {
}});
return deferred.promise;
- },
+ }),
/**
* Get string data from the clipboard