| 48 | declare const __THUNDERBIRD__: boolean; |
| 49 | |
| 50 | export class Extension { |
| 51 | private static autoState: AutomationState = ''; |
| 52 | private static wasEnabledOnLastCheck: boolean | null = null; |
| 53 | private static registeredContextMenus: boolean | null = null; |
| 54 | /** |
| 55 | * This value is used for two purposes: |
| 56 | * - to bypass Firefox bug |
| 57 | * - to filter out excessive Extension.onColorSchemeChange() invocations |
| 58 | */ |
| 59 | private static wasLastColorSchemeDark: boolean | null = null; |
| 60 | private static startBarrier: PromiseBarrier<void, void> | null = null; |
| 61 | private static stateManager: StateManager<ExtensionState> | null = null; |
| 62 | |
| 63 | private static readonly ALARM_NAME = 'auto-time-alarm'; |
| 64 | private static readonly LOCAL_STORAGE_KEY = 'Extension-state'; |
| 65 | |
| 66 | // Store system color theme |
| 67 | private static readonly SYSTEM_COLOR_LOCAL_STORAGE_KEY = 'system-color-state'; |
| 68 | private static systemColorStateManager: StateManager<SystemColorState>; |
| 69 | |
| 70 | // Record whether Extension.init() already ran since the last GB start |
| 71 | private static initialized = false; |
| 72 | |
| 73 | static isFirstLoad = false; |
| 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 |
nothing calls this directly
no test coverage detected