Skip to content

Commit a9d5d46

Browse files
committed
fix: ensure the update loop can never end
1 parent d056f5a commit a9d5d46

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

scripts/background.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,21 @@ const updateBadge = (count) => {
2727

2828
const getNotifications = async (alarm) => {
2929
if(navigator.onLine) {
30-
const handler = manager.getClientById(alarm.name),
31-
update = await handler.check();
32-
if(update) {
33-
updateBadge(await manager.getCount());
30+
try {
31+
const handler = manager.getClientById(alarm.name),
32+
update = await handler.check();
33+
if(update) {
34+
updateBadge(await manager.getCount());
35+
}
36+
}
37+
catch(e) {
38+
console.error(e);
39+
}
40+
finally {
41+
browser.alarms.create(handler.STORE_PREFIX, {
42+
when: handler.getNextCheckTime()
43+
});
3444
}
35-
browser.alarms.create(handler.STORE_PREFIX, {
36-
when: handler.getNextCheckTime()
37-
});
3845
}
3946
else {
4047
window.addEventListener('online', () => getNotifications(alarm), {

scripts/github.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ class GitHub {
257257
ratelimitRemaining = Math.max(AVOID_INFINITY, parseInt(response.headers.get("X-RateLimit-Remaining"), 10));
258258
this.pollInterval = Math.max(
259259
pollInterval,
260-
Math.ceil((ratelimitReset - nowS) / ratelimitRemaining)
260+
Math.ceil((ratelimitReset - nowS) / ratelimitRemaining),
261+
MIN_POLL_INTEVAL
261262
);
262263

263264
const now = new Date();

scripts/handler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ClientHandler extends window.Storage {
7676
super(uri.hostname + client.id, area);
7777
this._prefix = uri.hostname;
7878
this.client = client;
79+
this.pollInterval = 60;
7980
}
8081

8182
get STORE_PREFIX() {

0 commit comments

Comments
 (0)