From b03ac2ab0b6469aa70aab8f6c1cffdf41619f5bc Mon Sep 17 00:00:00 2001 From: impressionyang Date: Thu, 21 May 2026 19:47:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=92=8C=E6=A8=A1=E5=9E=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端变更: - src/app/commands.rs: 导入 Emitter trait - src/app/commands.rs: set_theme 命令添加 emit 发送 theme-change 事件 - src/app/commands.rs: select_model_file 改进错误处理和消息提示 前端变更: - web/src/pages/SettingsPage.tsx: 移除模型路径输入框的 onChange (与 readOnly 冲突) - web/src/pages/SettingsPage.tsx: handleSelectModel 添加用户友好的错误提示 - web/src/pages/SettingsPage.tsx: 移除主题按钮的 emoji 图标 修复问题: 1. 主题设置不生效 - set_theme 命令现在发送 theme-change 事件通知前端 2. 模型文件不能选择 - 移除 onChange 冲突,改进错误处理 构建结果: - Windows 包:dist/impress-asr-windows-x64-20260521_194309.zip - 文件大小:5.0MB --- src/app/commands.rs | 7 +++++-- web/src/pages/SettingsPage.tsx | 13 +++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) 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')} > - ☀️ 浅色 + 浅色