diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 054f26aa8..5381a5cbc 100644 --- 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 index 85e50d19b..e814727cf 100644 --- 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 index 5ef864c97..b6075b819 100644 --- 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", "");