fix: timeout waiting for invokeMethod clientStorage

This commit is contained in:
ihmily
2025-05-21 12:48:46 +08:00
parent 1625b3ad1a
commit 1944f7faad

View File

@@ -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