Skip to content

Commit c98c018

Browse files
committed
chore: update linting preset
1 parent 4b866df commit c98c018

File tree

8 files changed

+1161
-708
lines changed

8 files changed

+1161
-708
lines changed

package-lock.json

Lines changed: 1054 additions & 614 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
],
3333
"homepage": "https://github.com/freaktechnik/advanced-github-notifier#readme",
3434
"devDependencies": {
35-
"@freaktechnik/eslint-config-base": "^9.0.2",
36-
"@freaktechnik/eslint-config-extension": "^9.0.1",
37-
"@freaktechnik/eslint-config-node": "^9.0.3",
38-
"@freaktechnik/eslint-config-test": "^9.0.1",
35+
"@freaktechnik/eslint-config-base": "^9.1.1",
36+
"@freaktechnik/eslint-config-extension": "^9.1.1",
37+
"@freaktechnik/eslint-config-node": "^9.1.1",
38+
"@freaktechnik/eslint-config-test": "^9.1.1",
3939
"ava": "^5.2.0",
4040
"eclint": "^2.8.1",
4141
"eslint": "^8.39.0",

scripts/background.js

Lines changed: 71 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -117,52 +117,60 @@ const createHandler = async (type, details) => {
117117
}
118118
};
119119

120-
browser.runtime.onMessage.addListener((message) => {
120+
/**
121+
* A runtime.onMessage handler that runs asynchronously, without sending a response.
122+
*
123+
* @param {any} message - Message from another part of the extension.
124+
* @returns {undefined}
125+
*/
126+
const handleMessage = async (message) => {
121127
switch(message.topic) {
122128
case "open-notification":
123-
openNotification(message.notificationId).catch((error) => console.error(error));
129+
await openNotification(message.notificationId);
124130
break;
125-
case "open-notifications":
126-
browser.storage.local.get({
131+
case "open-notifications": {
132+
const { footer } = await browser.storage.local.get({
127133
"footer": "all"
128-
})
129-
.then(({ footer }) => {
130-
if(footer == "options") {
131-
return browser.runtime.openOptionsPage();
132-
}
133-
else if(footer in GitHub.FOOTER_URLS) {
134-
return browser.tabs.create({ url: GitHub.FOOTER_URLS[footer] });
135-
}
136-
throw new Error(`No matching footer action implemented for '${footer}'`);
137-
})
138-
.catch(console.error);
139-
break;
134+
});
135+
if(footer == "options") {
136+
await browser.runtime.openOptionsPage();
137+
break;
138+
}
139+
else if(footer in GitHub.FOOTER_URLS) {
140+
await browser.tabs.create({ url: GitHub.FOOTER_URLS[footer] });
141+
break;
142+
}
143+
throw new Error(`No matching footer action implemented for '${footer}'`);
144+
}
140145
case "mark-all-read":
141-
Promise.all(Array.from(manager.getClients(), (handler) => handler.markAsRead()))
142-
.then(() => updateBadge(''))
143-
.catch((error) => console.error(error));
146+
await Promise.all(Array.from(manager.getClients(), (handler) => handler.markAsRead()));
147+
await updateBadge('');
144148
break;
145149
case "mark-notification-read": {
146150
const handler = manager.getClientForNotificationID(message.notificationId);
147-
handler.markAsRead(message.notificationId)
148-
.then(() => manager.getCount())
149-
.then(updateBadge)
150-
.catch((error) => console.error(error));
151+
await handler.markAsRead(message.notificationId);
152+
const count = await manager.getCount();
153+
await updateBadge(count);
151154
break;
152155
}
153156
case "unsubscribe-notification": {
154157
const handler = manager.getClientForNotificationID(message.notificationId);
155-
handler.unsubscribeNotification(message.notificationId).catch(console.error);
158+
await handler.unsubscribeNotification(message.notificationId);
156159
break;
157160
}
158161
case "ignore-notification": {
159162
const handler = manager.getClientForNotificationID(message.notificationId);
160-
handler.ignoreNotification(message.notificationId).catch(console.error);
163+
await handler.ignoreNotification(message.notificationId);
161164
break;
162165
}
163166
case "logout": {
164167
const handler = manager.getClientById(message.handlerId);
165-
handler.logout(true).catch(console.error);
168+
try {
169+
await handler.logout(true);
170+
}
171+
catch(error) {
172+
console.error(error);
173+
}
166174
manager.removeClient(handler);
167175
if(!manager.clients.size) {
168176
needsAuth();
@@ -173,6 +181,30 @@ browser.runtime.onMessage.addListener((message) => {
173181
return createHandler(message.type, message.details);
174182
default:
175183
}
184+
};
185+
186+
const handleStorageChange = async (changes) => {
187+
await browser.menus.update('badge', {
188+
type: 'checkbox',
189+
checked: !changes.disableBadge.newValue
190+
});
191+
const [
192+
currentText,
193+
count
194+
] = await Promise.all([
195+
browser.browserAction.getBadgeText({}),
196+
manager.getCount()
197+
]);
198+
if(currentText === MISSING_AUTH) {
199+
await updateBadge();
200+
}
201+
else {
202+
await updateBadge(count);
203+
}
204+
};
205+
206+
browser.runtime.onMessage.addListener((message) => {
207+
handleMessage(message).catch(console.error);
176208
});
177209

178210
browser.runtime.onInstalled.addListener(async (details) => {
@@ -195,25 +227,12 @@ browser.runtime.onInstalled.addListener(async (details) => {
195227
const init = async () => {
196228
browser.storage.onChanged.addListener((changes, area) => {
197229
if(area === 'local' && changes.disableBadge) {
198-
browser.menus.update('badge', {
199-
type: 'checkbox',
200-
checked: !changes.disableBadge.newValue
201-
})
202-
.catch(console.error);
203-
Promise.all([
204-
browser.browserAction.getBadgeText({}),
205-
manager.getCount()
206-
])
207-
.then(([
208-
currentText,
209-
count
210-
]) => {
211-
if(currentText === MISSING_AUTH) {
212-
return updateBadge();
213-
}
214-
return updateBadge(count);
215-
})
216-
.catch(console.error);
230+
try {
231+
handleStorageChange(changes);
232+
}
233+
catch(error) {
234+
console.error(error);
235+
}
217236
}
218237
});
219238
browser.menus.onClicked.addListener(({
@@ -226,11 +245,11 @@ const init = async () => {
226245
}
227246
});
228247
const count = await manager.getInstances();
229-
if(!count) {
230-
needsAuth();
248+
if(count) {
249+
await setupNotificationWorkers();
231250
}
232251
else {
233-
await setupNotificationWorkers();
252+
needsAuth();
234253
}
235254
};
236255

@@ -264,10 +283,7 @@ window.requestIdleCallback(async () => {
264283
'foo',
265284
'bar'
266285
]);
267-
if(!records.length) {
268-
needsAuth();
269-
}
270-
else {
286+
if(records.length) {
271287
window.addEventListener("online", () => {
272288
init().catch(console.error);
273289
}, {
@@ -276,5 +292,8 @@ window.requestIdleCallback(async () => {
276292
once: true
277293
});
278294
}
295+
else {
296+
needsAuth();
297+
}
279298
}
280299
});

scripts/gitea.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class Gitea {
179179
throw new Error("could not fetch comment details");
180180
}
181181
}
182-
catch(error) {
182+
catch{
183183
json.html_url = notification.subject.latest_comment_url; // eslint-disable-line camelcase, xss/no-mixed-html
184184
}
185185
}
@@ -199,7 +199,7 @@ class Gitea {
199199
throw new Error("could not fetch comment details");
200200
}
201201
}
202-
catch(error) {
202+
catch{
203203
fallbackUrl = notification.subject.latest_comment_url; // eslint-disable-line xss/no-mixed-html
204204
}
205205
}

scripts/github.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,14 @@ class GitHub {
138138
const {
139139
access_token: accessToken, scope
140140
} = await response.json();
141-
if(!scope.includes(this.scope)) {
142-
throw new Error("Was not granted required permissions");
143-
}
144-
else {
141+
if(scope.includes(this.scope)) {
145142
this.setToken(accessToken);
146143
await this.getUsername();
147144
return accessToken;
148145
}
146+
throw new Error("Was not granted required permissions");
149147
}
150-
else {
151-
throw response;
152-
}
148+
throw response;
153149
}
154150

155151
async getUsername() {
@@ -353,7 +349,7 @@ class GitHub {
353349
gotComment = true;
354350
}
355351
}
356-
catch(error) {
352+
catch{
357353
// Ignore error.
358354
}
359355
if(!gotComment && notification.subject.latest_comment_url) {
@@ -368,7 +364,7 @@ class GitHub {
368364
}
369365
}
370366
}
371-
catch(error) {
367+
catch{
372368
// Ignore error.
373369
}
374370
}

scripts/handler.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class ClientHandler extends window.Storage {
213213
await this.setValue(ClientHandler.TOKEN, token);
214214
await this.setValue(ClientHandler.USERNAME, this.client._username);
215215
}
216-
catch(error) {
216+
catch{
217217
throw new Error("Was not granted required permissions");
218218
}
219219
return true;
@@ -252,21 +252,15 @@ class ClientHandler extends window.Storage {
252252
await this.client.authorize(token);
253253
await this.setValue(ClientHandler.USERNAME, this.client._username);
254254
}
255-
catch(error) {
255+
catch{
256256
await this.logout();
257257
return false;
258258
}
259259
return true;
260260
}
261261

262262
async markAsRead(id, remote = true) {
263-
if(!id) {
264-
if(remote) {
265-
await this.client.markNotificationsRead();
266-
}
267-
await this.setValue(ClientHandler.NOTIFICATIONS, []);
268-
}
269-
else {
263+
if(id) {
270264
if(remote) {
271265
const githubID = this._getOriginalID(id);
272266
await this.client.markNotificationRead(githubID);
@@ -280,10 +274,16 @@ class ClientHandler extends window.Storage {
280274
try {
281275
await browser.notifications.clear(id);
282276
}
283-
catch(error) {
277+
catch{
284278
// Don't care about notification clear failing
285279
}
286280
}
281+
else {
282+
if(remote) {
283+
await this.client.markNotificationsRead();
284+
}
285+
await this.setValue(ClientHandler.NOTIFICATIONS, []);
286+
}
287287
}
288288

289289
async getNotificationURL(id) {
@@ -372,15 +372,15 @@ class ClientHandler extends window.Storage {
372372
const details = await this.client.getNotificationDetails(notification);
373373
notification.subjectDetails = details;
374374
}
375-
catch(error) {
375+
catch{
376376
notification.subjectDetails = ClientHandler.buildNotificationDetails(notification);
377377
}
378378
notification.normalizedType = ClientHandler.getNormalizedType(notification);
379379
notification.detailState = ClientHandler.getNotificationState(notification);
380380
notification.icon = ClientHandler.getNotificationIcon(notification);
381381
/* eslint-enable require-atomic-updates */
382382
}
383-
catch(error) {
383+
catch{
384384
return null;
385385
}
386386
}
@@ -416,7 +416,7 @@ ${typeMessage}${stateMessage}`;
416416
try {
417417
await browser.notifications.clear(existingNotification.id);
418418
}
419-
catch(error) {
419+
catch{
420420
// ignore clearing errors.
421421
}
422422
}

scripts/l10n.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* Large parts of the logic are very similar to the SDK implmentation.
44
* All you have to do to use this in a document is load it.
55
*
6-
* @author Martin Giger
76
* @license MPL-2.0
7+
* @author Martin Giger
88
*/
99

1010
function translateElementAttributes(element) {

0 commit comments

Comments
 (0)