FileHandlers: Fall back when _getSystemHandler() fails
Continue to Zotero.launchFile() as intended. https://forums.zotero.org/discussion/113179/pdfs-will-not-open-in-system-reader-when-double-clicked
This commit is contained in:
parent
54b9ff6e8a
commit
63f54d3184
2 changed files with 45 additions and 9 deletions
|
@ -90,17 +90,19 @@ Zotero.FileHandlers = {
|
||||||
// If there are handlers for this platform and this reader type...
|
// If there are handlers for this platform and this reader type...
|
||||||
if (handlers) {
|
if (handlers) {
|
||||||
// First try to open with the custom handler
|
// First try to open with the custom handler
|
||||||
try {
|
if (handler) {
|
||||||
for (let [i, { name, open }] of handlers.entries()) {
|
try {
|
||||||
if (name.test(handler)) {
|
for (let [i, { name, open }] of handlers.entries()) {
|
||||||
Zotero.debug('Opening with handler ' + i);
|
if (name.test(handler)) {
|
||||||
await open(handler, { filePath: path, location, page });
|
Zotero.debug('Opening with handler ' + i);
|
||||||
return true;
|
await open(handler, { filePath: path, location, page });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (e) {
|
||||||
catch (e) {
|
Zotero.logError(e);
|
||||||
Zotero.logError(e);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, we don't have special handling for the custom
|
// If we get here, we don't have special handling for the custom
|
||||||
|
|
|
@ -109,5 +109,39 @@ describe("Zotero.FileHandlers", () => {
|
||||||
readerOpenSpy.restore();
|
readerOpenSpy.restore();
|
||||||
getSystemHandlerStub.restore();
|
getSystemHandlerStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should fall back when handler is set to system and we can't retrieve the system handler", async function () {
|
||||||
|
let pdf = await importFileAttachment('wonderland_short.pdf');
|
||||||
|
let wasRun = false;
|
||||||
|
let readerOpenSpy = sinon.spy(Zotero.Reader, 'open');
|
||||||
|
let launchFileStub = sinon.stub(Zotero, 'launchFile');
|
||||||
|
Zotero.FileHandlers._mockHandlers = {
|
||||||
|
pdf: [
|
||||||
|
{
|
||||||
|
name: new RegExp(''),
|
||||||
|
async open() {
|
||||||
|
wasRun = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set our custom handler to something nonexistent,
|
||||||
|
// and stub the system handler to something nonexistent as well
|
||||||
|
Zotero.Prefs.set('fileHandler.pdf', 'system');
|
||||||
|
let getSystemHandlerStub = sinon.stub(Zotero.FileHandlers, '_getSystemHandler');
|
||||||
|
getSystemHandlerStub.returns(false);
|
||||||
|
|
||||||
|
await Zotero.FileHandlers.open(pdf, { location: {} });
|
||||||
|
assert.isFalse(wasRun);
|
||||||
|
assert.isFalse(readerOpenSpy.called);
|
||||||
|
assert.isTrue(launchFileStub.called);
|
||||||
|
assert.notOk(Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID));
|
||||||
|
assert.isEmpty(Zotero.Reader.getWindowStates());
|
||||||
|
|
||||||
|
readerOpenSpy.restore();
|
||||||
|
launchFileStub.restore();
|
||||||
|
getSystemHandlerStub.restore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue