Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(window): frameless shell with custom top nav bar and tauri bridge

hairyf7dcd65dd5d22
diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json
index d5dd88db..980e62cc 100644
--- a/src-tauri/capabilities/default.json
+++ b/src-tauri/capabilities/default.json
@@ -17,6 +17,8 @@
"core:window:allow-hide",
"core:window:allow-minimize",
"core:window:allow-maximize",
+ "core:window:allow-toggle-maximize",
+ "core:window:allow-set-decorations",
"core:window:allow-set-focus",
"core:window:allow-unminimize",
"core:window:allow-unmaximize",
diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rs
index 3915f0db..9fb14cc7 100644
--- a/src-tauri/src/desktop/builder.rs
+++ b/src-tauri/src/desktop/builder.rs
@@ -112,7 +112,9 @@ pub fn build_main_window(app: &tauri::AppHandle<Wry>) -> tauri::Result<tauri::We
.inner_size(1280.0, 840.0)
.min_inner_size(860.0, 620.0)
.resizable(true)
- .decorations(true)
+ // 无系统标题栏:窗口 chrome 由壳层 ShellNavBar(插件未接管时)或
+ // dsh-tauri 插件导航栏(接管时)提供,两者样式一致
+ .decorations(false)
// 恢复 iframe 内 HTML5 拖拽(拖入图片/拖动元素):
// Tauri 默认注册 wry drag_drop_handler → WebView2 SetAllowExternalDrop(false)
// 并注入 IDropTarget 接管拖放,iframe 内拖拽被禁用。
diff --git a/src/components/harness-webview.tsx b/src/components/harness-webview.tsx
index 9009cd4e..c01af934 100644
--- a/src/components/harness-webview.tsx
+++ b/src/components/harness-webview.tsx
@@ -4,10 +4,12 @@ import { useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { useStore } from 'valtio-define'
import { useIframeShim } from '@/hooks/use-iframe-shim'
+import { useIframeTauri } from '@/hooks/use-iframe-tauri'
import { harness } from '../store/modules/harness'
import Loadable from './loadable'
import PreinstallSetup from './preinstall-setup'
import Setup from './setup'
+import ShellNavBar from './shell-nav-bar'
/**
* 主区域视图:安装/错误态渲染 Setup,
@@ -28,10 +30,12 @@ export default function HarnessWebview() {
const iframeRef = useRef<HTMLIFrameElement>(null)
useIframeShim(iframeRef)
+ const isTauriPluginNavActive = useIframeTauri(iframeRef)
if (status === 'error') {
return (
<main className="relative flex-1 bg-canvas">
+ <ShellNavBar />
<Setup />
</main>
)
@@ -41,6 +45,7 @@ export default function HarnessWebview() {
if (status === 'preinstall') {
return (
<main className="relative w-full bg-canvas">
+ <ShellNavBar />
<PreinstallSetup />
</main>
)
@@ -49,6 +54,7 @@ export default function HarnessWebview() {
if (status !== 'ready') {
return (
<main className="relative w-full bg-canvas">
+ <ShellNavBar />
<Setup />
</main>
)
@@ -58,30 +64,38 @@ export default function HarnessWebview() {
<main className="relative flex-1 bg-canvas">
{serviceHealthy
? (
- <iframe
- key={iframeKey}
- ref={iframeRef}
- className="block h-full w-full border-none bg-load-bg"
- src={iframeSrc}
- allow="clipboard-read; clipboard-write; camera; microphone; geolocation; display-capture; autoplay; encrypted-media; fullscreen; notifications *"
- sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals allow-downloads allow-storage-access-by-user-activation"
- onLoad={harness.markIframeLoaded}
- onError={harness.markIframeError}
- title={t('app.open_editor')}
- />
+ <>
+ {!isTauriPluginNavActive && <ShellNavBar />}
+ <iframe
+ key={iframeKey}
+ ref={iframeRef}
+ className="block h-full w-full border-none bg-load-bg"
+ src={iframeSrc}
+ allow="clipboard-read; clipboard-write; camera; microphone; geolocation; display-capture; autoplay; encrypted-media; fullscreen; notifications *"
+ sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals allow-downloads allow-storage-access-by-user-activation"
+ onLoad={harness.markIframeLoaded}
+ onError={harness.markIframeError}
+ title={t('app.open_editor')}
+ />
+ </>
)
: (
<div className="absolute inset-0 z-[1]">
+ <ShellNavBar />
<Loadable subtitle={t('status.loading')} />
</div>
)}
{serviceHealthy && iframeError && (
- <Loadable
- icon={CircleExclamation}
- title={t('ui.iframe_error')}
- errorMsg={t('ui.ensure_running', { url: serviceUrl })}
- onRetry={harness.refreshIframe}
- />
+ <>
+ <ShellNavBar />
+ <Loadable
+ icon={CircleExclamation}
+ title={t('ui.iframe_error')}
+ errorMsg={t('ui.ensure_running', { url: serviceUrl })}
+ onRetry={harness.refreshIframe}
+ />
+ </>
+
)}
</main>
)
diff --git a/src/components/shell-nav-bar.tsx b/src/components/shell-nav-bar.tsx
new file mode 100644
index 00000000..4f14e31c
--- /dev/null
+++ b/src/components/shell-nav-bar.tsx
@@ -0,0 +1,80 @@
+import { Minus, Square, Xmark } from '@gravity-ui/icons'
+import { Button } from '@heroui/react'
+import { getCurrentWindow } from '@tauri-apps/api/window'
+import { useTranslation } from 'react-i18next'
+
+/**
+ * 壳层窗口导航栏(44px):插件导航栏未加载时的回退 chrome。
+ *
+ * 样式与 dsh-tauri 插件导航栏完全一致(同色系、同按钮、无边框),
+ * 但只承载窗口控制(最小化/最大化/后台化 + 拖拽区)——侧边栏/后退/前进
+ * 属于 dsh 页面能力,由插件在 iframe 内提供。
+ *
+ * 显示时机:插件发来 `dsh://tauri-ready` 后由 useIframeTauri 置为隐藏,
+ * 插件导航栏接管;iframe 重载/插件未安装时自动恢复显示。
+ * 拖拽区用 Tauri 原生 `data-tauri-drag-region`(顶层文档直接生效),
+ * 双击拖拽区切换最大化,与插件导航栏行为一致。
+ */
+export default function ShellNavBar() {
+ const { t } = useTranslation()
+
+ function handleWindowAction(action: 'minimize' | 'maximize' | 'background') {
+ const appWindow = getCurrentWindow()
+ switch (action) {
+ case 'minimize':
+ void appWindow.minimize()
+ break
+ case 'maximize':
+ void appWindow.toggleMaximize()
+ break
+ case 'background':
+ // 后台化:隐藏窗口到托盘(与关闭按钮行为一致,服务保持运行)
+ void appWindow.hide()
+ break
+ }
+ }
+
+ return (
+ <div className="dsh-tauri-nav dsh-tauri-nav--shell">
+ {/* 拖拽区:Tauri 原生拖拽(仅此元素带 data-tauri-drag-region,按钮不受影响) */}
+ <div
+ className="dsh-tauri-nav__drag"
+ data-tauri-drag-region
+ onDoubleClick={() => { void getCurrentWindow().toggleMaximize() }}
+ />
+
+ <Button
+ isIconOnly
+ size="sm"
+ variant="ghost"
+ className="dsh-tauri-nav__btn"
+ aria-label={t('nav.minimize')}
+ onPress={() => { handleWindowAction('minimize') }}
+ >
+ <Minus />
+ </Button>
+
+ <Button
+ isIconOnly
+ size="sm"
+ variant="ghost"
+ className="dsh-tauri-nav__btn"
+ aria-label={t('nav.maximize')}
+ onPress={() => { handleWindowAction('maximize') }}
+ >
+ <Square style={{ width: 14, height: 14 }} />
+ </Button>
+
+ <Button
+ isIconOnly
+ size="sm"
+ variant="ghost"
+ className="dsh-tauri-nav__btn dsh-tauri-nav__btn--danger"
+ aria-label={t('nav.background')}
+ onPress={() => { handleWindowAction('background') }}
+ >
+ <Xmark />
+ </Button>
+ </div>
+ )
+}
diff --git a/src/hooks/use-iframe-tauri.ts b/src/hooks/use-iframe-tauri.ts
new file mode 100644
index 00000000..b98318ff
--- /dev/null
+++ b/src/hooks/use-iframe-tauri.ts
@@ -0,0 +1,79 @@
+import type { RefObject } from 'react'
+import { getCurrentWindow } from '@tauri-apps/api/window'
+import { useState } from 'react'
+import { useEvent } from 'react-use'
+
+/**
+ * dsh-tauri 插件桥:监听 iframe(dsh web UI)内插件发来的窗口控制事件。
+ *
+ * 协议(iframe → 宿主,postMessage):
+ * - `{ source: 'dsh-tauri', type: 'dsh://tauri-ready' }`
+ * 插件导航栏挂载完成 → 隐藏壳层自定义导航栏(ShellNavBar),由插件接管;
+ * - `{ source: 'dsh-tauri', type: 'dsh://window-control', action }`
+ * action: minimize | maximize | background | drag-start,对应 Tauri 窗口操作。
+ *
+ * 只在 iframe 直接发来的消息上生效(event.source 校验),与通知桥一致;
+ * iframe 每次重新加载时恢复壳层导航栏(插件未挂载期间窗口仍有可用 chrome)。
+ *
+ * @returns tauriNavActive —— 插件导航栏是否已接管(壳层导航栏应隐藏)。
+ */
+interface TauriControlMessage {
+ source?: 'dsh-tauri'
+ type?: 'dsh://tauri-ready' | 'dsh://window-control'
+ action?: 'minimize' | 'maximize' | 'background' | 'drag-start'
+}
+
+export function useIframeTauri(iframeRef: RefObject<HTMLIFrameElement | null>): boolean {
+ // 插件导航栏是否已接管(决定壳层 ShellNavBar 的显隐)
+ const [tauriNavActive, setTauriNavActive] = useState(false)
+
+ function handleMessage(event: MessageEvent<TauriControlMessage>) {
+ const data = event.data
+ if (!data || typeof data !== 'object' || data.source !== 'dsh-tauri') {
+ return
+ }
+ // 只接受 DSH 直接 iframe 发来的消息;不兼容多层嵌套 iframe。
+ if (event.source !== iframeRef.current?.contentWindow) {
+ return
+ }
+
+ if (data.type === 'dsh://tauri-ready') {
+ // 插件导航栏已就绪:隐藏壳层自定义导航栏,插件栏接管窗口 chrome
+ setTauriNavActive(true)
+ // ack:插件据此停止重试(握手收敛)
+ iframeRef.current?.contentWindow?.postMessage(
+ { source: 'dsh-tauri', type: 'dsh://tauri-ack' },
+ '*',
+ )
+ return
+ }
+
+ if (data.type !== 'dsh://window-control') {
+ return
+ }
+
+ const appWindow = getCurrentWindow()
+ switch (data.action) {
+ case 'minimize':
+ void appWindow.minimize().catch(error => console.error('[tauri-nav] minimize failed:', error))
+ break
+ case 'maximize':
+ void appWindow.toggleMaximize().catch(error => console.error('[tauri-nav] toggleMaximize failed:', error))
+ break
+ case 'background':
+ // 后台化:隐藏窗口到托盘(与关闭按钮行为一致,服务保持运行)
+ void appWindow.hide().catch(error => console.error('[tauri-nav] hide failed:', error))
+ break
+ case 'drag-start':
+ // 空白区拖拽:窗口移动循环由 Tauri 接管
+ void appWindow.startDragging().catch(error => console.error('[tauri-nav] startDragging failed:', error))
+ break
+ default:
+ break
+ }
+ }
+
+ useEvent('message', handleMessage)
+
+ return tauriNavActive
+}
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index 1e939f47..aa2aa3f5 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -103,5 +103,9 @@
"messages.start_failed": "Failed to start service",
"messages.stop_failed": "Failed to stop service",
"messages.restarting": "Restarting service...",
- "messages.logs_cleared": "Logs cleared"
+ "messages.logs_cleared": "Logs cleared",
+ "nav.minimize": "Minimize",
+ "nav.maximize": "Maximize",
+ "nav.background": "Background"
}
+
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index 3686d4f8..eaa0753b 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -103,5 +103,9 @@
"messages.start_failed": "启动服务失败",
"messages.stop_failed": "停止服务失败",
"messages.restarting": "正在重启服务...",
- "messages.logs_cleared": "日志已清空"
+ "messages.logs_cleared": "日志已清空",
+ "nav.minimize": "最小化",
+ "nav.maximize": "最大化",
+ "nav.background": "后台化"
}
+
diff --git a/src/style/main.css b/src/style/main.css
index 2aba2106..0eaf8a94 100644
--- a/src/style/main.css
+++ b/src/style/main.css
@@ -100,3 +100,75 @@ html[data-theme="light"] {
font-size: 14px;
}
}
+
+/* ── 顶部导航栏(壳层 ShellNavBar)────────────────────────────
+ 与 dsh-tauri 插件导航栏视觉一致:44px、无边框、主题色按钮。
+ 插件接管(dsh://tauri-ready)后该栏隐藏,插件在 iframe 内渲染同款。 */
+.dsh-tauri-nav {
+ --dsh-tauri-ink: #f9fafb;
+ --dsh-tauri-muted: #adb2b8;
+ --dsh-tauri-hover: rgba(255, 255, 255, 0.08);
+ --dsh-tauri-active: rgba(255, 255, 255, 0.12);
+ --dsh-tauri-line: rgba(255, 255, 255, 0.12);
+ --dsh-tauri-danger: #f25a5a;
+
+ height: 44px;
+ display: flex;
+ align-items: center;
+ gap: 2px;
+ padding: 0 6px;
+ box-sizing: border-box;
+ background: rgb(21, 21, 23);
+ border-bottom: 1px solid var(--dsh-tauri-line);
+ user-select: none;
+ -webkit-user-select: none;
+}
+html[data-theme="light"] .dsh-tauri-nav--shell {
+ --dsh-tauri-ink: #0f1115;
+ --dsh-tauri-muted: #61666b;
+ --dsh-tauri-hover: rgba(0, 0, 0, 0.06);
+ --dsh-tauri-active: rgba(0, 0, 0, 0.1);
+ --dsh-tauri-line: rgba(0, 0, 0, 0.12);
+ background: rgb(255, 255, 255);
+}
+/* 壳层导航栏:流内布局(插件栏是 fixed,这里覆盖为相对定位占满宽度) */
+.dsh-tauri-nav--shell {
+ position: relative;
+ width: 100%;
+ flex: none;
+}
+.dsh-tauri-nav__btn {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 32px;
+ height: 32px;
+ padding: 0;
+ border: none;
+ border-radius: 8px;
+ background: transparent;
+ color: var(--dsh-tauri-ink);
+ cursor: default;
+ outline: none;
+ transition: background-color 0.12s ease, color 0.12s ease;
+}
+.dsh-tauri-nav__btn:hover {
+ background: var(--dsh-tauri-hover);
+}
+.dsh-tauri-nav__btn:active {
+ background: var(--dsh-tauri-active);
+}
+.dsh-tauri-nav__btn[aria-disabled='true'],
+.dsh-tauri-nav__btn:disabled {
+ color: var(--dsh-tauri-muted);
+ background: transparent;
+}
+.dsh-tauri-nav__btn--danger:hover {
+ background: rgba(242, 90, 90, 0.16);
+ color: var(--dsh-tauri-danger);
+}
+.dsh-tauri-nav__drag {
+ flex: 1;
+ align-self: stretch;
+ min-width: 0;
+}