fix: 修复主题设置和模型文件选择功能
后端变更: - 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:
parent
6f4a7dafd4
commit
b03ac2ab0b
@ -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);
|
||||
}
|
||||
|
||||
/// 选择模型文件
|
||||
|
||||
@ -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')}
|
||||
>
|
||||
☀️ 浅色
|
||||
浅色
|
||||
</button>
|
||||
<button
|
||||
className={`theme-btn ${theme === 'dark' ? 'active' : ''}`}
|
||||
onClick={() => onThemeChange('dark')}
|
||||
>
|
||||
🌙 深色
|
||||
深色
|
||||
</button>
|
||||
<button
|
||||
className={`theme-btn ${theme === 'system' ? 'active' : ''}`}
|
||||
onClick={() => onThemeChange('system')}
|
||||
>
|
||||
💻 跟随系统
|
||||
跟随系统
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user