Skip to content

Commit

Permalink
Try to prevent issues if chrome.storage.get unexpectedly returns unde…
Browse files Browse the repository at this point in the history
…fined
  • Loading branch information
mymindstorm committed Jun 26, 2024
1 parent 5e8df8e commit ab7e15e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class UserSettings {
? StorageLocation.Local
: storageLocation;
const storageData: UserSettingsData =
(await chrome.storage[location].get("UserSettings")).UserSettings || {};
(await chrome.storage[location].get("UserSettings"))?.UserSettings || {};
delete storageData[key];

UserSettings.items = storageData;
Expand All @@ -163,7 +163,7 @@ export class UserSettings {

private static async getStorageData(location: StorageLocation) {
const storageData: UserSettingsData =
(await chrome.storage[location].get("UserSettings")).UserSettings || {};
(await chrome.storage[location].get("UserSettings"))?.UserSettings || {};

return storageData;
}
Expand Down
6 changes: 4 additions & 2 deletions src/store/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,10 @@ export class Accounts implements Module {
newStorageLocation === StorageLocation.Sync
) {
const localData = await chrome.storage.local.get();
delete localData.UserSettings;
await chrome.storage.sync.set(localData);
if (localData?.UserSettings) {
delete localData.UserSettings;
await chrome.storage.sync.set(localData);
}
const syncData = await chrome.storage.sync.get();

// Double check if data was set
Expand Down

0 comments on commit ab7e15e

Please sign in to comment.