From 6b61cd12eeb2fe478a6fd290b63fb6a9ef0f9ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E7=9F=A5?= Date: Wed, 27 Dec 2023 22:47:39 +0800 Subject: [PATCH] fix: theme storage toggle failed in Content script example #338 (#339) --- src/pages/content/injected.ts | 2 +- src/shared/storages/exampleThemeStorage.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/content/injected.ts b/src/pages/content/injected.ts index f33e5fd9b..d5be6e636 100644 --- a/src/pages/content/injected.ts +++ b/src/pages/content/injected.ts @@ -2,7 +2,7 @@ import exampleThemeStorage from '@src/shared/storages/exampleThemeStorage'; async function toggleTheme() { console.log('initial theme', await exampleThemeStorage.get()); - exampleThemeStorage.toggle(); + await exampleThemeStorage.toggle(); console.log('toggled theme', await exampleThemeStorage.get()); } diff --git a/src/shared/storages/exampleThemeStorage.ts b/src/shared/storages/exampleThemeStorage.ts index fbf96f114..71aa3a6b6 100644 --- a/src/shared/storages/exampleThemeStorage.ts +++ b/src/shared/storages/exampleThemeStorage.ts @@ -14,8 +14,8 @@ const storage = createStorage('theme-storage-key', 'light', { const exampleThemeStorage: ThemeStorage = { ...storage, // TODO: extends your own methods - toggle: () => { - storage.set(currentTheme => { + toggle: async () => { + await storage.set(currentTheme => { return currentTheme === 'light' ? 'dark' : 'light'; }); },