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,6 +90,7 @@ 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
|
||||||
|
if (handler) {
|
||||||
try {
|
try {
|
||||||
for (let [i, { name, open }] of handlers.entries()) {
|
for (let [i, { name, open }] of handlers.entries()) {
|
||||||
if (name.test(handler)) {
|
if (name.test(handler)) {
|
||||||
|
@ -102,6 +103,7 @@ Zotero.FileHandlers = {
|
||||||
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
|
||||||
// handler that the user has set. If we have a location, we really
|
// handler that the user has set. If we have a location, we really
|
||||||
|
|
|
@ -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