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

View file

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