()
| 19 | |
| 20 | // Add listeners to chrome.tabs, and load the index from session storage. |
| 21 | async init() { |
| 22 | if (this.initPromise) { |
| 23 | await this.initPromise; |
| 24 | return; |
| 25 | } |
| 26 | let resolveFn; |
| 27 | this.initPromise = new Promise((resolve, _reject) => { |
| 28 | resolveFn = resolve; |
| 29 | }); |
| 30 | |
| 31 | chrome.tabs.onActivated.addListener((activeInfo) => { |
| 32 | this.queueAction("register", activeInfo.tabId); |
| 33 | }); |
| 34 | chrome.tabs.onRemoved.addListener((tabId) => { |
| 35 | this.queueAction("deregister", tabId); |
| 36 | }); |
| 37 | |
| 38 | chrome.tabs.onReplaced.addListener((addedTabId, removedTabId) => { |
| 39 | this.queueAction("deregister", removedTabId); |
| 40 | this.queueAction("register", addedTabId); |
| 41 | }); |
| 42 | |
| 43 | chrome.windows.onFocusChanged.addListener(async (windowId) => { |
| 44 | if (windowId == chrome.windows.WINDOW_ID_NONE) return; |
| 45 | const tabs = await chrome.tabs.query({ windowId, active: true }); |
| 46 | if (tabs[0]) { |
| 47 | this.queueAction("register", tabs[0].id); |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | await this.loadFromStorage(); |
| 52 | while (this.queuedActions.length > 0) { |
| 53 | const [action, tabId] = this.queuedActions.shift(); |
| 54 | this.handleAction(action, tabId); |
| 55 | } |
| 56 | this.loaded = true; |
| 57 | resolveFn(); |
| 58 | } |
| 59 | |
| 60 | // Loads the index from session storage. |
| 61 | async loadFromStorage() { |
no test coverage detected