DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(window): add native macOS fullscreen controls
idealclovere76673a712e3
diff --git a/src-tauri/src/config/window_state.rs b/src-tauri/src/config/window_state.rsindex 510bec44..6a626f7b 100644--- a/src-tauri/src/config/window_state.rs+++ b/src-tauri/src/config/window_state.rs@@ -1,7 +1,7 @@//! 主窗口几何持久化:记住窗口大小/位置/最大化状态,重启后恢复。//!//! 为什么不直接用官方的 tauri-plugin-window-state:本项目主窗口是程序化创建-//! (见 `desktop::builder::build_main_window`)、无标题栏 `decorations(false)`,+//! (见 `desktop::builder::build_main_window`)、自定义壳层标题栏(macOS 上保留原生交通灯),//! 且关闭时是「隐藏到托盘」而非销毁(见 builder 的 on_window_event),并叠加//! release 的单例复用(二次启动 show/focus 同一窗口)。插件默认把状态写进独立的//! 配置文件、恢复时机与这套「隐藏 + 单例」流程存在耦合,且与本项目「所有应用数据@@ -86,6 +86,12 @@ fn save_window_state<R: Runtime>(app_handle: &AppHandle<R>, state: &WindowState)/// 采样当前窗口并保存(主窗口移动/缩放时由 builder 调用)。pub fn save_geometry<R: Runtime>(window: &Window<R>) {+ // 原生全屏切换会触发 Resized,但此时的屏幕尺寸不是可恢复的+ // 普通窗口几何;保留进入全屏前的最后一帧,退出全屏后会再次正常采样。+ if window.is_fullscreen().unwrap_or(false) {+ return;+ }+let pos = window.outer_position().ok();let size = window.outer_size().ok();let state = WindowState {diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rsindex 71da7b24..959706b9 100644--- a/src-tauri/src/desktop/builder.rs+++ b/src-tauri/src/desktop/builder.rs@@ -123,24 +123,38 @@ pub fn build_main_window(app: &tauri::AppHandle<Wry>) -> tauri::Result<tauri::We.title("Deepseek Harness Desktop").inner_size(1280.0, 840.0).min_inner_size(860.0, 620.0)- .resizable(true)- // 无系统标题栏:窗口 chrome 由壳层 ShellNavBar 常驻提供- // (44px 顶部导航:左侧 iframe 导航控制 + 右侧窗口控制)- .decorations(false)- // 恢复 iframe 内 HTML5 拖拽(拖入图片/拖动元素):- // Tauri 默认注册 wry drag_drop_handler → WebView2 SetAllowExternalDrop(false)- // 并注入 IDropTarget 接管拖放,iframe 内拖拽被禁用。- // 注意不能用 .drag_and_drop(false):它只设置 tao 窗口层的拖放开关- // (tauri issue #13761),不影响 webview 层,拖拽依旧失效;- // disable_drag_drop_handler 才能关掉 wry 的接管(等价于旧配置 dragDropEnabled: false)。- .disable_drag_drop_handler()- // 接管内嵌 iframe 的 window.open() / target=_blank 新窗口请求:- // WebView2 里这类请求走 NewWindowRequested,wry 在没有 handler 时- // 直接 SetHandled(true) 吞掉(点了没反应)——dshmarket 等预设插件的- // “源码”按钮在桌面端因此无法跳转(浏览器里正常)。- // 这里把 http(s) 链接交给系统浏览器打开,其余协议一律拒绝。- .on_new_window(move |url, features| on_new_window(app_handle.clone(), url, features))- .on_download(|webview, event| on_download(webview, event));+ .resizable(true);++ // macOS 保留原生交通灯:绿色按钮由 AppKit 进入独立 Space 的原生全屏,+ // 同时用 Overlay 让 44px 壳层导航栏继续与窗口 chrome 融合。其他平台+ // 仍由 ShellNavBar 的右侧按钮提供窗口控制。+ #[cfg(target_os = "macos")]+ let webview_builder = webview_builder+ .decorations(true)+ .title_bar_style(tauri::TitleBarStyle::Overlay)+ .hidden_title(true)+ // Wry 保留了 AppKit 原生按钮的纵向 frame 偏移;24px 在 44px+ // 壳层导航栏内的实测视觉圆心为 22px,而非 API 直觉上的 24px。+ .traffic_light_position(tauri::LogicalPosition::new(14.0, 24.0));++ #[cfg(not(target_os = "macos"))]+ let webview_builder = webview_builder.decorations(false);++ let webview_builder = webview_builder+ // 恢复 iframe 内 HTML5 拖拽(拖入图片/拖动元素):+ // Tauri 默认注册 wry drag_drop_handler → WebView2 SetAllowExternalDrop(false)+ // 并注入 IDropTarget 接管拖放,iframe 内拖拽被禁用。+ // 注意不能用 .drag_and_drop(false):它只设置 tao 窗口层的拖放开关+ // (tauri issue #13761),不影响 webview 层,拖拽依旧失效;+ // disable_drag_drop_handler 才能关掉 wry 的接管(等价于旧配置 dragDropEnabled: false)。+ .disable_drag_drop_handler()+ // 接管内嵌 iframe 的 window.open() / target=_blank 新窗口请求:+ // WebView2 里这类请求走 NewWindowRequested,wry 在没有 handler 时+ // 直接 SetHandled(true) 吞掉(点了没反应)——dshmarket 等预设插件的+ // “源码”按钮在桌面端因此无法跳转(浏览器里正常)。+ // 这里把 http(s) 链接交给系统浏览器打开,其余协议一律拒绝。+ .on_new_window(move |url, features| on_new_window(app_handle.clone(), url, features))+ .on_download(|webview, event| on_download(webview, event));#[cfg(windows)]let webview_builder = webview_builder.on_page_load(move |webview_window, payload| {diff --git a/src/layout/components/navbar.tsx b/src/layout/components/navbar.tsxindex b3e8300d..2dc22ec4 100644--- a/src/layout/components/navbar.tsx+++ b/src/layout/components/navbar.tsx@@ -14,6 +14,7 @@ import { invoke } from '@tauri-apps/api/core'import { getCurrentWindow } from '@tauri-apps/api/window'import { useTranslation } from 'react-i18next'import { If } from 'react-if-lite'+import { cn } from 'tailwind-variants'import { useStore } from 'valtio-define'import { ConfigDialog } from '@/components/config-dialog'import { DesktopAboutDialog } from '@/components/desktop-about-dialog'@@ -36,8 +37,11 @@ import { toast } from '@/utils'* 左侧控件只在「dsh-tauri 插件已启用(已安装)」且存在 iframe 时渲染:* 原生桥缺席时控件没有可靠接收方,避免出现点了没反应的死按钮。* - 空白拖拽区:Tauri 原生 `data-tauri-drag-region`(顶层文档直接生效),- * 双击切换最大化。- * - 窗口按钮:直接调用 Tauri 窗口 API;后台化 = 隐藏到托盘(服务保持运行)。+ * Windows/Linux 上双击切换最大化,macOS 上交由系统标题栏偏好。+ * - macOS:使用原生交通灯,红键后台化、黄键最小化、绿键进入原生全屏;+ * 导航栏左侧留出交通灯区域。+ * - Windows/Linux:右侧窗口按钮直接调用 Tauri API;+ * 后台化 = 隐藏到托盘(服务保持运行)。** 未传入 iframeRef(安装/错误/预装引导页,无 iframe 可操控)时* 只渲染窗口控制,不渲染左侧导航控制。@@ -49,6 +53,13 @@ import { toast } from '@/utils'*/const TAURI_PLUGIN_ID = 'dsh-tauri'+/** WKWebView 的 macOS UA 稳定包含 Macintosh,用于切换平台原生窗口 chrome。 */+function detectMacOS() {+ return navigator.userAgent.includes('Macintosh')+}++const IS_MACOS = detectMacOS()+export interface NavbarProps {/** 就绪态 iframe;传入时启用左侧导航控制 */iframeRef?: RefObject<HTMLIFrameElement | null>@@ -81,6 +92,12 @@ export function Navbar({ iframeRef }: NavbarProps) {}}+ function handleDragRegionDoubleClick() {+ // macOS 的双击标题栏行为由系统偏好决定,不用网页强制覆盖。+ if (!IS_MACOS)+ void getCurrentWindow().toggleMaximize()+ }+function handleHelpAction(key: string) {if (key === 'check-update')void handleCheckUpdate()@@ -118,7 +135,15 @@ export function Navbar({ iframeRef }: NavbarProps) {}return (- <div className="relative flex h-11 w-full flex-none select-none items-center gap-0.5 border-b border-line px-1.5 bg-panel">+ <div+ className={cn(+ 'relative flex h-11 w-full flex-none select-none items-center gap-0.5 border-b border-line bg-panel',+ {+ 'pl-20 pr-1.5': IS_MACOS,+ 'px-1.5': !IS_MACOS,+ },+ )}+ ><If cond={iframeRef != null && tauriEnabled}><ButtonclassName="rounded-lg size-7"@@ -222,41 +247,43 @@ export function Navbar({ iframeRef }: NavbarProps) {<divclassName="min-w-0 flex-1 self-stretch"data-tauri-drag-region- onDoubleClick={() => { void getCurrentWindow().toggleMaximize() }}+ onDoubleClick={handleDragRegionDoubleClick}/>- <Button- className="rounded-lg size-7"- isIconOnly- size="sm"- variant="ghost"- aria-label={t('nav.minimize')}- onPress={() => { handleWindowAction('minimize') }}- >- <Minus />- </Button>+ <If cond={!IS_MACOS}>+ <Button+ className="rounded-lg size-7"+ isIconOnly+ size="sm"+ variant="ghost"+ aria-label={t('nav.minimize')}+ onPress={() => { handleWindowAction('minimize') }}+ >+ <Minus />+ </Button>- <Button- className="rounded-lg size-7"- isIconOnly- size="sm"- variant="ghost"- aria-label={t('nav.maximize')}- onPress={() => { handleWindowAction('maximize') }}- >- <Square style={{ width: 14, height: 14 }} />- </Button>+ <Button+ className="rounded-lg size-7"+ isIconOnly+ size="sm"+ variant="ghost"+ aria-label={t('nav.maximize')}+ onPress={() => { handleWindowAction('maximize') }}+ >+ <Square style={{ width: 14, height: 14 }} />+ </Button>- <Button- className="rounded-lg size-7 transition-colors enabled:hover:bg-danger/16 enabled:hover:text-danger"- isIconOnly- size="sm"- variant="ghost"- aria-label={t('nav.background')}- onPress={() => { handleWindowAction('background') }}- >- <Xmark />- </Button>+ <Button+ className="rounded-lg size-7 transition-colors enabled:hover:bg-danger/16 enabled:hover:text-danger"+ isIconOnly+ size="sm"+ variant="ghost"+ aria-label={t('nav.background')}+ onPress={() => { handleWindowAction('background') }}+ >+ <Xmark />+ </Button>+ </If></div>)}