提交记录修改cmd/cage-client/main.go+2 −0看文件
修改cmd/cage/main.go+1 −0看文件
修改docs/troubleshooting.md+1 −0看文件
修改docs/windows.md+1 −1看文件
修改internal/host/runtime_unix.go+4 −0看文件
修改internal/host/runtime_windows.go+11 −0看文件
修改internal/remotehost/local_session.go+1 −2看文件
新增internal/remotehost/local_session_unix.go+7 −0看文件
新增internal/remotehost/local_session_windows.go+6 −0看文件
修改internal/workbench/browser_file_desktop.go+1 −1看文件
修改internal/workbench/platform_unix.go+0 −1看文件
修改internal/workbench/platform_windows.go+0 −3看文件
修改internal/workbench/runtime.go+3 −2看文件
新增ui/scripts/offline-quit-smoke.mjs+51 −0看文件
修改ui/src/account.jsx+0 −9看文件
修改ui/src/api.js+30 −5看文件
修改ui/src/client-context.mjs+1 −1看文件
修改ui/src/client-context.test.mjs+74 −0看文件
修改ui/src/desktop-entry.jsx+6 −0看文件
修改ui/src/main.jsx+12 −2看文件
修改ui/src/remote-hosts.jsx+0 −8看文件
| @@ -16,6 +16,7 @@ import ( | ||
| 16 | 16 | |
| 17 | 17 | "github.com/sylvinus/agent-vm/internal/cage" |
| 18 | 18 | "github.com/sylvinus/agent-vm/internal/diagnostics" |
| 19 | 新增: "github.com/sylvinus/agent-vm/internal/host" | |
| 19 | 20 | "github.com/sylvinus/agent-vm/internal/version" |
| 20 | 21 | "github.com/sylvinus/agent-vm/internal/workbench" |
| 21 | 22 | ) |
| @@ -153,6 +154,7 @@ func relay(config string) error { | ||
| 153 | 154 | defer out.Close() |
| 154 | 155 | defer stderr.Close() |
| 155 | 156 | cmd.Stdout, cmd.Stderr = out, stderr |
| 157 | 新增: host.HideCommandWindow(cmd) | |
| 156 | 158 | if err := cmd.Start(); err != nil { |
| 157 | 159 | return err |
| 158 | 160 | } |
| @@ -586,6 +586,7 @@ func relay(configPath, kind string) int { | ||
| 586 | 586 | stderr := store.Stream(source, "error") |
| 587 | 587 | defer stderr.Close() |
| 588 | 588 | cmd.Stdout, cmd.Stderr = out, stderr |
| 589 | 新增: host.HideCommandWindow(cmd) | |
| 589 | 590 | if err := cmd.Start(); err != nil { |
| 590 | 591 | return fail(err) |
| 591 | 592 | } |
| @@ -134,6 +134,7 @@ Cage 不自动读取主机上的 Claude 登录。请在 Cage 终端运行 `claud | ||
| 134 | 134 | | 网页复制按钮显示成功,本机粘贴仍是旧内容 | 保持网页和 Cage 窗口在前台重试。已有页面若改写了复制 API,可刷新后再试;复杂 DOM 选区、图片、富文本或超长文字可使用复制快捷键及“文本传递”面板。 | |
| 135 | 135 | | 停止后旧终端不见了 | 停止虚拟机会结束进程。磁盘和登录态保留,但需要新建终端。 | |
| 136 | 136 | | 关掉窗口后任务还在运行 | 关闭窗口保留环境;需要结束时选择“停止环境并退出”。 | |
| 137 | 新增:| 已在命令行关闭 Cage 后台,桌面窗口还开着 | 从应用菜单选择“退出 Cage”(Windows 也可使用托盘菜单)。若提示无法确认环境状态,选择“仅退出桌面应用”。重新连接后可查看环境和任务状态。 | | |
| 137 | 138 | | 修改设置后无法正常使用 | “设置 → 环境与恢复”可恢复上一份配置;此操作需要停止并重启环境,已结束的终端不能恢复。 | |
| 138 | 139 | |
| 139 | 140 | ## 页面与出口状态 |
| @@ -37,7 +37,7 @@ DISM /Online /Enable-Feature /FeatureName:HypervisorPlatform /All | ||
| 37 | 37 | |
| 38 | 38 | Windows 快捷键以 `Ctrl` 为主:`Ctrl+O` 打开项目、`Ctrl+T` 新建网页、`Ctrl+L` 定位地址栏、`Ctrl+W` 关闭标签,`Ctrl+Shift+Enter` 新建终端。终端使用 `Ctrl+Shift+C/V` 复制粘贴,`Ctrl+C` 中断命令。网页和编辑器采用 Linux 的 Ctrl 组合键。 |
| 39 | 39 | |
| 40 | 删除:关闭窗口会保留环境与后台任务,可从托盘图标重新打开;停止环境或选择停止后退出会结束终端。重新打开应用可连接仍运行的会话。 | |
| 40 | 新增:从开始菜单打开 Cage 时,完整版和轻量客户端的后台服务都会静默启动。关闭工作台窗口会保留环境与后台任务,可从托盘图标重新打开。要退出桌面程序,在托盘菜单选择“退出 Cage”。本机环境仍在运行时,可以选择保留任务或停止环境;停止环境会结束其中的终端。 | |
| 41 | 41 | |
| 42 | 42 | 浏览器上传通过本机文件选择窗口选取文件;下载完成可用 Windows“另存为”选择位置。侧栏“下载”提供打开文件、在资源管理器中显示与再次另存为,取消保存窗口时保留默认 Downloads 中的文件。操作与限制见[浏览器上传与下载](getting-started.md#浏览器上传与下载)。 |
| 43 | 43 | |
| @@ -2,5 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | package host |
| 4 | 4 | |
| 5 | 新增:import "os/exec" | |
| 6 | 新增: | |
| 7 | 新增:func HideCommandWindow(cmd *exec.Cmd) {} | |
| 8 | 新增: | |
| 5 | 9 | func ConfigureWindowsRuntime() error { return nil } |
| 6 | 10 | func windowsHypervisorReady() error { return nil } |
| @@ -3,14 +3,25 @@ package host | ||
| 3 | 3 | import ( |
| 4 | 4 | "fmt" |
| 5 | 5 | "os" |
| 6 | 新增: "os/exec" | |
| 6 | 7 | "path/filepath" |
| 7 | 8 | "runtime" |
| 8 | 9 | "strings" |
| 10 | 新增: "syscall" | |
| 9 | 11 | "unsafe" |
| 10 | 12 | |
| 11 | 13 | "golang.org/x/sys/windows" |
| 12 | 14 | ) |
| 13 | 15 | |
| 16 | 新增:// HideCommandWindow prevents a background console child from opening a terminal. | |
| 17 | 新增:func HideCommandWindow(cmd *exec.Cmd) { | |
| 18 | 新增: if cmd.SysProcAttr == nil { | |
| 19 | 新增: cmd.SysProcAttr = &syscall.SysProcAttr{} | |
| 20 | 新增: } | |
| 21 | 新增: cmd.SysProcAttr.HideWindow = true | |
| 22 | 新增: cmd.SysProcAttr.CreationFlags |= windows.CREATE_NO_WINDOW | |
| 23 | 新增:} | |
| 24 | 新增: | |
| 14 | 25 | // ConfigureWindowsRuntime uses only the runtime shipped next to cage.exe. |
| 15 | 26 | // The install does not modify the user's system PATH or SSH configuration. |
| 16 | 27 | func ConfigureWindowsRuntime() error { |
| @@ -7,7 +7,6 @@ import ( | ||
| 7 | 7 | "net/http" |
| 8 | 8 | "net/url" |
| 9 | 9 | "sync" |
| 10 | 删除: "syscall" | |
| 11 | 10 | "time" |
| 12 | 11 | ) |
| 13 | 12 | |
| @@ -27,7 +26,7 @@ func LocalSession(ctx context.Context, origin string, manifest PublicManifest, j | ||
| 27 | 26 | return nil, errors.New("本机服务地址已改变") |
| 28 | 27 | } |
| 29 | 28 | conn, err := dial.DialContext(ctx, "tcp4", endpoint) |
| 30 | 删除: if errors.Is(err, syscall.ECONNREFUSED) { | |
| 29 | 新增: if errors.Is(err, connectionRefused) { | |
| 31 | 30 | cancel() |
| 32 | 31 | } |
| 33 | 32 | return conn, err |
| @@ -0,0 +1,7 @@ | ||
| 1 | 新增://go:build !windows | |
| 2 | 新增: | |
| 3 | 新增:package remotehost | |
| 4 | 新增: | |
| 5 | 新增:import "syscall" | |
| 6 | 新增: | |
| 7 | 新增:const connectionRefused = syscall.ECONNREFUSED | |
| @@ -0,0 +1,6 @@ | ||
| 1 | 新增:package remotehost | |
| 2 | 新增: | |
| 3 | 新增:import "golang.org/x/sys/windows" | |
| 4 | 新增: | |
| 5 | 新增:// A refused TCP dial returns the Winsock error, not syscall.ECONNREFUSED. | |
| 6 | 新增:const connectionRefused = windows.WSAECONNREFUSED | |
| @@ -213,7 +213,7 @@ func BrowserFileForConnection(configPath, connectionID, action, id, destination | ||
| 213 | 213 | } |
| 214 | 214 | cmd = exec.Command("gio", "open", path) |
| 215 | 215 | } |
| 216 | 删除: hideCommand(cmd) | |
| 216 | 新增: host.HideCommandWindow(cmd) | |
| 217 | 217 | if err = cmd.Run(); err != nil { |
| 218 | 218 | return result, errors.New("无法打开文件,请通过显示的位置手动查看") |
| 219 | 219 | } |
| @@ -22,7 +22,6 @@ func processExists(pid int) bool { | ||
| 22 | 22 | } |
| 23 | 23 | func terminateLegacy(pid int) error { return syscall.Kill(pid, syscall.SIGTERM) } |
| 24 | 24 | func detachController(cmd *exec.Cmd) { cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} } |
| 25 | 删除:func hideCommand(cmd *exec.Cmd) {} | |
| 26 | 25 | func sshExecutable() string { return "/usr/bin/ssh" } |
| 27 | 26 | func sshEnvironment() []string { |
| 28 | 27 | return []string{"PATH=/usr/bin:/bin:/usr/sbin:/sbin", "LANG=C", "LC_ALL=C", "TERM=xterm-256color"} |
| @@ -34,9 +34,6 @@ func terminateLegacy(pid int) error { | ||
| 34 | 34 | func detachController(cmd *exec.Cmd) { |
| 35 | 35 | cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: windows.CREATE_NEW_PROCESS_GROUP | windows.DETACHED_PROCESS} |
| 36 | 36 | } |
| 37 | 删除:func hideCommand(cmd *exec.Cmd) { | |
| 38 | 删除: cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: windows.CREATE_NO_WINDOW} | |
| 39 | 删除:} | |
| 40 | 37 | func sshExecutable() string { |
| 41 | 38 | exe, _ := os.Executable() |
| 42 | 39 | bundled := filepath.Join(filepath.Dir(exe), "runtime", "openssh", "ssh.exe") |
| @@ -15,6 +15,7 @@ import ( | ||
| 15 | 15 | |
| 16 | 16 | "github.com/sylvinus/agent-vm/internal/cage" |
| 17 | 17 | "github.com/sylvinus/agent-vm/internal/containerenv" |
| 18 | 新增: "github.com/sylvinus/agent-vm/internal/host" | |
| 18 | 19 | "github.com/sylvinus/agent-vm/internal/managedproxy" |
| 19 | 20 | ) |
| 20 | 21 | |
| @@ -68,7 +69,7 @@ func (s *Server) sshCommandOptions(ctx context.Context, maintenance bool, args . | ||
| 68 | 69 | base = append(base, args...) |
| 69 | 70 | cmd := exec.CommandContext(ctx, sshExecutable(), base...) |
| 70 | 71 | cmd.Env = sshEnvironment() |
| 71 | 删除: hideCommand(cmd) | |
| 72 | 新增: host.HideCommandWindow(cmd) | |
| 72 | 73 | return cmd |
| 73 | 74 | } |
| 74 | 75 | func (s *Server) guest(ctx context.Context, script string) ([]byte, error) { |
| @@ -203,7 +204,7 @@ func (s *Server) runCage(args ...string) error { | ||
| 203 | 204 | defer cancel() |
| 204 | 205 | } |
| 205 | 206 | cmd := exec.CommandContext(ctx, s.exe, args...) |
| 206 | 删除: hideCommand(cmd) | |
| 207 | 新增: host.HideCommandWindow(cmd) | |
| 207 | 208 | cmd.Dir = s.environmentDir() |
| 208 | 209 | if cmd.Dir == "" { |
| 209 | 210 | cmd.Dir = s.profile |
| @@ -0,0 +1,51 @@ | ||
| 1 | 新增:import assert from "node:assert/strict"; | |
| 2 | 新增:import { createWorkbench } from "./workbench-fixture.mjs"; | |
| 3 | 新增: | |
| 4 | 新增:const calls = []; | |
| 5 | 新增:const view = { | |
| 6 | 新增: mode: "local", desktop_gateway: true, connection_id: "test-local-view", | |
| 7 | 新增: connection: { state: "connected" }, | |
| 8 | 新增:}; | |
| 9 | 新增:const { page, browser, errors } = await createWorkbench({ | |
| 10 | 新增: clientContext: view, | |
| 11 | 新增: nativeRequest: async (request) => { calls.push(request); return null; }, | |
| 12 | 新增:}); | |
| 13 | 新增:const quit = () => page.evaluate(() => window.cageNativeAction("quit")); | |
| 14 | 新增:const exits = () => calls.filter(({ action }) => action === "quitNow").length; | |
| 15 | 新增:const refused = (route) => route.abort("connectionrefused"); | |
| 16 | 新增:const stops = []; | |
| 17 | 新增:page.on("request", (request) => { | |
| 18 | 新增: if (new URL(request.url()).pathname === "/api/stop") stops.push(request); | |
| 19 | 新增:}); | |
| 20 | 新增:try { | |
| 21 | 新增: await page.exposeFunction("testDesktopExits", exits); | |
| 22 | 新增: // Lose the gateway while the workbench still shows the previous environment. | |
| 23 | 新增: await page.route("**/api/**", refused); | |
| 24 | 新增: await page.locator(".connection-banner").waitFor(); | |
| 25 | 新增: await quit(); | |
| 26 | 新增: const dialog = page.getByRole("dialog", { name: "退出 Cage" }); | |
| 27 | 新增: await dialog.getByRole("button", { name: "取消" }).click(); | |
| 28 | 新增: assert.equal(exits(), 0); | |
| 29 | 新增: await quit(); | |
| 30 | 新增: await dialog.getByRole("button", { name: "仅退出桌面应用" }).click(); | |
| 31 | 新增: await page.waitForFunction(async () => (await window.testDesktopExits()) === 1, null, { timeout: 5000 }); | |
| 32 | 新增: assert.equal(exits(), 1); | |
| 33 | 新增: | |
| 34 | 新增: // Initial context cannot be loaded on reopening the page. | |
| 35 | 新增: await page.reload(); | |
| 36 | 新增: await page.getByRole("alert").getByRole("button", { name: "重新连接" }).waitFor(); | |
| 37 | 新增: await quit(); | |
| 38 | 新增: assert.equal(exits(), 2); | |
| 39 | 新增: | |
| 40 | 新增: // Gateway is alive, but its selected CLI controller has exited. | |
| 41 | 新增: view.connection = { state: "failed", error_code: "connection_lost" }; | |
| 42 | 新增: await page.unroute("**/api/**", refused); | |
| 43 | 新增: await page.reload(); | |
| 44 | 新增: await page.getByRole("heading", { name: "重新连接本机工作台" }).waitFor(); | |
| 45 | 新增: await quit(); | |
| 46 | 新增: assert.equal(exits(), 3); | |
| 47 | 新增: assert.equal(stops.length, 0); | |
| 48 | 新增: assert.deepEqual(errors, []); | |
| 49 | 新增:} finally { | |
| 50 | 新增: await browser.close(); | |
| 51 | 新增:} | |
| @@ -213,15 +213,6 @@ export function AccountGate({ children }) { | ||
| 213 | 213 | setBusy(true); |
| 214 | 214 | deviceAction("unlock", "automatic").catch((e) => setError(e.message)).finally(() => setBusy(false)); |
| 215 | 215 | }, [account?.unlocked, account?.devices?.automatic, account?.require_authentication, deviceSupport]); |
| 216 | 删除: useEffect(() => { | |
| 217 | 删除: if (account?.unlocked) return; | |
| 218 | 删除: window.cageNativeAction = async (action) => { | |
| 219 | 删除: if (action === "quit") await native("quitNow"); | |
| 220 | 删除: }; | |
| 221 | 删除: return () => { | |
| 222 | 删除: delete window.cageNativeAction; | |
| 223 | 删除: }; | |
| 224 | 删除: }, [account?.unlocked]); | |
| 225 | 216 | if (account?.unlocked) return children; |
| 226 | 217 | const creating = account && !account.exists; |
| 227 | 218 | const submit = async (event) => { |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { reportDiagnostic } from "./diagnostics.mjs"; |
| 2 | 2 | import { assertConnection, connectionHeaders, getClientContext } from "./client-context.mjs"; |
| 3 | 3 | let sessionRenewal; |
| 4 | 新增:class WorkbenchUnreachable extends Error {} | |
| 4 | 5 | async function responseError(response) { |
| 5 | 6 | const error = new Error( |
| 6 | 7 | (await response.text()).trim() || "连接未完成,请重试", |
| @@ -38,7 +39,11 @@ export async function api(path, body, method) { | ||
| 38 | 39 | }; |
| 39 | 40 | const send = async () => { |
| 40 | 41 | try { return await fetch("/api" + path, options); } |
| 41 | 删除: catch (error) { reportDiagnostic("frontend", error); throw error; } | |
| 42 | 新增: catch (error) { | |
| 43 | 新增: reportDiagnostic("frontend", error); | |
| 44 | 新增: if (error instanceof TypeError) throw new WorkbenchUnreachable(error.message, { cause: error }); | |
| 45 | 新增: throw error; | |
| 46 | 新增: } | |
| 42 | 47 | }; |
| 43 | 48 | let response = await send(); |
| 44 | 49 | // Authentication fails before a handler runs, so retrying this rejected |
| @@ -89,11 +94,31 @@ export async function uploadFile(path, file, { signal, onProgress } = {}) { | ||
| 89 | 94 | } |
| 90 | 95 | export const nativeAvailable = () => |
| 91 | 96 | Boolean(window.webkit?.messageHandlers?.cage); |
| 97 | 新增:const lostLocalView = (context) => | |
| 98 | 新增: context.desktop_gateway && context.mode === "local" && | |
| 99 | 新增: context.connection?.state === "failed" && context.connection.error_code === "connection_lost"; | |
| 100 | 新增: | |
| 101 | 新增:async function suspendBeforeQuit(context) { | |
| 102 | 新增: if (context.mode !== "local" || context.client_only || lostLocalView(context)) return; | |
| 103 | 新增: try { | |
| 104 | 新增: await api("/account/suspend", {}); | |
| 105 | 新增: } catch (error) { | |
| 106 | 新增: if (error.status === 423) return; | |
| 107 | 新增: // The first request after CLI shutdown can fail before the next context poll. | |
| 108 | 新增: if (context.desktop_gateway && [409, 502].includes(error.status)) { | |
| 109 | 新增: const latest = await api("/client/context"); | |
| 110 | 新增: if (latest.connection_id === context.connection_id && lostLocalView(latest)) return; | |
| 111 | 新增: } | |
| 112 | 新增: throw error; | |
| 113 | 新增: } | |
| 114 | 新增:} | |
| 92 | 115 | export async function native(action, extra = {}) { |
| 93 | 删除: const connection = getClientContext().connection_id; | |
| 94 | 删除: if (action === "quitNow" && getClientContext().mode === "local" && !getClientContext().client_only) { | |
| 95 | 删除: try { await api("/account/suspend", {}); } | |
| 96 | 删除: catch (error) { if (error.status !== 423) throw error; } | |
| 116 | 新增: const context = getClientContext(); | |
| 117 | 新增: const connection = context.connection_id; | |
| 118 | 新增: if (action === "quitNow") { | |
| 119 | 新增: try { await suspendBeforeQuit(context); } | |
| 120 | 新增: catch (error) { if (!(error instanceof WorkbenchUnreachable)) throw error; } | |
| 121 | 新增: assertConnection(connection); | |
| 97 | 122 | } |
| 98 | 123 | try { |
| 99 | 124 | const result = await window.webkit.messageHandlers.cage.postMessage({ action, ...extra, connection_id: connection }); |
| @@ -1,4 +1,4 @@ | ||
| 1 | 删除:let current = Object.freeze({ mode: "local", connection_id: "local" }); | |
| 1 | 新增:let current = Object.freeze({ mode: "none", connection_id: "" }); | |
| 2 | 2 | |
| 3 | 3 | export function setClientContext(value) { |
| 4 | 4 | current = Object.freeze({ ...value }); |
| @@ -52,6 +52,80 @@ test("quitting a remote client never suspends the cloud account", async (t) => { | ||
| 52 | 52 | assert.deepEqual(request, { action: "quitNow", connection_id: "first" }); |
| 53 | 53 | }); |
| 54 | 54 | |
| 55 | 新增:const localGateway = (state) => ({ | |
| 56 | 新增: mode: "local", desktop_gateway: true, connection_id: "local-view", | |
| 57 | 新增: connection: { state, error_code: state === "failed" ? "connection_lost" : "" }, | |
| 58 | 新增:}); | |
| 59 | 新增: | |
| 60 | 新增:test("quit still reaches the desktop after the selected CLI controller exits", async (t) => { | |
| 61 | 新增: environment(t); | |
| 62 | 新增: setClientContext(localGateway("connected")); | |
| 63 | 新增: const calls = []; | |
| 64 | 新增: let status; | |
| 65 | 新增: globalThis.fetch = async (path) => { | |
| 66 | 新增: calls.push(path); | |
| 67 | 新增: if (path === "/api/client/context") return Response.json(localGateway("failed")); | |
| 68 | 新增: return new Response("connection unavailable", { status }); | |
| 69 | 新增: }; | |
| 70 | 新增: window.webkit.messageHandlers.cage.postMessage = ({ action }) => calls.push(action); | |
| 71 | 新增: for (status of [502, 409]) { | |
| 72 | 新增: calls.length = 0; | |
| 73 | 新增: await native("quitNow"); | |
| 74 | 新增: assert.deepEqual(calls, ["/api/account/suspend", "/api/client/context", "quitNow"]); | |
| 75 | 新增: } | |
| 76 | 新增: calls.length = 0; | |
| 77 | 新增: setClientContext(localGateway("failed")); | |
| 78 | 新增: await native("quitNow"); | |
| 79 | 新增: assert.deepEqual(calls, ["quitNow"]); | |
| 80 | 新增:}); | |
| 81 | 新增: | |
| 82 | 新增:test("a disconnected view from another generation cannot authorize a pending quit", async (t) => { | |
| 83 | 新增: environment(t); | |
| 84 | 新增: setClientContext(localGateway("connected")); | |
| 85 | 新增: globalThis.fetch = async (path) => path === "/api/client/context" | |
| 86 | 新增: ? Response.json({ ...localGateway("failed"), connection_id: "replacement" }) | |
| 87 | 新增: : new Response("view changed", { status: 409 }); | |
| 88 | 新增: window.webkit.messageHandlers.cage.postMessage = () => assert.fail("stale quit"); | |
| 89 | 新增: await assert.rejects(native("quitNow"), { status: 409 }); | |
| 90 | 新增:}); | |
| 91 | 新增: | |
| 92 | 新增:test("quit still reaches the desktop when the CLI HTTP listener is gone", async (t) => { | |
| 93 | 新增: environment(t); | |
| 94 | 新增: setClientContext({ mode: "local", connection_id: "local" }); | |
| 95 | 新增: globalThis.fetch = async (path) => { | |
| 96 | 新增: if (path === "/api/diagnostics/events") return Response.json({}); | |
| 97 | 新增: assert.equal(path, "/api/account/suspend"); | |
| 98 | 新增: throw new TypeError("Failed to fetch"); | |
| 99 | 新增: }; | |
| 100 | 新增: const actions = []; | |
| 101 | 新增: window.webkit.messageHandlers.cage.postMessage = ({ action }) => actions.push(action); | |
| 102 | 新增: await native("quitNow"); | |
| 103 | 新增: assert.deepEqual(actions, ["quitNow"]); | |
| 104 | 新增:}); | |
| 105 | 新增: | |
| 106 | 新增:test("a reachable local controller must lock or report already locked before quit", async (t) => { | |
| 107 | 新增: environment(t); | |
| 108 | 新增: setClientContext(localGateway("connected")); | |
| 109 | 新增: window.dispatchEvent = () => {}; | |
| 110 | 新增: const calls = []; | |
| 111 | 新增: let status = 500; | |
| 112 | 新增: globalThis.fetch = async (path) => { | |
| 113 | 新增: calls.push(path); | |
| 114 | 新增: if (path === "/api/client/context") return Response.json(localGateway("connected")); | |
| 115 | 新增: return Response.json({}, { status }); | |
| 116 | 新增: }; | |
| 117 | 新增: window.webkit.messageHandlers.cage.postMessage = ({ action }) => calls.push(action); | |
| 118 | 新增: for (status of [500, 409, 502]) { | |
| 119 | 新增: await assert.rejects(native("quitNow"), { status }); | |
| 120 | 新增: assert.ok(!calls.includes("quitNow")); | |
| 121 | 新增: } | |
| 122 | 新增: for (status of [200, 423]) { | |
| 123 | 新增: calls.length = 0; | |
| 124 | 新增: await native("quitNow"); | |
| 125 | 新增: assert.deepEqual(calls, ["/api/account/suspend", "quitNow"]); | |
| 126 | 新增: } | |
| 127 | 新增:}); | |
| 128 | 新增: | |
| 55 | 129 | test("an account device operation retains its host generation and rejects a late result", async (t) => { |
| 56 | 130 | environment(t); |
| 57 | 131 | let release; |
| @@ -3,11 +3,17 @@ import { createRoot } from "react-dom/client"; | ||
| 3 | 3 | import { installDiagnostics } from "./diagnostics.mjs"; |
| 4 | 4 | import { DiagnosticBoundary } from "./diagnostics.jsx"; |
| 5 | 5 | import { ClientRoot } from "./remote-hosts"; |
| 6 | 新增:import { native } from "./api"; | |
| 6 | 7 | import "./style.css"; |
| 7 | 8 | |
| 8 | 9 | const Workbench = lazy(() => import("./main.jsx")); |
| 9 | 10 | |
| 10 | 11 | installDiagnostics(); |
| 12 | 新增:// Keep the native menu usable while the workbench is loading or disconnected. | |
| 13 | 新增:window.cageNativeAction = (command) => { | |
| 14 | 新增: if (window.cageWorkbenchAction) return window.cageWorkbenchAction(command); | |
| 15 | 新增: if (command === "quit") return native("quitNow"); | |
| 16 | 新增:}; | |
| 11 | 17 | createRoot(document.getElementById("root")).render( |
| 12 | 18 | <DiagnosticBoundary> |
| 13 | 19 | <ClientRoot> |
| @@ -764,7 +764,7 @@ function App() { | ||
| 764 | 764 | return terminalControls.current.get(current.id)?.edit(command) || false; |
| 765 | 765 | return remote.current?.edit(command) || false; |
| 766 | 766 | }; |
| 767 | 删除: window.cageNativeAction = async (command) => { | |
| 767 | 新增: window.cageWorkbenchAction = async (command) => { | |
| 768 | 768 | if (document.querySelector("[data-environment-dialog]")) { |
| 769 | 769 | if (command === "closeTab") document.dispatchEvent(new Event("cage-close-modal")); |
| 770 | 770 | return; |
| @@ -830,6 +830,15 @@ function App() { | ||
| 830 | 830 | await native("quitNow"); |
| 831 | 831 | return; |
| 832 | 832 | } |
| 833 | 新增: if (connectionError || fatal) { | |
| 834 | 新增: setDialog({ | |
| 835 | 新增: title: "退出 Cage", | |
| 836 | 新增: body: "工作台连接已中断,暂时无法确认环境状态。仍在运行的后台任务会继续。", | |
| 837 | 新增: confirm: "仅退出桌面应用", | |
| 838 | 新增: resolve: (confirmed) => confirmed && native("quitNow"), | |
| 839 | 新增: }); | |
| 840 | 新增: return; | |
| 841 | 新增: } | |
| 833 | 842 | setDialog({ |
| 834 | 843 | title: "退出 Cage", |
| 835 | 844 | body: "退出前请保存文件和设置。可以保留环境,让后台任务继续运行;下次打开会重新连接。", |
| @@ -847,7 +856,7 @@ function App() { | ||
| 847 | 856 | }; |
| 848 | 857 | return () => { |
| 849 | 858 | window.removeEventListener("keydown", key, true); |
| 850 | 删除: delete window.cageNativeAction; | |
| 859 | 新增: delete window.cageWorkbenchAction; | |
| 851 | 860 | delete window.cageEditAction; |
| 852 | 861 | }; |
| 853 | 862 | }, [ |
| @@ -863,6 +872,7 @@ function App() { | ||
| 863 | 872 | busy, |
| 864 | 873 | active, |
| 865 | 874 | connectionError, |
| 875 | 新增: fatal, | |
| 866 | 876 | projectDialog, |
| 867 | 877 | rename, |
| 868 | 878 | showHome, |
| @@ -229,14 +229,6 @@ function Environment({ context, refresh, children }) { | ||
| 229 | 229 | }) |
| 230 | 230 | .catch(() => {}); |
| 231 | 231 | } |
| 232 | 删除: if (ready) return; | |
| 233 | 删除: const action = async (name) => { | |
| 234 | 删除: if (name === "quit") await native("quitNow"); | |
| 235 | 删除: }; | |
| 236 | 删除: window.cageNativeAction = action; | |
| 237 | 删除: return () => { | |
| 238 | 删除: if (window.cageNativeAction === action) delete window.cageNativeAction; | |
| 239 | 删除: }; | |
| 240 | 232 | }, [ready, defaultLocal]); |
| 241 | 233 | const act = async (name, operation) => { |
| 242 | 234 | if (runningAction.current) return; |

