commit da09a3bb9610e00f63a108d39af6646b28f7fe2d
parent f6926ccda678b728f5fb692a60ef8023aee99a26
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 5 Mar 2018 19:29:03 -0500
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
Diffstat:
3 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -1110,21 +1110,8 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
else {
var pref = "fallbackLauncher.unix";
}
- var path = Zotero.Prefs.get(pref);
-
- 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);
+ let launcher = Zotero.Prefs.get(pref);
+ this.launchFileWithApplication(file.path, launcher);
}
catch (e) {
Zotero.debug(e);
@@ -1142,7 +1129,21 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
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]);
+ };
/**
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -4199,6 +4199,21 @@ var ZoteroPane = new function()
}
else {
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);
}
}
diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js
@@ -184,6 +184,9 @@ pref("extensions.zotero.ingester.allowedSites", "");
pref("extensions.zotero.connector.repo.lastCheck.localTime", 0);
pref("extensions.zotero.connector.repo.lastCheck.repoTime", 0);
+// Custom file handlers
+pref("extensions.zotero.fileHandler.pdf", "");
+
// File/URL opening executable if launch() fails
pref("extensions.zotero.fallbackLauncher.unix", "/usr/bin/xdg-open");
pref("extensions.zotero.fallbackLauncher.windows", "");