Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to prevent issues if chrome.storage.get unexpectedly returns undefined #1216

Merged
merged 4 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run-tests:
runs-on: ubuntu-latest
name: Run tests
needs: [ build ]
needs: [build]

steps:
- uses: actions/checkout@v2
Expand All @@ -53,9 +53,9 @@ jobs:
- name: Install dependencies
run: npm ci
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 'true'
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true"

- name: Test code
uses: mujo-code/puppeteer-headful@master
uses: mymindstorm/puppeteer-headful@8f745c770f7f4c0f9f332d7c43a775f90e53779a
with:
args: npm test
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
Loading