DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(shell): 远端新窗口加载壳层本体——与主窗口同一顶栏,启动即切目标机器
Menghuan191819a2cf4c6b95
diff --git a/src-tauri/src/bridge/remote.rs b/src-tauri/src/bridge/remote.rsindex 2c544397..9fec3d88 100644--- a/src-tauri/src/bridge/remote.rs+++ b/src-tauri/src/bridge/remote.rs@@ -4,9 +4,11 @@//! 任何机器状态;这里只暴露 iframe 内插件做不了的两件事://!//! - `remote_open_window { machineId, url }`:打开(已开则聚焦)label 为-//! `remote-<machineId>` 的专用 WebviewWindow,加载调用方传入的隧道 URL。-//! URL 由插件经 `/api-ssh` 的连接状态给出(`http://127.0.0.1:<port>`),-//! 命令侧再做一次回环校验(纵深防御:桥白名单之外的输入不可信)。+//! `remote-<machineId>` 的专用 WebviewWindow。窗口加载的是壳层应用本体+//! (与主窗口同一套导航栏/切换器),前端按自身 label 解析出 machineId+//! 并在启动时切到该机器——远端界面嵌在壳内呈现,而不是裸加载隧道页。+//! `url`(隧道 URL)仍做回环校验(纵深防御:桥白名单之外的输入不可信,+//! 且未连接机器的调用在第一道就被挡掉)。//! - `remote_bridge_ping`:无参探测。iframe 内的插件(S4 面板)用它判定//! 自己运行在桌面壳内;纯 web 环境下该调用超时/被拒,弹窗按钮自隐藏。//!@@ -71,27 +73,29 @@ fn open_window_args(machine_id: &str, url: &str) -> Result<(String, tauri::Url),Ok((label, parsed_url))}-/// 打开(已开则聚焦)`remote-<machineId>` 弹窗窗口,加载隧道 URL。+/// 打开(已开则聚焦)`remote-<machineId>` 弹窗窗口,加载壳层应用。///-/// 壳不自存机器状态:URL 由插件随调用传入,此处只做回环校验。重复调用-/// 聚焦已有窗口(不重复建窗);失败返回带前缀的可读错误,由调用方(S4-/// 面板按钮)呈现。+/// 壳不自存机器状态:前端按窗口 label 自解析目标机器并切换(机器状态经+/// `/api-ssh` 轮询获取);`url` 只做回环校验。重复调用聚焦已有窗口(不+/// 重复建窗);失败返回带前缀的可读错误,由调用方(S4 面板按钮)呈现。#[tauri::command]pub fn remote_open_window(app_handle: AppHandle,machine_id: String,url: String,) -> Result<(), String> {- let (label, parsed_url) = open_window_args(&machine_id, &url)?;+ let (label, _validated_url) = open_window_args(&machine_id, &url)?;// 已有窗口:聚焦即可(再次「打开」同一机器的语义)。if let Some(existing) = app_handle.get_webview_window(&label) {let _ = existing.set_focus();return Ok(());}+ // 加载壳层应用本体(label 即机器寻址:前端 remote-<id> 自切换);+ // 多窗口按 machineId 分 label 天然并存。WebviewWindowBuilder::new(&app_handle,&label,- WebviewUrl::External(parsed_url),+ WebviewUrl::App("index.html".into()),).title(format!("DSH Remote · {machine_id}")).inner_size(1280.0, 840.0)diff --git a/src/hooks/use-remote-machines.ts b/src/hooks/use-remote-machines.tsindex b616514d..8267668b 100644--- a/src/hooks/use-remote-machines.ts+++ b/src/hooks/use-remote-machines.ts@@ -1,13 +1,35 @@import { useEventListener, useMount } from '@reause/core'+import { getCurrentWindow } from '@tauri-apps/api/window'import { store } from '@/store'+/** 远端弹窗 label 前缀(与 rust remote_open_window 的窗口命名一致)。 */+const REMOTE_WINDOW_LABEL_PREFIX = 'remote-'+/*** 远端机器数据面的组件侧装配:启动轮询(store 内幂等)并挂「窗口聚焦 /* 页面可见」触发的即时刷新。卸载时只摘监听——轮询属于壳层生命周期,由* store 持有(StrictMode 双挂载下 boot 只执行一次)。+ *+ * 远端弹窗(label remote-<machineId>,加载壳层本体)启动即切到目标机器:+ * 本窗口的 store 独立于主窗口,切换只影响本窗口视图。*/export function useRemoteMachines(): void {- useMount(() => store.remote.boot())+ useMount(() => {+ store.remote.boot()+ // 非 tauri 运行时(单测 jsdom)getCurrentWindow 直接抛——按主窗口语义跳过+ let label = ''+ try {+ label = getCurrentWindow().label+ }+ catch {+ label = ''+ }+ if (label.startsWith(REMOTE_WINDOW_LABEL_PREFIX)) {+ const machineId = label.slice(REMOTE_WINDOW_LABEL_PREFIX.length)+ if (machineId !== '')+ void store.remote.openInitialMachine(machineId)+ }+ })function refreshNow() {if (!document.hidden)diff --git a/src/store/modules/remote/store.test.ts b/src/store/modules/remote/store.test.tsindex dea8a134..3aac2257 100644--- a/src/store/modules/remote/store.test.ts+++ b/src/store/modules/remote/store.test.ts@@ -81,6 +81,44 @@ describe('remote store 轮询与降级', () => {})})+describe('remote store 远端弹窗启动寻址', () => {+ it('openInitialMachine:列表为空先拉一轮,已连接机器直接切换', async () => {+ const engine = bindEngine({ list: [[machineOf({ id: 'm1', state: 'connected', tunnelBaseUrl: 'http://127.0.0.1:4001' })]] })+ expect(remote.machines).toHaveLength(0)+ await remote.openInitialMachine('m1')+ expect(engine.listMachines).toHaveBeenCalled()+ expect(remote.activeId).toBe('m1')+ expect(remote.activeTunnelUrl).toBe('http://127.0.0.1:4001')+ })++ it('openInitialMachine:未连接机器走标准连接流程(进度弹窗照常)', async () => {+ // 状态机式 mock:connect 前 disconnected、后 connected(轮询发现就绪)+ let connected = false+ const engine = bindEngine({+ list: [[]],+ connect: vi.fn(async () => {+ connected = true+ return { tunnelBaseUrl: 'http://127.0.0.1:4001' }+ }),+ })+ engine.listMachines.mockImplementation(async () =>+ [machineOf(connected+ ? { id: 'm1', state: 'connected', tunnelBaseUrl: 'http://127.0.0.1:4001' }+ : { id: 'm1', state: 'disconnected' })])+ await remote.openInitialMachine('m1')+ expect(engine.connect).toHaveBeenCalledWith('m1')+ await vi.waitFor(() => expect(remote.activeTunnelUrl).toBe('http://127.0.0.1:4001'))+ expect(remote.activeId).toBe('m1')+ })++ it('openInitialMachine:未知机器静默不切换(label 与列表不符的兜底)', async () => {+ bindEngine({ list: [[]] })+ await remote.openInitialMachine('ghost')+ expect(remote.activeId).toBeNull()+ expect(remote.activeTunnelUrl).toBe('')+ })+})+describe('remote store 切换语义', () => {it('switchTo 已连接机器:立即切换到隧道 URL', async () => {bindEngine({ list: [[machineOf({ id: 'm1', state: 'connected', tunnelBaseUrl: 'http://127.0.0.1:4001' })]] })diff --git a/src/store/modules/remote/store.ts b/src/store/modules/remote/store.tsindex 706c4db1..159fb741 100644--- a/src/store/modules/remote/store.ts+++ b/src/store/modules/remote/store.ts@@ -243,6 +243,17 @@ export const remote = defineStore({}},+ /**+ * 远端弹窗启动寻址:窗口 label 为 remote-<machineId> 时由壳层调用——+ * 列表未载先拉一轮,随后走标准 switchTo(已连接直切;未连接发起连接,+ * 进度弹窗照常)。幂等:重复调用以最后一次为准。+ */+ async openInitialMachine(machineId: string) {+ if (this.machines.length === 0)+ await this.refresh().catch(() => undefined)+ this.switchTo(machineId)+ },+/** 退回本地实例视图(不断开远端连接;同时撤销挂起中的切换)。 */backToLocal() {this.activeId = null