Skip to content

Commit aef4672

Browse files
committed
Obey the X-PollInterval header
1 parent bf71849 commit aef4672

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

background.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(function () {
2-
let lastNotificationCount = 0;
2+
let lastNotificationCount = 0,
3+
responsePollInterval = 30;
34

45
async function update() {
56
let options,
@@ -21,6 +22,10 @@
2122
cache: 'reload'
2223
});
2324

25+
responsePollInterval = response.headers.get('X-Poll-Interval') || responsePollInterval;
26+
27+
setTimeout(update, 1000 * responsePollInterval);
28+
2429
if (!response.ok) {
2530
throw new Error(response.statusText);
2631
}
@@ -32,6 +37,8 @@
3237
});
3338
browser.browserAction.disable();
3439

40+
setTimeout(update, 1000 * responsePollInterval);
41+
3542
return;
3643
}
3744

@@ -88,8 +95,6 @@
8895
});
8996
}
9097

91-
setInterval(update, 1000 * 60);
92-
9398
browser.browserAction.onClicked.addListener((e) => {
9499
const notificationsUrl = 'https://github.com/notifications';
95100

@@ -114,4 +119,6 @@
114119
});
115120
});
116121
});
122+
123+
update();
117124
})();

0 commit comments

Comments
 (0)