Use Zotero.Utilities.Internal.exec() for PDF tool calls
This commit is contained in:
parent
77f12527aa
commit
3ad15f7b59
2 changed files with 10 additions and 27 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue