()
| 74 | |
| 75 | // This sync initializer needs to run on every BG restart before anything else can happen |
| 76 | private static init() { |
| 77 | if (Extension.initialized) { |
| 78 | return; |
| 79 | } |
| 80 | Extension.initialized = true; |
| 81 | |
| 82 | Messenger.init(Extension.getMessengerAdapter()); |
| 83 | TabManager.init({ |
| 84 | getConnectionMessage: Extension.getConnectionMessage, |
| 85 | getTabMessage: Extension.getTabMessage, |
| 86 | onColorSchemeChange: Extension.onColorSchemeChange, |
| 87 | }); |
| 88 | |
| 89 | Extension.startBarrier = new PromiseBarrier(); |
| 90 | Extension.stateManager = new StateManager<ExtensionState>(Extension.LOCAL_STORAGE_KEY, Extension, { |
| 91 | autoState: '', |
| 92 | wasEnabledOnLastCheck: null, |
| 93 | registeredContextMenus: null, |
| 94 | }, logWarn); |
| 95 | |
| 96 | chrome.alarms.onAlarm.addListener(Extension.alarmListener); |
| 97 | |
| 98 | if (chrome.commands) { |
| 99 | // Firefox Android does not support chrome.commands |
| 100 | if (isFirefox) { |
| 101 | // Firefox may not register onCommand listener on extension startup so we need to use setTimeout |
| 102 | setTimeout(() => chrome.commands.onCommand.addListener(async (command) => Extension.onCommand(command as Command, null, null, null))); |
| 103 | } else { |
| 104 | chrome.commands.onCommand.addListener(async (command, tab) => Extension.onCommand(command as Command, tab && tab.id! || null, 0, null)); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if (chrome.permissions.onRemoved) { |
| 109 | chrome.permissions.onRemoved.addListener((permissions) => { |
| 110 | // As far as we know, this code is never actually run because there |
| 111 | // is no browser UI for removing 'contextMenus' permission. |
| 112 | // This code exists for future-proofing in case browsers ever add such UI. |
| 113 | if (!permissions?.permissions?.includes('contextMenus')) { |
| 114 | Extension.registeredContextMenus = false; |
| 115 | } |
| 116 | }); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | private static async MV3syncSystemColorStateManager(isDark: boolean | null): Promise<void> { |
| 121 | if (!__CHROMIUM_MV3__) { |
no test coverage detected