DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(macos): localize native window menu and restore fullscreen entry (#834)
云游君7e66436aeccb
diff --git a/src-tauri/Info.plist b/src-tauri/Info.plistindex bb377a3a..9dea8c50 100644--- a/src-tauri/Info.plist+++ b/src-tauri/Info.plist@@ -16,6 +16,13 @@--><plist version="1.0"><dict>+ <key>CFBundleDevelopmentRegion</key>+ <string>en</string>+ <key>CFBundleLocalizations</key>+ <array>+ <string>en</string>+ <string>zh-Hans</string>+ </array><key>NSMicrophoneUsageDescription</key><string>Voice input in DeepSeek Harness requires access to the microphone.</string><key>NSCameraUsageDescription</key>diff --git a/src-tauri/src/config/i18n.rs b/src-tauri/src/config/i18n.rsindex 0447367f..cdd42401 100644--- a/src-tauri/src/config/i18n.rs+++ b/src-tauri/src/config/i18n.rs@@ -53,7 +53,7 @@ pub fn t(key: &str) -> String {"menu.window" => ("窗口", "Window"),"menu.minimize" => ("最小化", "Minimize"),"menu.zoom" => ("缩放", "Zoom"),- "menu.bring_all_to_front" => ("前置全部窗口", "Bring All to Front"),+ "menu.bring_all_to_front" => ("全部置于顶层", "Bring All to Front"),"menu.keyboard_shortcuts" => ("显示键盘快捷键", "Show Keyboard Shortcuts"),"menu.enter_fullscreen" => ("进入全屏幕", "Enter Full Screen"),"menu.exit_fullscreen" => ("退出全屏幕", "Exit Full Screen"),diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rsindex 871ed821..5ea02fa9 100644--- a/src-tauri/src/desktop/builder.rs+++ b/src-tauri/src/desktop/builder.rs@@ -27,8 +27,7 @@ use tauri::tray::{MouseButton, TrayIconBuilder, TrayIconEvent};use tauri::menu::{PredefinedMenuItem, Submenu};#[cfg(target_os = "macos")]-static MACOS_FULLSCREEN_MENU_ITEM: OnceLock<Mutex<Option<PredefinedMenuItem<Wry>>>> =- OnceLock::new();+static MACOS_FULLSCREEN_MENU_ITEM: OnceLock<Mutex<Option<MenuItem<Wry>>>> = OnceLock::new();#[cfg(windows)]use crate::desktop::window::on_page_load;@@ -306,7 +305,14 @@ pub fn install_macos_menu(app: &tauri::AppHandle<Wry>) -> tauri::Result<()> {.and_then(|window| window.is_fullscreen().ok()).unwrap_or(false);let fullscreen_label = crate::config::i18n::t(fullscreen_menu_label_key(is_fullscreen));- let fullscreen = PredefinedMenuItem::fullscreen(app, Some(&fullscreen_label))?;+ // AppKit 会因标准 toggleFullScreen: 菜单项省略“窗口”中的自动全屏入口。+ let fullscreen = MenuItem::with_id(+ app,+ "desktop-fullscreen",+ &fullscreen_label,+ true,+ Some("Ctrl+Super+F"),+ )?;let run_menu = Submenu::with_id_and_items(app,"desktop-run-menu",@@ -522,6 +528,11 @@ fn fullscreen_menu_label_key(is_fullscreen: bool) -> &'static str {/// 原生全屏动画会连续触发 Resize;只在状态真正变化时刷新菜单文案。#[cfg(target_os = "macos")]fn sync_macos_fullscreen_menu(window: &tauri::Window<Wry>) {+ if window.label() == crate::desktop::pet::PET_WINDOW_LABEL+ || !window.is_focused().unwrap_or(false)+ {+ return;+ }let Ok(is_fullscreen) = window.is_fullscreen() else {return;};@@ -1237,6 +1248,20 @@ pub fn builder() -> tauri::Builder<tauri::Wry> {Ok(())}).on_menu_event(|app, event| match event.id().as_ref() {+ #[cfg(target_os = "macos")]+ "desktop-fullscreen" => {+ if let Some(window) = app.webview_windows().into_values().find(|window| {+ window.label() != crate::desktop::pet::PET_WINDOW_LABEL+ && window.is_focused().unwrap_or(false)+ }) {+ if let Err(error) = window+ .is_fullscreen()+ .and_then(|is_fullscreen| window.set_fullscreen(!is_fullscreen))+ {+ log::warn!("[menu] FULLSCREEN_TOGGLE_FAILED: {error}");+ }+ }+ }"desktop-config"| "desktop-profiles"| "desktop-plugins"@@ -1332,19 +1357,20 @@ pub fn builder() -> tauri::Builder<tauri::Wry> {label if label == MAIN_WINDOW_LABEL => crate::config::save_geometry(window),_ => {}}- // 全屏菜单文案与 Accessory 切换都只针对主窗口:附加窗口没有- // 独立的全屏菜单项,也不参与「关闭主窗口即后台化」的激活策略。#[cfg(target_os = "macos")]{- if window.label() == MAIN_WINDOW_LABEL- && matches!(event, tauri::WindowEvent::Resized(_))- {- // 退出全屏后补做全屏期间被推迟的 Accessory 切换+ if matches!(event, tauri::WindowEvent::Resized(_)) {+ // 全屏文案跟随聚焦的壳层窗口,Accessory 切换仍只处理主窗口。sync_macos_fullscreen_menu(window);- crate::desktop::activation::on_window_resized(window);+ if window.label() == MAIN_WINDOW_LABEL {+ // 退出全屏后补做全屏期间被推迟的 Accessory 切换。+ crate::desktop::activation::on_window_resized(window);+ }}}}+ #[cfg(target_os = "macos")]+ tauri::WindowEvent::Focused(true) => sync_macos_fullscreen_menu(window),_ => {}});diff --git a/test/macos-run-menu.test.ts b/test/macos-run-menu.test.tsindex 15106cf3..d170682f 100644--- a/test/macos-run-menu.test.ts+++ b/test/macos-run-menu.test.ts@@ -12,6 +12,25 @@ function submenuItems(id: string) {}describe('macOS native menu', () => {+ it('declares English and Simplified Chinese for system-provided menu items', () => {+ const plist = readFileSync(new URL('../src-tauri/Info.plist', import.meta.url), 'utf8').replace(/<!--[\s\S]*?-->/g, '')+ const localizations = plist.match(/<key>CFBundleLocalizations<\/key>\s*<array>([\s\S]*?)<\/array>/)++ expect(localizations).not.toBeNull()+ expect([...localizations![1].matchAll(/<string>(.*?)<\/string>/g)].map(language => language[1])).toEqual(['en', 'zh-Hans'])+ expect(plist).toMatch(/<key>CFBundleDevelopmentRegion<\/key>\s*<string>en<\/string>/)+ })++ it('leaves system window actions to AppKit and matches the native bring-to-front label', () => {+ expect(submenuItems('desktop-window-menu')).toEqual([+ '&minimize',+ '&zoom',+ '&window_separator',+ '&bring_all_to_front',+ ])+ expect(i18nSource).toContain('"menu.bring_all_to_front" => ("全部置于顶层", "Bring All to Front")')+ })+it('orders File, Edit, View, Run, Window and Help after the macOS application menu', () => {const nativeMenuSource = builderSource.slice(builderSource.indexOf('pub fn install_macos_menu('))const menu = nativeMenuSource.match(/let menu = Menu::with_items\(\s*app,\s*&\[([^\]]+)\]/)@@ -58,9 +77,15 @@ describe('macOS native menu', () => {expect(i18nSource).toContain('"menu.run" => ("运行", "Run")')})- it('keeps fullscreen as a native action with state-dependent labels', () => {+ it('toggles the focused shell window from View without suppressing AppKit fullscreen in Window', () => {expect(submenuItems('desktop-view-menu')).toEqual(['&fullscreen'])- expect(builderSource).toContain('PredefinedMenuItem::fullscreen(app, Some(&fullscreen_label))?')+ expect(builderSource).not.toContain('PredefinedMenuItem::fullscreen(')+ expect(builderSource).toMatch(/MenuItem::with_id\(\s*app,\s*"desktop-fullscreen",\s*&fullscreen_label,\s*true,\s*Some\("Ctrl\+Super\+F"\)/)+ const handler = builderSource.slice(builderSource.indexOf('"desktop-fullscreen" =>'))+ expect(handler).toContain('window.label() != crate::desktop::pet::PET_WINDOW_LABEL')+ expect(handler).toContain('window.is_focused().unwrap_or(false)')+ expect(handler).toContain('.and_then(|is_fullscreen| window.set_fullscreen(!is_fullscreen))')+ expect(builderSource).toMatch(/tauri::WindowEvent::Focused\(true\) => sync_macos_fullscreen_menu\(window\)/)expect(builderSource).toMatch(/fn fullscreen_menu_label_key\(is_fullscreen: bool\) -> &'static str \{\s*if is_fullscreen \{\s*"menu.exit_fullscreen"\s*\} else \{\s*"menu.enter_fullscreen"\s*\}/)expect(builderSource).toContain('let fullscreen_label = crate::config::i18n::t(fullscreen_menu_label_key(is_fullscreen));')expect(builderSource).toContain('let label = crate::config::i18n::t(fullscreen_menu_label_key(is_fullscreen));')