fix: 修复主题设置和模型文件选择功能
Some checks are pending
Build Windows GUI / build-windows (push) Waiting to run
Build Windows GUI / release (push) Blocked by required conditions

后端变更:
- 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
This commit is contained in:
impressionyang 2026-05-21 19:47:38 +08:00
parent 6f4a7dafd4
commit b03ac2ab0b
2 changed files with 12 additions and 8 deletions

View File

@ -6,7 +6,7 @@ use crate::{
config::{get_config, save_config as save_config_file, AppSettings}, config::{get_config, save_config as save_config_file, AppSettings},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tauri::State; use tauri::{Emitter, State};
use tracing::{error, info}; use tracing::{error, info};
use super::state::{AppState, AppTheme}; use super::state::{AppState, AppTheme};
@ -156,9 +156,12 @@ pub fn get_theme(state: State<'_, AppState>) -> String {
/// 设置主题 /// 设置主题
#[tauri::command] #[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); let app_theme = AppTheme::from_str(&theme);
state.set_theme(app_theme); state.set_theme(app_theme);
// 通知前端主题已变更
let _ = app.emit("theme-change", theme);
} }
/// 选择模型文件 /// 选择模型文件

View File

@ -78,13 +78,15 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps
const handleSelectModel = async () => { const handleSelectModel = async () => {
try { try {
const modelPath = await window.__TAURI__.invoke('select_model_file') as string const modelPath = await window.__TAURI__.invoke('select_model_file')
if (modelPath) { if (modelPath) {
setSettings(prev => ({ ...prev, modelPath: modelPath })) const path = modelPath as string
setSettings(prev => ({ ...prev, modelPath: path }))
setModified(true) setModified(true)
} }
} catch (e) { } catch (e) {
console.error('选择模型文件失败:', e) console.error('选择模型文件失败:', e)
alert('选择模型文件失败,请重试')
} }
} }
@ -125,7 +127,6 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps
className="input" className="input"
style={{ flex: 1, marginRight: '8px' }} style={{ flex: 1, marginRight: '8px' }}
value={settings.modelPath || ''} value={settings.modelPath || ''}
onChange={(e) => handleChange('modelPath', e.target.value)}
placeholder="选择自定义模型文件..." placeholder="选择自定义模型文件..."
readOnly readOnly
/> />
@ -239,19 +240,19 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps
className={`theme-btn ${theme === 'light' ? 'active' : ''}`} className={`theme-btn ${theme === 'light' ? 'active' : ''}`}
onClick={() => onThemeChange('light')} onClick={() => onThemeChange('light')}
> >
</button> </button>
<button <button
className={`theme-btn ${theme === 'dark' ? 'active' : ''}`} className={`theme-btn ${theme === 'dark' ? 'active' : ''}`}
onClick={() => onThemeChange('dark')} onClick={() => onThemeChange('dark')}
> >
🌙
</button> </button>
<button <button
className={`theme-btn ${theme === 'system' ? 'active' : ''}`} className={`theme-btn ${theme === 'system' ? 'active' : ''}`}
onClick={() => onThemeChange('system')} onClick={() => onThemeChange('system')}
> >
💻
</button> </button>
</div> </div>
</div> </div>