fix: 修复重启后主题不能保持的问题

This commit is contained in:
NanGua-QWQ
2026-03-24 18:37:41 +08:00
parent 271cf1b00a
commit 03e0c59692
+17 -2
View File
@@ -6,7 +6,7 @@ use tauri::AppHandle;
use crate::services::{ use crate::services::{
auth::AuthService, auto_score::AutoScoreService, data::DataService, logger::LoggerService, auth::AuthService, auto_score::AutoScoreService, data::DataService, logger::LoggerService,
permission::PermissionService, security::SecurityService, settings::SettingsService, permission::PermissionService, security::SecurityService, settings::SettingsService,
theme::ThemeService, theme::ThemeService, SettingsKey, SettingsValue,
}; };
pub struct AppState { pub struct AppState {
@@ -51,7 +51,22 @@ impl AppState {
pub async fn initialize(&self) -> Result<(), Box<dyn std::error::Error>> { pub async fn initialize(&self) -> Result<(), Box<dyn std::error::Error>> {
self.settings.write().initialize().await?; self.settings.write().initialize().await?;
self.logger.write().initialize(&self.app_handle).await?; self.logger.write().initialize(&self.app_handle).await?;
self.theme.write().initialize(&self.app_handle).await?;
{
let settings = self.settings.read();
let current_theme_id = match settings.get_value(SettingsKey::CurrentThemeId) {
SettingsValue::String(s) => s,
_ => "light-default".to_string(),
};
let themes_custom = match settings.get_value(SettingsKey::ThemesCustom) {
SettingsValue::Json(j) => j,
_ => serde_json::Value::Array(vec![]),
};
let mut theme = self.theme.write();
theme.load_custom_themes(themes_custom);
theme.load_saved_theme(&current_theme_id);
}
self.auto_score.write().initialize(&self.app_handle).await?; self.auto_score.write().initialize(&self.app_handle).await?;
Ok(()) Ok(())
} }