-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
49 lines (42 loc) · 1.59 KB
/
background.js
File metadata and controls
49 lines (42 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { browserAPI } from './shared/browser-api.js';
import { DEBUG_MODE } from './shared/logger.js';
import {
initializePlatform,
loadCustomColors,
createOrUpdateContextMenus,
applySettingsFromSync,
} from './background/settings-service.js';
import { initContextMenus } from './background/context-menu.js';
import { registerMessageRouter } from './background/message-router.js';
import { initSyncListener, migrateLocalToSync } from './background/sync-service.js';
// ===================================================================
// Top-level listener registration
// Service worker may restart at any time; listeners must be registered
// synchronously at the top level to avoid event loss on restart.
// ===================================================================
registerMessageRouter();
initContextMenus();
initSyncListener({
onSettingsChanged: async (newSettings) => {
const { colorsChanged } = await applySettingsFromSync(newSettings);
if (colorsChanged) {
await createOrUpdateContextMenus();
}
},
});
browserAPI.runtime.onInstalled.addListener(async () => {
if (DEBUG_MODE) console.log('Extension installed/updated. Debug mode:', DEBUG_MODE);
});
// ===================================================================
// Async initialization
// ===================================================================
(async () => {
try {
await initializePlatform();
await loadCustomColors();
await createOrUpdateContextMenus();
await migrateLocalToSync();
} catch (e) {
console.error('Initialization error in background script', e);
}
})();