MCPcopy
hub / github.com/philc/vimium / loadFromStorage

Method loadFromStorage

background_scripts/tab_recency.js:61–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 });

Callers 2

initMethod · 0.95

Calls 2

getMethod · 0.80
hasMethod · 0.80

Tested by

no test coverage detected