diff --git a/src/app/commands.rs b/src/app/commands.rs index 5b492eb..32c4409 100644 --- a/src/app/commands.rs +++ b/src/app/commands.rs @@ -173,7 +173,9 @@ pub async fn select_model_file(app: tauri::AppHandle) -> Result .add_filter("ONNX Model", &["onnx"]) .pick_file(move |file_path| { let result = match file_path { - Some(path) => Ok(path.to_string_lossy().to_string()), + Some(path) => path.into_path() + .map(|p| p.to_string_lossy().to_string()) + .map_err(|e| format!("转换路径失败:{}", e)), None => Err("用户取消选择".to_string()), }; let _ = tx.send(result); diff --git a/src/app/mod.rs b/src/app/mod.rs index 29c287a..f57f1f8 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -4,9 +4,9 @@ use anyhow::Result; use tauri::{ - menu::{Menu, MenuItem}, + menu::{Menu, MenuItem, Submenu}, tray::TrayIconBuilder, - Manager, + Manager, Emitter, }; use tracing::{info, warn}; @@ -164,7 +164,7 @@ pub fn run() -> Result<()> { _ => {} } }) - .on_page_load(|window, payload| { + .on_page_load(|_window, payload| { info!("[页面加载] URL: {}", payload.url()); match payload.event() { tauri::webview::PageLoadEvent::Started => { @@ -266,7 +266,7 @@ fn setup_tray(app: &tauri::App) -> Result<()> { let theme_light = MenuItem::with_id(app, "theme_light", "浅色主题", true, None::<&str>)?; let theme_dark = MenuItem::with_id(app, "theme_dark", "深色主题", true, None::<&str>)?; let theme_system = MenuItem::with_id(app, "theme_system", "跟随系统", true, None::<&str>)?; - let theme_menu = Menu::with_items(app, &[&theme_light, &theme_dark, &theme_system])?; + let theme_submenu = Submenu::with_items(app, "主题", true, &[&theme_light, &theme_dark, &theme_system])?; info!(" - '主题' 子菜单已创建(浅色/深色/跟随系统)"); // 完全退出选项 @@ -274,7 +274,7 @@ fn setup_tray(app: &tauri::App) -> Result<()> { info!(" - '完全退出' 菜单项已创建"); info!(" [托盘] 组合菜单..."); - let menu = Menu::with_items(app, &[&show, &record, &settings, &theme_menu, &quit_now])?; + let menu = Menu::with_items(app, &[&show, &record, &settings, &theme_submenu, &quit_now])?; info!(" ✓ 菜单创建成功 (5 项 + 主题子菜单)"); info!(" [托盘] 加载图标..."); diff --git a/src/app/state.rs b/src/app/state.rs index a218012..ce97e00 100644 --- a/src/app/state.rs +++ b/src/app/state.rs @@ -59,6 +59,8 @@ impl AppState { current_recording_path: RwLock::new(None), history: RwLock::new(VecDeque::with_capacity(MAX_HISTORY)), current_model: RwLock::new("sensevoice-small".to_string()), + current_theme: RwLock::new(AppTheme::Dark), + allow_exit: RwLock::new(false), } } diff --git a/web/src/App.tsx b/web/src/App.tsx index eac3ada..eab3b17 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -22,9 +22,9 @@ function App() { useEffect(() => { const loadTheme = async () => { try { - const currentTheme = await window.__TAURI__.invoke('get_theme') - setTheme(currentTheme as Theme) - applyTheme(currentTheme as Theme) + const currentTheme = await window.__TAURI__.invoke('get_theme') as Theme + setTheme(currentTheme) + applyTheme(currentTheme) } catch (e) { console.error('Failed to load theme:', e) } diff --git a/web/src/pages/SettingsPage.tsx b/web/src/pages/SettingsPage.tsx index 664f74c..33b83e5 100644 --- a/web/src/pages/SettingsPage.tsx +++ b/web/src/pages/SettingsPage.tsx @@ -78,9 +78,9 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps const handleSelectModel = async () => { try { - const modelPath = await window.__TAURI__.invoke('select_model_file') + const modelPath = await window.__TAURI__.invoke('select_model_file') as string if (modelPath) { - setSettings(prev => ({ ...prev, modelPath })) + setSettings(prev => ({ ...prev, modelPath: modelPath })) setModified(true) } } catch (e) {