From ab7e15e9e43a6fbca78d4ee3319bfb256b8a2c93 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Tue, 25 Jun 2024 19:58:35 -0500 Subject: [PATCH] Try to prevent issues if chrome.storage.get unexpectedly returns undefined --- src/models/settings.ts | 4 ++-- src/store/Accounts.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/models/settings.ts b/src/models/settings.ts index ae793e76..f40cb2e1 100644 --- a/src/models/settings.ts +++ b/src/models/settings.ts @@ -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; @@ -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; } diff --git a/src/store/Accounts.ts b/src/store/Accounts.ts index 22c00b1a..2a6bd0bf 100644 --- a/src/store/Accounts.ts +++ b/src/store/Accounts.ts @@ -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