Fix zotero://open-pdf links on Windows if no handler is set in registry
This commit is contained in:
parent
c81ac1f642
commit
2a804d5d4a
2 changed files with 30 additions and 25 deletions
|
@ -56,6 +56,8 @@ Zotero.OpenPDF = {
|
||||||
}
|
}
|
||||||
else if (Zotero.isWin) {
|
else if (Zotero.isWin) {
|
||||||
handler = handler || this._getPDFHandlerWindows();
|
handler = handler || this._getPDFHandlerWindows();
|
||||||
|
if (handler) {
|
||||||
|
Zotero.debug("Handler is " + handler);
|
||||||
// Include flags to open the PDF on a given page in various apps
|
// 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
|
// Adobe Acrobat: http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf
|
||||||
|
@ -64,6 +66,10 @@ Zotero.OpenPDF = {
|
||||||
Zotero.Utilities.Internal.exec(handler, args);
|
Zotero.Utilities.Internal.exec(handler, args);
|
||||||
opened = true;
|
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')) {
|
||||||
this._openWithEvinceOrOkular(handler, path, page);
|
this._openWithEvinceOrOkular(handler, path, page);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
var command = wrk.readStringValue('').match(/^(?:".+?"|[^"]\S+)/);
|
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, '');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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();
|
|
||||||
// TODO: Open pane if closed (macOS)
|
|
||||||
if (zp) {
|
|
||||||
zp.viewAttachment([item.id]);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var opened = Zotero.OpenPDF.openToPage(path, page);
|
opened = await Zotero.OpenPDF.openToPage(path, page);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.logError(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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue