Fix zotero://open-pdf links on Windows if no handler is set in registry

This commit is contained in:
Dan Stillman 2020-02-09 14:03:47 -05:00
parent c81ac1f642
commit 2a804d5d4a
2 changed files with 30 additions and 25 deletions

View file

@ -56,13 +56,19 @@ Zotero.OpenPDF = {
} }
else if (Zotero.isWin) { else if (Zotero.isWin) {
handler = handler || this._getPDFHandlerWindows(); handler = handler || this._getPDFHandlerWindows();
// Include flags to open the PDF on a given page in various apps if (handler) {
// Zotero.debug("Handler is " + handler);
// Adobe Acrobat: http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf // Include flags to open the PDF on a given page in various apps
// PDF-XChange: http://help.tracker-software.com/eu/default.aspx?pageid=PDFXView25:command_line_options //
let args = ['/A', 'page=' + page, path]; // Adobe Acrobat: http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf
Zotero.Utilities.Internal.exec(handler, args); // PDF-XChange: http://help.tracker-software.com/eu/default.aspx?pageid=PDFXView25:command_line_options
opened = true; let args = ['/A', 'page=' + page, path];
Zotero.Utilities.Internal.exec(handler, args);
opened = true;
}
else {
Zotero.debug("No handler found");
}
} }
else if (Zotero.isLinux) { else if (Zotero.isLinux) {
if (handler.includes('evince') || handler.includes('okular')) { if (handler.includes('evince') || handler.includes('okular')) {
@ -176,10 +182,11 @@ Zotero.OpenPDF = {
// //
/** /**
* Get path to default pdf reader application on windows * Get path to default pdf reader application on windows
* @return {string} Path to default pdf reader application
* *
* From getPDFReader() in ZotFile (GPL) * From getPDFReader() in ZotFile (GPL)
* https://github.com/jlegewie/zotfile/blob/master/chrome/content/zotfile/utils.js * https://github.com/jlegewie/zotfile/blob/master/chrome/content/zotfile/utils.js
*
* @return {String|false} - Path to default pdf reader application, or false if none
*/ */
_getPDFHandlerWindows: function () { _getPDFHandlerWindows: function () {
var wrk = Components.classes["@mozilla.org/windows-registry-key;1"] var wrk = Components.classes["@mozilla.org/windows-registry-key;1"]
@ -212,7 +219,7 @@ Zotero.OpenPDF = {
if (!progId) { if (!progId) {
wrk.close(); wrk.close();
return; return false;
} }
// Get version specific handler, if it exists // Get version specific handler, if it exists
@ -246,14 +253,17 @@ Zotero.OpenPDF = {
if (!success) { if (!success) {
wrk.close(); wrk.close();
return; return false;
} }
var command = wrk.readStringValue('').match(/^(?:".+?"|[^"]\S+)/); try {
var command = wrk.readStringValue('').match(/^(?:".+?"|[^"]\S+)/);
}
catch (e) {}
wrk.close(); wrk.close();
if (!command) return; if (!command) return false;
return command[0].replace(/"/g, ''); return command[0].replace(/"/g, '');
}, },

View file

@ -1036,24 +1036,19 @@ function ZoteroProtocolHandler() {
return; return;
} }
// If no page number, just open normally var opened = false;
if (!page) { if (page) {
let zp = Zotero.getActiveZoteroPane(); try {
// TODO: Open pane if closed (macOS) opened = await Zotero.OpenPDF.openToPage(path, page);
if (zp) { }
zp.viewAttachment([item.id]); catch (e) {
Zotero.logError(e);
} }
return;
} }
try {
var opened = Zotero.OpenPDF.openToPage(path, page);
}
catch (e) {
Zotero.logError(e);
}
// If something went wrong, just open PDF without page // If something went wrong, just open PDF without page
if (!opened) { if (!opened) {
Zotero.debug("Launching PDF without page number");
let zp = Zotero.getActiveZoteroPane(); let zp = Zotero.getActiveZoteroPane();
// TODO: Open pane if closed (macOS) // TODO: Open pane if closed (macOS)
if (zp) { if (zp) {