Skip to content

Commit cb66577

Browse files
committed
onInstalled and onStartup run late
1 parent 7281e0a commit cb66577

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/background/icon-manager.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {kDisableAll, kInstall} from '/js/consts';
1+
import {kDisableAll} from '/js/consts';
22
import {subscribe, __values as __prefs} from '/js/prefs';
33
import {CHROME, FIREFOX, MOBILE, VIVALDI} from '/js/ua';
44
import {debounce} from '/js/util';
55
import {ignoreChromeError, MF_ICON_EXT, MF_ICON_PATH} from '/js/util-webext';
66
import * as colorScheme from './color-scheme';
7-
import {bgBusy, bgPreInit} from './common';
7+
import {bgBusy, bgInit} from './common';
88
import {removePreloadedStyles} from './style-via-webrequest';
99
import * as tabMan from './tab-manager';
1010

@@ -27,9 +27,17 @@ const kShowBadge = 'show-badge';
2727
// https://github.com/openstyles/stylus/issues/335
2828
let hasCanvas = FIREFOX_ANDROID ? false : null;
2929

30+
bgInit.push(initIcons);
3031

31-
bgBusy.then(() => {
32-
const runNow = !__.MV3 || bgPreInit.includes(kInstall);
32+
export async function refreshIconsWhenReady() {
33+
if (bgBusy) {
34+
bgInit[bgInit.indexOf(initIcons)] = 0;
35+
await bgBusy;
36+
}
37+
initIcons(true);
38+
}
39+
40+
function initIcons(runNow = !__.MV3) {
3341
colorScheme.onChange(() => {
3442
if (__prefs[kIconset] === -1) {
3543
debounce(refreshGlobalIcon);
@@ -47,7 +55,7 @@ bgBusy.then(() => {
4755
kDisableAll,
4856
kIconset,
4957
], () => debounce(refreshAllIcons), runNow);
50-
});
58+
}
5159

5260
tabMan.onUnload.add((tabId, frameId, port) => {
5361
if (frameId && tabMan.getStyleIds(tabId)) {

src/background/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {bgBusy, bgInit, bgPreInit, stateDB} from './common';
1515
import reinjectContentScripts from './content-scripts';
1616
import initContextMenus from './context-menus';
1717
import download from './download';
18-
import {updateIconBadge} from './icon-manager';
18+
import {refreshIconsWhenReady, updateIconBadge} from './icon-manager';
1919
import prefsApi from './prefs-api';
2020
import setClientData from './set-client-data';
2121
import * as styleMan from './style-manager';
@@ -103,11 +103,15 @@ chrome.runtime.onInstalled.addListener(({reason, previousVersion}) => {
103103
stateDB.clear(),
104104
DNR.getDynamicRules().then(rules => updateDynamicRules(undefined, getRuleIds(rules))),
105105
DNR.getSessionRules().then(rules => updateSessionRules(undefined, getRuleIds(rules))),
106-
kInstall,
107106
);
107+
refreshIconsWhenReady();
108108
}
109109
});
110110

111+
if (__.MV3) {
112+
chrome.runtime.onStartup.addListener(refreshIconsWhenReady);
113+
}
114+
111115
onMessage(async (m, sender) => {
112116
if (m.method === 'invokeAPI') {
113117
if (bgBusy) await bgBusy;

0 commit comments

Comments
 (0)