From 1944f7faadc7c17ab48a2ad7fb37d8a06010d82b Mon Sep 17 00:00:00 2001 From: ihmily <114978440+ihmily@users.noreply.github.com> Date: Wed, 21 May 2025 12:48:46 +0800 Subject: [PATCH] fix: timeout waiting for invokeMethod clientStorage --- app/ui/themes/theme_manager.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/ui/themes/theme_manager.py b/app/ui/themes/theme_manager.py index b23c0fa..cfea71a 100644 --- a/app/ui/themes/theme_manager.py +++ b/app/ui/themes/theme_manager.py @@ -9,9 +9,10 @@ class ThemeManager: def __init__(self, app): self.page = app.page self.custom_font = None + self.theme_color = None self.assets_dir = app.assets_dir self.init_fonts() - self.apply_initial_theme() + self.page.run_task(self.apply_initial_theme) def init_fonts(self): """Initialize fonts for the application.""" @@ -25,20 +26,25 @@ class ThemeManager: } self.custom_font = custom_font - def apply_initial_theme(self): + async def apply_initial_theme(self): """Apply initial theme based on saved settings or default to light theme.""" self.page.theme = create_light_theme(self.custom_font) self.page.dark_theme = create_dark_theme(self.custom_font) + try: + self.theme_color = await self.page.client_storage.get_async("theme_color") + if self.theme_color is not None: + await self.update_theme_color(self.theme_color) + return + except Exception: + pass + await self.update_theme_color("blue") - theme_color = self.page.client_storage.get("theme_color") - if theme_color is not None: - self.update_theme_color(theme_color) - else: - self.update_theme_color("blue") - - def update_theme_color(self, color): + async def update_theme_color(self, color): """Update the current theme color scheme and save it.""" self.page.theme.color_scheme_seed = color self.page.theme.color_scheme = ft.ColorScheme(primary=color) self.page.update() - self.page.client_storage.set("theme_color", color) + try: + await self.page.client_storage.set_async("theme_color", color) + except Exception: + pass