Skip to content

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

feat(desktop): shell nav bar controls with iframe navigation bridge

hairyf29aaaafaa6fb
diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rs
index 05318938..6a450e33 100644
--- a/src-tauri/src/desktop/builder.rs
+++ b/src-tauri/src/desktop/builder.rs
@@ -112,8 +112,8 @@ 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)
- // 无系统标题栏:窗口 chrome 由壳层 ShellNavBar(插件未接管时)或
- // dsh-tauri 插件导航栏(接管时)提供,两者样式一致
+ // 无系统标题栏:窗口 chrome 由壳层 ShellNavBar 常驻提供
+ // (44px 顶部导航:左侧 iframe 导航控制 + 右侧窗口控制)
.decorations(false)
// 恢复 iframe 内 HTML5 拖拽(拖入图片/拖动元素):
// Tauri 默认注册 wry drag_drop_handler → WebView2 SetAllowExternalDrop(false)
@@ -140,10 +140,12 @@ pub fn build_main_window(app: &tauri::AppHandle<Wry>) -> tauri::Result<tauri::We
});
// 非 Windows(macOS/Linux)没有 WebView2 的 FrameCreated/ContentLoading 流程,
- // 直接用 Tauri 的 initialization_script_for_all_frames 把通知桥注入所有 frame。
+ // 直接用 Tauri 的 initialization_script_for_all_frames 把通知桥与导航桥注入
+ // 所有 frame(两个脚本均带 window.__dsh_*_bridge__ 幂等守卫,重复注入安全)。
#[cfg(not(windows))]
let webview_builder = webview_builder
- .initialization_script_for_all_frames(crate::desktop::notification::NOTIFICATION_SHIM_JS);
+ .initialization_script_for_all_frames(crate::desktop::notification::NOTIFICATION_SHIM_JS)
+ .initialization_script_for_all_frames(crate::desktop::nav::NAV_SHIM_JS);
let webview_window = webview_builder.build()?;
diff --git a/src-tauri/src/desktop/mod.rs b/src-tauri/src/desktop/mod.rs
index 704414e4..e56840f3 100644
--- a/src-tauri/src/desktop/mod.rs
+++ b/src-tauri/src/desktop/mod.rs
@@ -1,4 +1,5 @@
pub mod builder;
+pub mod nav;
pub mod notification;
pub mod payload;
pub mod window;
diff --git a/src-tauri/src/desktop/nav.rs b/src-tauri/src/desktop/nav.rs
new file mode 100644
index 00000000..fe8f791c
--- /dev/null
+++ b/src-tauri/src/desktop/nav.rs
@@ -0,0 +1,233 @@
+//! 壳层导航桥:宿主(ShellNavBar)→ iframe 的导航控制,以及 iframe → 宿主的
+//! dsh 状态回报(侧边栏折叠 / 页面历史边界)。
+//!
+//! 导航栏左侧三个控件(侧边栏切换 / 后退 / 前进)位于 Tauri 宿主文档(`tauri://`),
+//! 而目标页面是跨域的 dsh iframe(`http://127.0.0.1:<port>`),宿主无法直接访问
+//! iframe 的应用内部状态,只能靠 postMessage + 注入脚本桥接。
+//! 本脚本与 [`crate::desktop::notification::NOTIFICATION_SHIM_JS`] 走同一套注入通道
+//! (Windows 在 FrameCreated → ContentLoading 时 ExecuteScript,其余平台
+//! `initialization_script_for_all_frames`),因此 iframe 每次重新加载都会自动重建。
+//!
+//! 协议(与 dsh-tauri 插件完全一致):
+//! - 接收 `dsh://sidebar:toggle` / `dsh://page:prev` / `dsh://page:next` 命令;
+//! - 回报 `dsh://sidebar:collapsed` / `dsh://page:firsted` / `dsh://page:lasted` 事件。
+//! 插件加载后设置 `window.__dsh_tauri_bridge__`,本脚本检测到即让位
+//! (命令与事件都停发,避免双重执行);插件卸载后自动恢复接管。
+//!
+//! 页面模型:dsh 应用不产生浏览器历史,「页面」= 侧边栏当前选中的会话
+//! (`[role="treeitem"][aria-selected="true"]`)。观察选中会话变化维护会话
+//! 访问栈(纯内存):用户点击会话 → 截断前进记录后追加新页并上报;后退/前进 →
+//! 点击栈内对应会话行(行元素失效时按标题匹配兜底)。
+
+/// iframe 内注入的导航桥脚本(dsh-tauri 插件缺席时的兜底实现)。
+pub(crate) const NAV_SHIM_JS: &str = r#"(function () {
+ if (window.__dsh_nav_bridge__) return;
+ window.__dsh_nav_bridge__ = true;
+
+ var SRC_BRIDGE = 'dsh-nav-bridge';
+ // 侧边栏开关按钮的已知 aria-label(zh/en 两个内置语言),
+ // 用于校验按位置命中的按钮确实是开关,避免误点品牌/新建会话按钮。
+ var TOGGLE_LABELS = ['打开侧边栏', '收起侧边栏', 'Open sidebar', 'Collapse sidebar'];
+ // 会话行菜单按钮的 aria-label 模板(zh/en),用于提取标题与按标题找行。
+ var SESSION_LABEL_PATTERNS = [/^会话“(.+)”的操作$/, /^Session actions for (.+)$/];
+
+ // dsh-tauri 插件已接管时让位:命令与事件都停发,避免双重执行
+ function bridgeActive() {
+ return !!window.__dsh_tauri_bridge__;
+ }
+
+ function post(message) {
+ if (bridgeActive()) return;
+ try {
+ window.parent.postMessage(Object.assign({ source: SRC_BRIDGE }, message), '*');
+ } catch (_) {}
+ }
+
+ // AppFrame:dsh 应用布局的根(shell.overlay 的父节点),
+ // 与官方 layout 插件维护的 data-sidebar-collapsed 同源。
+ function findFrame() {
+ var overlay = document.querySelector('[data-shell-overlay]');
+ return overlay && overlay.parentElement;
+ }
+
+ function isCollapsed() {
+ var frame = findFrame();
+ return !!(frame && frame.hasAttribute('data-sidebar-collapsed'));
+ }
+
+ // 定位侧边栏开关按钮:AppFrame 第一个子节点即侧边栏列。
+ // 展开态 logoRow = 品牌按钮(新建会话) + 开关;折叠态品牌按钮隐藏,开关是第一个按钮。
+ // 命中后校验 aria-label 是否属于已知开关文案,不属于则全列扫描兜底(新语言包时)。
+ function findToggleButton() {
+ var frame = findFrame();
+ if (!frame) return null;
+ var col = frame.firstElementChild;
+ if (!col) return null;
+ var buttons = col.querySelectorAll('button');
+ if (buttons.length === 0) return null;
+
+ var idx = isCollapsed() ? 0 : 1;
+ var ordered = [];
+ if (buttons[idx]) ordered.push(buttons[idx]);
+ for (var i = 0; i < buttons.length; i++) ordered.push(buttons[i]);
+
+ for (var j = 0; j < ordered.length; j++) {
+ var label = (ordered[j].getAttribute('aria-label') || '').trim();
+ if (TOGGLE_LABELS.indexOf(label) !== -1) return ordered[j];
+ }
+ return null;
+ }
+
+ // ── 会话访问栈(页面模型,纯内存)─────────────────────────────
+ // dsh 应用不产生浏览器历史,「页面」= 侧边栏当前选中的会话。观察
+ // aria-selected 变化维护访问栈:用户点击会话 → 截断前进记录后追加;
+ // 后退/前进 → 点击栈内对应会话行让应用切回。
+ var pages = []; // [{ key, el }]
+ var position = 0;
+ var lastKey = null;
+ var suppress = false; // 本桥导航落位中,观察器不应记录新页面
+
+ function sidebarCol() {
+ var frame = findFrame();
+ return frame ? frame.firstElementChild : null;
+ }
+
+ // 当前选中的会话行
+ function currentSelected() {
+ var col = sidebarCol();
+ if (!col) return null;
+ return col.querySelector('[role="treeitem"][aria-selected="true"]');
+ }
+
+ // 行标题:从行内菜单按钮 aria-label 提取(zh/en),失败回退整行文本
+ function rowTitle(row) {
+ if (!row) return '';
+ var btn = row.querySelector('button[aria-label]');
+ var label = btn ? (btn.getAttribute('aria-label') || '') : '';
+ for (var i = 0; i < SESSION_LABEL_PATTERNS.length; i++) {
+ var m = SESSION_LABEL_PATTERNS[i].exec(label);
+ if (m) return m[1].trim();
+ }
+ return label || (row.textContent || '').trim();
+ }
+
+ // 按标题找会话行(行元素被重建后的兜底)
+ function findRowByTitle(title) {
+ if (!title) return null;
+ var col = sidebarCol();
+ if (!col) return null;
+ var rows = col.querySelectorAll('[role="treeitem"]');
+ for (var i = 0; i < rows.length; i++) {
+ if (rowTitle(rows[i]) === title) return rows[i];
+ }
+ return null;
+ }
+
+ function reportPage() {
+ if (bridgeActive()) return;
+ post({ type: 'dsh://page:firsted', firsted: position <= 0 });
+ post({ type: 'dsh://page:lasted', lasted: position >= pages.length - 1 });
+ }
+
+ // 用户导航到新会话:截断前进记录后追加
+ function pushPage(key, el) {
+ pages = pages.slice(0, position + 1).concat([{ key: key, el: el }]);
+ position = pages.length - 1;
+ reportPage();
+ }
+
+ // 后退/前进:切到栈内目标页(点击对应会话行让应用落位)
+ function navigateTo(index) {
+ if (index < 0 || index >= pages.length) return;
+ var page = pages[index];
+ position = index;
+ var target = page.el && page.el.isConnected ? page.el : findRowByTitle(page.key || '');
+ if (target) {
+ suppress = true;
+ target.click();
+ }
+ reportPage();
+ }
+
+ function onDomChange() {
+ if (bridgeActive()) return;
+ var sel = currentSelected();
+ var key = rowTitle(sel);
+ if (key === lastKey) return;
+ lastKey = key;
+ if (suppress) {
+ // 本桥导航落位:同步当前页记录(行元素可能被 React 重建)
+ suppress = false;
+ if (pages[position] !== undefined) {
+ pages[position] = { key: key, el: sel };
+ }
+ return;
+ }
+ // 用户主动切换会话(无选中 = 欢迎/归档态,不入栈)
+ if (key) pushPage(key, sel);
+ }
+
+ var pageObserver = new MutationObserver(onDomChange);
+
+ // ── 侧边栏折叠观察 + 初始化 ──────────────────────────────────
+ function reportSidebar() {
+ if (bridgeActive()) return;
+ post({ type: 'dsh://sidebar:collapsed', collapsed: isCollapsed() });
+ }
+
+ // 应用挂载前无会话树:轮询直到拿到 AppFrame 再初始化
+ function startTrack() {
+ var frame = findFrame();
+ if (!frame) return false;
+
+ new MutationObserver(reportSidebar)
+ .observe(frame, { attributes: true, attributeFilter: ['data-sidebar-collapsed'] });
+ reportSidebar();
+
+ var sel = currentSelected();
+ var key = rowTitle(sel);
+ lastKey = key;
+ // 根页:当前选中的会话(无选中时以「欢迎页」为根,首个会话打开即入栈)
+ pages = [{ key: key || null, el: sel }];
+ position = 0;
+ pageObserver.observe(document.body, {
+ childList: true,
+ subtree: true,
+ attributes: true,
+ attributeFilter: ['aria-selected']
+ });
+ reportPage();
+ return true;
+ }
+ (function () {
+ if (startTrack()) return;
+ var tries = 0;
+ var timer = setInterval(function () {
+ if (startTrack()) {
+ clearInterval(timer);
+ } else if (++tries > 30) {
+ clearInterval(timer);
+ }
+ }, 500);
+ })();
+
+ // ── 宿主命令接收 ─────────────────────────────────────────────
+ window.addEventListener('message', function (event) {
+ if (bridgeActive()) return;
+ var data = event.data;
+ if (!data || typeof data !== 'object' || data.source !== 'dsh-desktop') return;
+ switch (data.type) {
+ case 'dsh://sidebar:toggle': {
+ var btn = findToggleButton();
+ if (btn) btn.click();
+ break;
+ }
+ case 'dsh://page:prev':
+ navigateTo(position - 1);
+ break;
+ case 'dsh://page:next':
+ navigateTo(position + 1);
+ break;
+ }
+ });
+})();"#;
diff --git a/src-tauri/src/desktop/notification.rs b/src-tauri/src/desktop/notification.rs
index 3efa32e1..8aa80cba 100644
--- a/src-tauri/src/desktop/notification.rs
+++ b/src-tauri/src/desktop/notification.rs
@@ -271,11 +271,17 @@ pub fn enable_notification_permissions(
let _ = frame3.add_ContentLoading(
&FrameContentLoadingEventHandler::create(Box::new(move |_, _| {
- let script = HSTRING::from(NOTIFICATION_SHIM_JS);
- let _ = frame_for_injection.ExecuteScript(
- &script,
- &ExecuteScriptCompletedHandler::create(Box::new(|_, _| Ok(()))),
- );
+ // 通知桥 + 导航桥(壳层导航栏左侧控制需要 iframe 上下文执行)
+ for script in [
+ crate::desktop::notification::NOTIFICATION_SHIM_JS,
+ crate::desktop::nav::NAV_SHIM_JS,
+ ] {
+ let script = HSTRING::from(script);
+ let _ = frame_for_injection.ExecuteScript(
+ &script,
+ &ExecuteScriptCompletedHandler::create(Box::new(|_, _| Ok(()))),
+ );
+ }
Ok(())
})),
&mut content_token,
diff --git a/src/components/harness-webview.tsx b/src/components/harness-webview.tsx
index c01af934..1f52cb62 100644
--- a/src/components/harness-webview.tsx
+++ b/src/components/harness-webview.tsx
@@ -4,7 +4,6 @@ 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'
@@ -12,8 +11,9 @@ import Setup from './setup'
import ShellNavBar from './shell-nav-bar'
/**
- * 主区域视图:安装/错误态渲染 Setup,
- * 就绪态渲染 iframe(挂载后加载职责交给 dsh 应用内官方 boot 页,避免两套 loading 叠加)。
+ * 主区域视图:壳层导航栏(ShellNavBar)常驻顶部,
+ * 安装/错误态渲染 Setup,就绪态渲染 iframe
+ * (挂载后加载职责交给 dsh 应用内官方 boot 页,避免两套 loading 叠加)。
* 状态与方法全部来自 harness store,不再接收 props。
*/
export default function HarnessWebview() {
@@ -30,13 +30,14 @@ 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">
+ <main className="relative flex min-h-0 flex-1 flex-col bg-canvas">
<ShellNavBar />
- <Setup />
+ <div className="min-h-0 flex-1">
+ <Setup />
+ </div>
</main>
)
}
@@ -44,28 +45,34 @@ export default function HarnessWebview() {
// 预装插件引导:独立于安装/加载界面,渲染推荐插件列表与安装控制台
if (status === 'preinstall') {
return (
- <main className="relative w-full bg-canvas">
+ <main className="relative flex min-h-0 w-full flex-col bg-canvas">
<ShellNavBar />
- <PreinstallSetup />
+ <div className="min-h-0 flex-1">
+ <PreinstallSetup />
+ </div>
</main>
)
}
if (status !== 'ready') {
return (
- <main className="relative w-full bg-canvas">
+ <main className="relative flex min-h-0 w-full flex-col bg-canvas">
<ShellNavBar />
- <Setup />
+ <div className="min-h-0 flex-1">
+ <Setup />
+ </div>
</main>
)
}
return (
- <main className="relative flex-1 bg-canvas">
- {serviceHealthy
- ? (
- <>
- {!isTauriPluginNavActive && <ShellNavBar />}
+ <main className="relative flex min-h-0 flex-1 flex-col bg-canvas">
+ <ShellNavBar iframeRef={iframeRef} />
+
+ {/* iframe 区域:加载失败时用覆盖层展示重试(iframe 保持挂载,重试复用) */}
+ <div className="relative min-h-0 flex-1">
+ {serviceHealthy
+ ? (
<iframe
key={iframeKey}
ref={iframeRef}
@@ -77,26 +84,22 @@ export default function HarnessWebview() {
onError={harness.markIframeError}
title={t('app.open_editor')}
/>
- </>
- )
- : (
- <div className="absolute inset-0 z-[1]">
- <ShellNavBar />
+ )
+ : (
<Loadable subtitle={t('status.loading')} />
- </div>
- )}
- {serviceHealthy && iframeError && (
- <>
- <ShellNavBar />
- <Loadable
- icon={CircleExclamation}
- title={t('ui.iframe_error')}
- errorMsg={t('ui.ensure_running', { url: serviceUrl })}
- onRetry={harness.refreshIframe}
- />
- </>
+ )}
- )}
+ {serviceHealthy && iframeError && (
+ <div className="absolute inset-0 z-[1]">
+ <Loadable
+ icon={CircleExclamation}
+ title={t('ui.iframe_error')}
+ errorMsg={t('ui.ensure_running', { url: serviceUrl })}
+ onRetry={harness.refreshIframe}
+ />
+ </div>
+ )}
+ </div>
</main>
)
}
diff --git a/src/components/shell-nav-bar.tsx b/src/components/shell-nav-bar.tsx
index 4f14e31c..4dd343f2 100644
--- a/src/components/shell-nav-bar.tsx
+++ b/src/components/shell-nav-bar.tsx
@@ -1,22 +1,57 @@
-import { Minus, Square, Xmark } from '@gravity-ui/icons'
+import type { RefObject } from 'react'
+import {
+ ArrowLeft,
+ ArrowRight,
+ LayoutSideContent,
+ LayoutSideContentLeft,
+ Minus,
+ Square,
+ Xmark,
+} from '@gravity-ui/icons'
import { Button } from '@heroui/react'
import { getCurrentWindow } from '@tauri-apps/api/window'
import { useTranslation } from 'react-i18next'
+import { If } from 'react-if-lite'
+import { useDshPlugins } from '../hooks/use-dsh-plugins'
+import { useIframeTauri } from '../hooks/use-iframe-tauri'
/**
- * 壳层窗口导航栏(44px):插件导航栏未加载时的回退 chrome。
+ * 壳层窗口顶部导航栏(44px,常驻):
*
- * 样式与 dsh-tauri 插件导航栏完全一致(同色系、同按钮、无边框),
- * 但只承载窗口控制(最小化/最大化/后台化 + 拖拽区)——侧边栏/后退/前进
- * 属于 dsh 页面能力,由插件在 iframe 内提供。
+ * [侧边栏(展开/收起)] [后退] [前进] [ 空白拖拽区 ] [最小化][最大化][后台化(X)]
*
- * 显示时机:插件发来 `dsh://tauri-ready` 后由 useIframeTauri 置为隐藏,
- * 插件导航栏接管;iframe 重载/插件未安装时自动恢复显示。
- * 拖拽区用 Tauri 原生 `data-tauri-drag-region`(顶层文档直接生效),
- * 双击拖拽区切换最大化,与插件导航栏行为一致。
+ * - 侧边栏/后退/前进:经 postMessage 操控 iframe 内的 dsh 应用
+ * (`dsh://sidebar:toggle` / `dsh://page:prev` / `dsh://page:next`,
+ * 由 dsh-tauri 插件或桌面端注入的导航桥脚本 NAV_SHIM_JS 执行);
+ * 折叠图标与按钮禁用态由 iframe 回报的
+ * `dsh://sidebar:collapsed` / `dsh://page:firsted` / `dsh://page:lasted` 同步。
+ * 左侧控件只在「dsh-tauri 插件已启用(已安装)」且存在 iframe 时渲染:
+ * 原生桥缺席时控件没有可靠接收方,避免出现点了没反应的死按钮。
+ * - 空白拖拽区:Tauri 原生 `data-tauri-drag-region`(顶层文档直接生效),
+ * 双击切换最大化。
+ * - 窗口按钮:直接调用 Tauri 窗口 API;后台化 = 隐藏到托盘(服务保持运行)。
+ *
+ * 未传入 iframeRef(安装/错误/预装引导页,无 iframe 可操控)时
+ * 只渲染窗口控制,不渲染左侧导航控制。
*/
-export default function ShellNavBar() {
+
+/**
+ * dsh-tauri 插件 id:安装后 iframe 内提供 `window.__dsh_tauri_bridge__`
+ * 原生导航桥(`useDshPlugins` 实时同步其安装状态,插件增删即时生效)
+ */
+const TAURI_PLUGIN_ID = 'dsh-tauri'
+
+interface ShellNavBarProps {
+ /** 就绪态 iframe;传入时启用左侧导航控制 */
+ iframeRef?: RefObject<HTMLIFrameElement | null>
+}
+
+export default function ShellNavBar({ iframeRef }: ShellNavBarProps) {
const { t } = useTranslation()
+ const { plugins } = useDshPlugins()
+ const { sidebarCollapsed, canGoBack, canGoForward, sendNav } = useIframeTauri(iframeRef)
+ // 仅当 dsh-tauri 插件启用(已安装)时显示左侧导航控件
+ const tauriEnabled = plugins.some(plugin => plugin.id === TAURI_PLUGIN_ID)
function handleWindowAction(action: 'minimize' | 'maximize' | 'background') {
const appWindow = getCurrentWindow()
@@ -35,10 +70,51 @@ export default function ShellNavBar() {
}
return (
- <div className="dsh-tauri-nav dsh-tauri-nav--shell">
+ <div className="shell-nav">
+ <If cond={iframeRef != null && tauriEnabled}>
+ <Button
+ isIconOnly
+ size="sm"
+ variant="ghost"
+ className="shell-nav__btn"
+ aria-label={t(sidebarCollapsed ? 'nav.sidebar_expand' : 'nav.sidebar_collapse')}
+ onPress={() => { sendNav('sidebar:toggle') }}
+ >
+ <If
+ cond={sidebarCollapsed}
+ then={<LayoutSideContentLeft />}
+ else={<LayoutSideContent />}
+ />
+ </Button>
+
+ <Button
+ isIconOnly
+ size="sm"
+ variant="ghost"
+ className="shell-nav__btn"
+ aria-label={t('nav.back')}
+ isDisabled={!canGoBack}
+ onPress={() => { sendNav('page:prev') }}
+ >
+ <ArrowLeft />
+ </Button>
+
+ <Button
+ isIconOnly
+ size="sm"
+ variant="ghost"
+ className="shell-nav__btn"
+ aria-label={t('nav.forward')}
+ isDisabled={!canGoForward}
+ onPress={() => { sendNav('page:next') }}
+ >
+ <ArrowRight />
+ </Button>
+ </If>
+
{/* 拖拽区:Tauri 原生拖拽(仅此元素带 data-tauri-drag-region,按钮不受影响) */}
<div
- className="dsh-tauri-nav__drag"
+ className="shell-nav__drag"
data-tauri-drag-region
onDoubleClick={() => { void getCurrentWindow().toggleMaximize() }}
/>
@@ -47,7 +123,7 @@ export default function ShellNavBar() {
isIconOnly
size="sm"
variant="ghost"
- className="dsh-tauri-nav__btn"
+ className="shell-nav__btn"
aria-label={t('nav.minimize')}
onPress={() => { handleWindowAction('minimize') }}
>
@@ -58,7 +134,7 @@ export default function ShellNavBar() {
isIconOnly
size="sm"
variant="ghost"
- className="dsh-tauri-nav__btn"
+ className="shell-nav__btn"
aria-label={t('nav.maximize')}
onPress={() => { handleWindowAction('maximize') }}
>
@@ -69,7 +145,7 @@ export default function ShellNavBar() {
isIconOnly
size="sm"
variant="ghost"
- className="dsh-tauri-nav__btn dsh-tauri-nav__btn--danger"
+ className="shell-nav__btn shell-nav__btn--danger"
aria-label={t('nav.background')}
onPress={() => { handleWindowAction('background') }}
>
diff --git a/src/hooks/use-iframe-tauri.ts b/src/hooks/use-iframe-tauri.ts
index b98318ff..b0fe3ed2 100644
--- a/src/hooks/use-iframe-tauri.ts
+++ b/src/hooks/use-iframe-tauri.ts
@@ -1,79 +1,91 @@
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)内插件发来的窗口控制事件。
+ * 壳层导航桥(宿主侧):ShellNavBar 左侧三个控件的消息通道。
*
- * 协议(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 窗口操作。
+ * 协议(与 dsh-tauri 插件 / 桌面端 NAV_SHIM_JS 一致):
+ * - 发送(宿主 → iframe):`{ source: 'dsh-desktop', type }`
+ * - `dsh://sidebar:toggle` 切换侧边栏
+ * - `dsh://page:prev` / `dsh://page:next` 后退 / 前进
+ * - 接收(iframe → 宿主):`{ source: 'dsh-nav-bridge', type, ... }`
+ * - `dsh://sidebar:collapsed` `{ collapsed }` 侧边栏折叠状态
+ * - `dsh://page:firsted` / `dsh://page:lasted` `{ firsted/lasted }`
+ * 历史边界(宿主据此禁用后退/前进按钮)
*
- * 只在 iframe 直接发来的消息上生效(event.source 校验),与通知桥一致;
- * iframe 每次重新加载时恢复壳层导航栏(插件未挂载期间窗口仍有可用 chrome)。
- *
- * @returns tauriNavActive —— 插件导航栏是否已接管(壳层导航栏应隐藏)。
+ * 只在 iframe 直接发来的消息上生效(event.source 校验),与通知桥一致。
+ * iframeRef 为空(安装/错误/预装引导页)时只返回默认状态,不发送任何消息。
*/
-interface TauriControlMessage {
- source?: 'dsh-tauri'
- type?: 'dsh://tauri-ready' | 'dsh://window-control'
- action?: 'minimize' | 'maximize' | 'background' | 'drag-start'
+
+/** 左侧导航控制动作(宿主 → iframe 命令)。 */
+export type ShellNavAction = 'sidebar:toggle' | 'page:prev' | 'page:next'
+
+/** 命令类型映射(消息 type 与 action 一一对应)。 */
+const COMMAND_TYPES: Record<ShellNavAction, string> = {
+ 'sidebar:toggle': 'dsh://sidebar:toggle',
+ 'page:prev': 'dsh://page:prev',
+ 'page:next': 'dsh://page:next',
+}
+
+/** iframe 导航桥回报协议。 */
+interface NavBridgeMessage {
+ source?: 'dsh-nav-bridge'
+ type?: 'dsh://sidebar:collapsed' | 'dsh://page:firsted' | 'dsh://page:lasted'
+ collapsed?: boolean
+ firsted?: boolean
+ lasted?: boolean
}
-export function useIframeTauri(iframeRef: RefObject<HTMLIFrameElement | null>): boolean {
- // 插件导航栏是否已接管(决定壳层 ShellNavBar 的显隐)
- const [tauriNavActive, setTauriNavActive] = useState(false)
+export function useIframeTauri(
+ iframeRef: RefObject<HTMLIFrameElement | null> | undefined,
+): {
+ sidebarCollapsed: boolean
+ /** 可否后退(!firsted);默认不可,收到桥回报后更新 */
+ canGoBack: boolean
+ /** 可否前进(!lasted);默认不可,收到桥回报后更新 */
+ canGoForward: boolean
+ sendNav: (action: ShellNavAction) => void
+} {
+ const [sidebarCollapsed, setSidebarCollapsed] = useState(false)
+ // 历史边界默认置位(按钮禁用),等待 iframe 内导航桥回报后更新
+ const [pageEdge, setPageEdge] = useState({ firsted: true, lasted: true })
- function handleMessage(event: MessageEvent<TauriControlMessage>) {
+ function handleMessage(event: MessageEvent<NavBridgeMessage>) {
const data = event.data
- if (!data || typeof data !== 'object' || data.source !== 'dsh-tauri') {
+ if (!data || typeof data !== 'object' || data.source !== 'dsh-nav-bridge') {
return
}
// 只接受 DSH 直接 iframe 发来的消息;不兼容多层嵌套 iframe。
- if (event.source !== iframeRef.current?.contentWindow) {
+ 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))
+ switch (data.type) {
+ case 'dsh://sidebar:collapsed':
+ setSidebarCollapsed(Boolean(data.collapsed))
break
- case 'background':
- // 后台化:隐藏窗口到托盘(与关闭按钮行为一致,服务保持运行)
- void appWindow.hide().catch(error => console.error('[tauri-nav] hide failed:', error))
+ case 'dsh://page:firsted':
+ setPageEdge(prev => ({ ...prev, firsted: Boolean(data.firsted) }))
break
- case 'drag-start':
- // 空白区拖拽:窗口移动循环由 Tauri 接管
- void appWindow.startDragging().catch(error => console.error('[tauri-nav] startDragging failed:', error))
- break
- default:
+ case 'dsh://page:lasted':
+ setPageEdge(prev => ({ ...prev, lasted: Boolean(data.lasted) }))
break
}
}
useEvent('message', handleMessage)
- return tauriNavActive
+ function sendNav(action: ShellNavAction) {
+ iframeRef?.current?.contentWindow?.postMessage(
+ { source: 'dsh-desktop', type: COMMAND_TYPES[action] },
+ '*',
+ )
+ }
+
+ return {
+ sidebarCollapsed,
+ canGoBack: !pageEdge.firsted,
+ canGoForward: !pageEdge.lasted,
+ sendNav,
+ }
}
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index 436a165c..b1c7dc4a 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -110,8 +110,11 @@
"messages.stop_failed": "Failed to stop service",
"messages.restarting": "Restarting service...",
"messages.logs_cleared": "Logs cleared",
+ "nav.sidebar_expand": "Expand sidebar",
+ "nav.sidebar_collapse": "Collapse sidebar",
+ "nav.back": "Back",
+ "nav.forward": "Forward",
"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 fe41fb38..d8251597 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -110,8 +110,11 @@
"messages.stop_failed": "停止服务失败",
"messages.restarting": "正在重启服务...",
"messages.logs_cleared": "日志已清空",
+ "nav.sidebar_expand": "展开侧边栏",
+ "nav.sidebar_collapse": "收起侧边栏",
+ "nav.back": "后退",
+ "nav.forward": "前进",
"nav.minimize": "最小化",
"nav.maximize": "最大化",
"nav.background": "后台化"
}
-
diff --git a/src/style/main.css b/src/style/main.css
index 0eaf8a94..0df40d60 100644
--- a/src/style/main.css
+++ b/src/style/main.css
@@ -101,17 +101,20 @@ html[data-theme="light"] {
}
}
-/* ── 顶部导航栏(壳层 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;
+/* ── 顶部导航栏(壳层 ShellNavBar,常驻)────────────────────────
+ 44px、无边框、主题色按钮:左侧为 iframe 导航控制(侧边栏/后退/前进),
+ 右侧为窗口控制(最小化/最大化/后台化),空白区为 Tauri 原生拖拽。 */
+.shell-nav {
+ --shell-nav-ink: #f9fafb;
+ --shell-nav-muted: #adb2b8;
+ --shell-nav-hover: rgba(255, 255, 255, 0.08);
+ --shell-nav-active: rgba(255, 255, 255, 0.12);
+ --shell-nav-line: rgba(255, 255, 255, 0.12);
+ --shell-nav-danger: #f25a5a;
+ position: relative;
+ width: 100%;
+ flex: none;
height: 44px;
display: flex;
align-items: center;
@@ -119,25 +122,19 @@ html[data-theme="light"] {
padding: 0 6px;
box-sizing: border-box;
background: rgb(21, 21, 23);
- border-bottom: 1px solid var(--dsh-tauri-line);
+ border-bottom: 1px solid var(--shell-nav-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);
+html[data-theme="light"] .shell-nav {
+ --shell-nav-ink: #0f1115;
+ --shell-nav-muted: #61666b;
+ --shell-nav-hover: rgba(0, 0, 0, 0.06);
+ --shell-nav-active: rgba(0, 0, 0, 0.1);
+ --shell-nav-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 {
+.shell-nav__btn {
display: inline-flex;
align-items: center;
justify-content: center;
@@ -147,27 +144,27 @@ html[data-theme="light"] .dsh-tauri-nav--shell {
border: none;
border-radius: 8px;
background: transparent;
- color: var(--dsh-tauri-ink);
+ color: var(--shell-nav-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);
+.shell-nav__btn:hover {
+ background: var(--shell-nav-hover);
}
-.dsh-tauri-nav__btn:active {
- background: var(--dsh-tauri-active);
+.shell-nav__btn:active {
+ background: var(--shell-nav-active);
}
-.dsh-tauri-nav__btn[aria-disabled='true'],
-.dsh-tauri-nav__btn:disabled {
- color: var(--dsh-tauri-muted);
+.shell-nav__btn[aria-disabled='true'],
+.shell-nav__btn:disabled {
+ color: var(--shell-nav-muted);
background: transparent;
}
-.dsh-tauri-nav__btn--danger:hover {
+.shell-nav__btn--danger:hover {
background: rgba(242, 90, 90, 0.16);
- color: var(--dsh-tauri-danger);
+ color: var(--shell-nav-danger);
}
-.dsh-tauri-nav__drag {
+.shell-nav__drag {
flex: 1;
align-self: stretch;
min-width: 0;