Skip to content

Commit bdb8177

Browse files
committed
switch to fetch for checking for the test file
getLocalFile intentionally doesn't cope with errors, so it was the wrong choice. This could have been causing real errors on the options page (as `loaded` wasn't being set to true), but I didn't observe any problems.
1 parent f48a41e commit bdb8177

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/common/options.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,25 @@ function onLoad() {
113113
// Hide the tests link if the page isn't available. It may be stripped out
114114
// of extension packages.
115115

116-
// Check if our test file exists.
117-
Utils.getLocalFile('./test/index.html', 'text', function(_, err) {
118-
// The test files aren't present, so hide the button.
119-
if (err) {
116+
// Check if our test file exists. Note that we can't use Utils.getLocalFile as it throws
117+
// an asynchronous error if the file isn't found.
118+
// TODO: When Utils.getLocalFile is changed to return a promise, use it here.
119+
fetch('./test/index.html')
120+
.then(response => {
121+
if (!response.ok) {
122+
// The test files aren't present, so hide the button.
123+
$('#tests-link').hide();
124+
}
125+
else {
126+
// When the file is absent, Firefox still gives a 200 status, but will throw an
127+
// error when the response is read.
128+
return response.text();
129+
}
130+
})
131+
.catch(err => {
120132
// The test files aren't present, so hide the button.
121133
$('#tests-link').hide();
122-
}
123-
});
134+
});
124135

125136
// Older Thunderbird may try to open this options page in a new ChromeWindow, and it
126137
// won't work. So in that case we need to tell the user how they can actually open the

src/common/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,10 @@ function getLocalURL(url) {
339339
// Makes an asynchrous XHR request for a local file (basically a thin wrapper).
340340
// `dataType` must be one of 'text', 'json', or 'base64'.
341341
// `callback` will be called with the response value, of a type depending on `dataType`.
342-
// Errors are no expected for local files, and will result in an exception being thrown asynchrously.
342+
// Errors are not expected for local files, and will result in an exception being thrown asynchrously.
343+
// TODO: Return a promise instead of using a callback. This will allow returning an error
344+
// properly, and then this can be used in options.js when checking for the existence of
345+
// the test file.
343346
function getLocalFile(url, dataType, callback) {
344347
fetch(url)
345348
.then(response => {

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "__MSG_app_name__",
4-
"version": "2.14.0",
4+
"version": "2.14.1",
55
"description": "__MSG_app_slogan__",
66
"homepage_url": "https://markdown-here.com",
77
"default_locale": "en",

0 commit comments

Comments
 (0)