Skip to content

Commit

Permalink
ref: use session storage for persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
mayan-000 committed Mar 6, 2024
1 parent 9c4901f commit 192ff8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ const extractChromeStorage = async (
): Promise<TablePersistentSettingsStoreContext['state']> => {
const tabId = chrome.devtools.inspectedWindow.tabId.toString();

const data = await chrome.storage.local.get();
const tableData = data?.[tabId];
const data = await chrome.storage.session.get();
const tableData = data?.[tabId + persistenceKey];
if (tableData) {
const persistenceData = tableData?.[persistenceKey];
if (persistenceData) {
return persistenceData;
}
return tableData;
}

return {} as TablePersistentSettingsStoreContext['state'];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ const updateChromeStorage = async (
}
const tabId = chrome.devtools.inspectedWindow.tabId.toString();

const data = await chrome.storage.local.get();
const data = await chrome.storage.session.get();

let tableData: TablePersistentSettingsStoreContext['state'] =
data?.[tabId]?.[TABLE_PERSISTENT_SETTINGS_STORE_KEY];
data?.[tabId + TABLE_PERSISTENT_SETTINGS_STORE_KEY];
let requiredData = tableData?.[persistenceKey];

if (requiredData) {
Expand All @@ -108,9 +108,9 @@ const updateChromeStorage = async (
requiredData = storageData;
}

if (!tableData && data[tabId]) {
data[tabId][TABLE_PERSISTENT_SETTINGS_STORE_KEY] = {};
tableData = data[tabId][TABLE_PERSISTENT_SETTINGS_STORE_KEY];
if (!tableData) {
data[tabId + TABLE_PERSISTENT_SETTINGS_STORE_KEY] = {};
tableData = data[tabId + TABLE_PERSISTENT_SETTINGS_STORE_KEY];
}

if (tableData && !tableData[persistenceKey]) {
Expand All @@ -120,7 +120,7 @@ const updateChromeStorage = async (
tableData[persistenceKey] = requiredData;
}

await chrome.storage.local.set(data);
await chrome.storage.session.set(data);

return tableData;
};
Expand Down

0 comments on commit 192ff8b

Please sign in to comment.