()
| 59 | |
| 60 | // Loads the index from session storage. |
| 61 | async loadFromStorage() { |
| 62 | const tabsPromise = chrome.tabs.query({}); |
| 63 | const storagePromise = chrome.storage.session.get("tabRecency"); |
| 64 | const [tabs, storage] = await Promise.all([tabsPromise, storagePromise]); |
| 65 | if (storage.tabRecency == null) return; |
| 66 | |
| 67 | let maxCounter = 0; |
| 68 | for (const counter of Object.values(storage.tabRecency)) { |
| 69 | if (maxCounter < counter) maxCounter = counter; |
| 70 | } |
| 71 | if (this.counter < maxCounter) { |
| 72 | this.counter = maxCounter; |
| 73 | } |
| 74 | |
| 75 | this.tabIdToCounter = Object.assign({}, storage.tabRecency); |
| 76 | |
| 77 | // Remove any tab IDs which aren't currently loaded. |
| 78 | const tabIds = new Set(tabs.map((t) => t.id)); |
| 79 | for (const id in this.tabIdToCounter) { |
| 80 | if (!tabIds.has(parseInt(id))) { |
| 81 | delete this.tabIdToCounter[id]; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | async saveToStorage() { |
| 87 | await chrome.storage.session.set({ tabRecency: this.tabIdToCounter }); |
no test coverage detected