Allow custom handler for PDF files
Configurable via extensions.zotero.fileHandler.pdf hidden pref for now, though we'll probably make it a visible pref. We also appear to have been doing blocking launches when launch() failed, which may have been causing UI hangs when opening files on some Linux installations. (I'm not sure if that's an issue with recent Firefox builds. launch() works on Ubuntu 17.10.) All launches are now async. This is a rewritten version of PR #1450 by @ehhc. Closes #1450
This commit is contained in:
parent
f6926ccda6
commit
da09a3bb96
3 changed files with 35 additions and 16 deletions
|
@ -1110,21 +1110,8 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
||||||
else {
|
else {
|
||||||
var pref = "fallbackLauncher.unix";
|
var pref = "fallbackLauncher.unix";
|
||||||
}
|
}
|
||||||
var path = Zotero.Prefs.get(pref);
|
let launcher = Zotero.Prefs.get(pref);
|
||||||
|
this.launchFileWithApplication(file.path, launcher);
|
||||||
var exec = Components.classes["@mozilla.org/file/local;1"]
|
|
||||||
.createInstance(Components.interfaces.nsILocalFile);
|
|
||||||
exec.initWithPath(path);
|
|
||||||
if (!exec.exists()) {
|
|
||||||
throw new Error(path + " does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
var proc = Components.classes["@mozilla.org/process/util;1"]
|
|
||||||
.createInstance(Components.interfaces.nsIProcess);
|
|
||||||
proc.init(exec);
|
|
||||||
|
|
||||||
var args = [file.path];
|
|
||||||
proc.runw(true, args, args.length);
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.debug(e);
|
Zotero.debug(e);
|
||||||
|
@ -1142,7 +1129,21 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
||||||
nsIEPS.loadUrl(uri);
|
nsIEPS.loadUrl(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch a file with the given application
|
||||||
|
*/
|
||||||
|
this.launchFileWithApplication = function (filePath, applicationPath) {
|
||||||
|
var exec = Zotero.File.pathToFile(applicationPath);
|
||||||
|
if (!exec.exists()) {
|
||||||
|
throw new Error("'" + applicationPath + "' does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Async, but we don't want to block
|
||||||
|
Zotero.Utilities.Internal.exec(applicationPath, [filePath]);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4199,6 +4199,21 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Zotero.Notifier.trigger('open', 'file', itemID);
|
Zotero.Notifier.trigger('open', 'file', itemID);
|
||||||
|
|
||||||
|
// Custom PDF handler
|
||||||
|
if (item.attachmentContentType === 'application/pdf') {
|
||||||
|
let pdfHandler = Zotero.Prefs.get("fileHandler.pdf");
|
||||||
|
if (pdfHandler) {
|
||||||
|
if (yield OS.File.exists(pdfHandler)) {
|
||||||
|
Zotero.launchFileWithApplication(file.path, pdfHandler);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Zotero.logError(`${pdfHandler} not found -- launching file normally`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Zotero.launchFile(file);
|
Zotero.launchFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,9 @@ pref("extensions.zotero.ingester.allowedSites", "");
|
||||||
pref("extensions.zotero.connector.repo.lastCheck.localTime", 0);
|
pref("extensions.zotero.connector.repo.lastCheck.localTime", 0);
|
||||||
pref("extensions.zotero.connector.repo.lastCheck.repoTime", 0);
|
pref("extensions.zotero.connector.repo.lastCheck.repoTime", 0);
|
||||||
|
|
||||||
|
// Custom file handlers
|
||||||
|
pref("extensions.zotero.fileHandler.pdf", "");
|
||||||
|
|
||||||
// File/URL opening executable if launch() fails
|
// File/URL opening executable if launch() fails
|
||||||
pref("extensions.zotero.fallbackLauncher.unix", "/usr/bin/xdg-open");
|
pref("extensions.zotero.fallbackLauncher.unix", "/usr/bin/xdg-open");
|
||||||
pref("extensions.zotero.fallbackLauncher.windows", "");
|
pref("extensions.zotero.fallbackLauncher.windows", "");
|
||||||
|
|
Loading…
Reference in a new issue