Skip to content

Commit cdbf83e

Browse files
Improve background performance.
1 parent 8796e55 commit cdbf83e

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

extension/changelog.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"changes": [
1313
{ "message": "Keep a consistent order within the sidebar information section.", "contributor": "DeKleineKobini" },
1414
{ "message": "Change some features to be compatible with older browsers again.", "contributor": "DeKleineKobini" },
15-
{ "message": "Update the hardcoded items which we use as fallback.", "contributor": "DeKleineKobini" }
15+
{ "message": "Update the hardcoded items which we use as fallback.", "contributor": "DeKleineKobini" },
16+
{ "message": "Improve background performance.", "contributor": "DeKleineKobini" }
1617
],
1718
"removed": []
1819
}

extension/scripts/background.js

+20-24
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,13 @@ let npcUpdater;
6363
// On browser update, extension update or extension (re)install
6464
chrome.runtime.onInstalled.addListener(async () => {
6565
await migrateDatabase(true);
66+
void checkUpdate();
6667

67-
await checkUpdate();
68-
69-
await chrome.alarms.clearAll();
70-
await chrome.alarms.create(ALARM_NAMES.CLEAR_CACHE, { periodInMinutes: 60 });
71-
await chrome.alarms.create(ALARM_NAMES.CLEAR_USAGE, { periodInMinutes: 60 * 24 });
72-
await chrome.alarms.create(ALARM_NAMES.DATA_UPDATE_AND_NOTIFICATIONS, { periodInMinutes: 0.52 });
73-
74-
notificationHistory = await ttStorage.get("notificationHistory");
75-
notifications = await ttStorage.get("notifications");
68+
chrome.alarms.clearAll().then(() => {
69+
void chrome.alarms.create(ALARM_NAMES.CLEAR_CACHE, { periodInMinutes: 60 });
70+
void chrome.alarms.create(ALARM_NAMES.CLEAR_USAGE, { periodInMinutes: 60 * 24 });
71+
void chrome.alarms.create(ALARM_NAMES.DATA_UPDATE_AND_NOTIFICATIONS, { periodInMinutes: 0.52 });
72+
});
7673

7774
// These are refresh tasks, not clearing.
7875
clearUsage();
@@ -81,15 +78,14 @@ chrome.runtime.onInstalled.addListener(async () => {
8178
// Initial call
8279
timedUpdates();
8380

84-
await showIconBars();
85-
storageListeners.settings.push(async () => {
86-
await showIconBars();
87-
});
81+
void showIconBars();
82+
storageListeners.settings.push(showIconBars);
8883
});
8984

9085
// When SW (re)starts
9186
chrome.runtime.onStartup.addListener(async () => {
9287
await migrateDatabase(false);
88+
void checkUpdate();
9389

9490
// These are refresh tasks, not clearing.
9591
clearUsage();
@@ -98,21 +94,21 @@ chrome.runtime.onStartup.addListener(async () => {
9894
// Initial call
9995
timedUpdates();
10096

101-
await showIconBars();
102-
storageListeners.settings.push(async () => {
103-
await showIconBars();
104-
});
97+
void showIconBars();
98+
storageListeners.settings.push(showIconBars);
10599
});
106100

107101
// Register updaters, if not registered.
108102
(async () => {
109-
const currentAlarms = await chrome.alarms.getAll();
110-
if (currentAlarms.length !== 3) {
111-
await chrome.alarms.clearAll();
112-
await chrome.alarms.create(ALARM_NAMES.CLEAR_CACHE, { periodInMinutes: 60 });
113-
await chrome.alarms.create(ALARM_NAMES.CLEAR_USAGE, { periodInMinutes: 60 * 24 });
114-
await chrome.alarms.create(ALARM_NAMES.DATA_UPDATE_AND_NOTIFICATIONS, { periodInMinutes: 0.52 });
115-
}
103+
chrome.alarms.getAll().then((currentAlarms) => {
104+
if (currentAlarms.length === 3) return;
105+
106+
chrome.alarms.clearAll().then(() => {
107+
void chrome.alarms.create(ALARM_NAMES.CLEAR_CACHE, { periodInMinutes: 60 });
108+
void chrome.alarms.create(ALARM_NAMES.CLEAR_USAGE, { periodInMinutes: 60 * 24 });
109+
void chrome.alarms.create(ALARM_NAMES.DATA_UPDATE_AND_NOTIFICATIONS, { periodInMinutes: 0.52 });
110+
});
111+
});
116112
})();
117113

118114
// On alarm triggered

0 commit comments

Comments
 (0)