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
|
// Modified 3.02 version that can output a text file directly
|
||||||
if (_pdfInfo && _pdfInfoVersion.startsWith('3.02')) {
|
if (_pdfInfo && _pdfInfoVersion.startsWith('3.02')) {
|
||||||
var args = [filePath, infoFilePath];
|
let 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);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
proc.runw(true, args, args.length);
|
yield Zotero.Utilities.Internal.exec(_pdfInfo, args);
|
||||||
var totalPages = yield getTotalPagesFromFile(itemID);
|
var totalPages = yield getTotalPagesFromFile(itemID);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
@ -643,17 +636,10 @@ Zotero.Fulltext = new function(){
|
||||||
}
|
}
|
||||||
// Use redirection script
|
// Use redirection script
|
||||||
else if (_pdfInfoScript) {
|
else if (_pdfInfoScript) {
|
||||||
var args = [_pdfInfo.path, filePath, infoFilePath];
|
let 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);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
proc.runw(true, args, args.length);
|
yield Zotero.Utilities.Internal.exec(_pdfInfoScript, args);
|
||||||
var totalPages = yield getTotalPagesFromFile(itemID);
|
var totalPages = yield getTotalPagesFromFile(itemID);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
@ -666,8 +652,6 @@ Zotero.Fulltext = new function(){
|
||||||
Zotero.debug(this.pdfInfoName + " is not available");
|
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();
|
var {exec, args} = this.getPDFConverterExecAndArgs();
|
||||||
args.push('-enc', 'UTF-8', '-nopgbrk');
|
args.push('-enc', 'UTF-8', '-nopgbrk');
|
||||||
|
|
||||||
|
@ -682,11 +666,8 @@ Zotero.Fulltext = new function(){
|
||||||
}
|
}
|
||||||
args.push(filePath, cacheFilePath);
|
args.push(filePath, cacheFilePath);
|
||||||
|
|
||||||
Zotero.debug("Running " + exec.path + " " + args.map(arg => "'" + arg + "'").join(" "));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
proc.init(exec);
|
yield Zotero.Utilities.Internal.exec(exec, args);
|
||||||
proc.runw(true, args, args.length);
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Components.utils.reportError(e);
|
Components.utils.reportError(e);
|
||||||
|
|
|
@ -334,20 +334,22 @@ Zotero.Utilities.Internal = {
|
||||||
* @param {String[]} args Arguments given
|
* @param {String[]} args Arguments given
|
||||||
* @return {Promise} Promise resolved to true if command succeeds, or an error otherwise
|
* @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') {
|
if (typeof cmd == 'string') {
|
||||||
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
||||||
cmd = new FileUtils.File(cmd);
|
cmd = new FileUtils.File(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!cmd.isExecutable()) {
|
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"].
|
var proc = Components.classes["@mozilla.org/process/util;1"].
|
||||||
createInstance(Components.interfaces.nsIProcess);
|
createInstance(Components.interfaces.nsIProcess);
|
||||||
proc.init(cmd);
|
proc.init(cmd);
|
||||||
|
|
||||||
|
Zotero.debug("Running " + cmd.path + " " + args.map(arg => "'" + arg + "'").join(" "));
|
||||||
|
|
||||||
var deferred = Zotero.Promise.defer();
|
var deferred = Zotero.Promise.defer();
|
||||||
proc.runwAsync(args, args.length, {"observe":function(subject, topic) {
|
proc.runwAsync(args, args.length, {"observe":function(subject, topic) {
|
||||||
if(topic !== "process-finished") {
|
if(topic !== "process-finished") {
|
||||||
|
@ -360,7 +362,7 @@ Zotero.Utilities.Internal = {
|
||||||
}});
|
}});
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get string data from the clipboard
|
* Get string data from the clipboard
|
||||||
|
|
Loading…
Reference in a new issue