fix: 修复 Windows 交叉编译错误
修复内容: - src/app/state.rs: AppState::new() 添加 current_theme 和 allow_exit 字段初始化 - src/app/commands.rs: 修复 FilePath 类型转换,使用 into_path() 方法 - src/app/mod.rs: 导入 Emitter trait 以使用 emit() 方法,修复 unused variable 警告 - src/app/mod.rs: 将主题菜单从 Menu 改为 Submenu 以符合 IsMenuItem trait - web/src/App.tsx: 修复 invoke 类型错误,使用 as 类型断言 - web/src/pages/SettingsPage.tsx: 修复 invoke 类型错误和 modelPath 类型推断 构建结果: - Windows 包已生成:dist/impress-asr-windows-x64-20260521_185247.zip - 文件大小:5.0MB - 包含 GUI 程序、CLI 工具、manifest 文件和前端资源
This commit is contained in:
parent
a4d6353f1a
commit
f3fe6bafc4
@ -173,7 +173,9 @@ pub async fn select_model_file(app: tauri::AppHandle) -> Result<String, String>
|
||||
.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);
|
||||
|
||||
@ -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!(" [托盘] 加载图标...");
|
||||
|
||||
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,9 +22,9 @@ function App() {
|
||||
useEffect(() => {
|
||||
const loadTheme = async () => {
|
||||
try {
|
||||
const currentTheme = await window.__TAURI__.invoke<string>('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)
|
||||
}
|
||||
|
||||
@ -78,9 +78,9 @@ export default function SettingsPage({ theme, onThemeChange }: SettingsPageProps
|
||||
|
||||
const handleSelectModel = async () => {
|
||||
try {
|
||||
const modelPath = await window.__TAURI__.invoke<string>('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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user