diff --git a/src/app/commands.rs b/src/app/commands.rs index 32c4409..457f76a 100644 --- a/src/app/commands.rs +++ b/src/app/commands.rs @@ -6,7 +6,7 @@ use crate::{ config::{get_config, save_config as save_config_file, AppSettings}, }; use serde::{Deserialize, Serialize}; -use tauri::State; +use tauri::{Emitter, State}; use tracing::{error, info}; use super::state::{AppState, AppTheme}; @@ -156,9 +156,12 @@ pub fn get_theme(state: State<'_, AppState>) -> String { /// 设置主题 #[tauri::command] -pub fn set_theme(theme: String, state: State<'_, AppState>) { +pub fn set_theme(theme: String, state: State<'_, AppState>, app: tauri::AppHandle) { let app_theme = AppTheme::from_str(&theme); state.set_theme(app_theme); + + // 通知前端主题已变更 + let _ = app.emit("theme-change", theme); } /// 选择模型文件 diff --git a/web/src/pages/SettingsPage.tsx b/web/src/pages/SettingsPage.tsx index 33b83e5..6a0e1c2 100644 --- a/web/src/pages/SettingsPage.tsx +++ b/web/src/pages/SettingsPage.tsx @@ -78,13 +78,15 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps const handleSelectModel = async () => { try { - const modelPath = await window.__TAURI__.invoke('select_model_file') as string + const modelPath = await window.__TAURI__.invoke('select_model_file') if (modelPath) { - setSettings(prev => ({ ...prev, modelPath: modelPath })) + const path = modelPath as string + setSettings(prev => ({ ...prev, modelPath: path })) setModified(true) } } catch (e) { console.error('选择模型文件失败:', e) + alert('选择模型文件失败,请重试') } } @@ -125,7 +127,6 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps className="input" style={{ flex: 1, marginRight: '8px' }} value={settings.modelPath || ''} - onChange={(e) => handleChange('modelPath', e.target.value)} placeholder="选择自定义模型文件..." readOnly /> @@ -239,19 +240,19 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps className={`theme-btn ${theme === 'light' ? 'active' : ''}`} onClick={() => onThemeChange('light')} > - ☀️ 浅色 + 浅色