提交记录新增ui/src/remote-cursor.mjs+23 −0看文件
新增ui/src/remote-cursor.test.mjs+60 −0看文件
修改ui/src/views.jsx+4 −2看文件
| @@ -0,0 +1,23 @@ | ||
| 1 | 新增:// noVNC hides the local cursor until the server supplies a visible shape. | |
| 2 | 新增:// Headless macOS guests may never do so, so keep a native arrow as a fallback. | |
| 3 | 新增:export function installLocalCursorFallback(cursor, enabled) { | |
| 4 | 新增: if (!enabled) return; | |
| 5 | 新增: | |
| 6 | 新增: const change = cursor.change.bind(cursor); | |
| 7 | 新增: const clear = cursor.clear.bind(cursor); | |
| 8 | 新增: const fallback = () => { | |
| 9 | 新增: clear(); | |
| 10 | 新增: cursor._target.style.cursor = "default"; | |
| 11 | 新增: }; | |
| 12 | 新增: | |
| 13 | 新增: cursor.clear = fallback; | |
| 14 | 新增: cursor.change = (rgba, hotx, hoty, w, h) => { | |
| 15 | 新增: for (let i = 3; i < rgba.length; i += 4) { | |
| 16 | 新增: if (rgba[i] !== 0) { | |
| 17 | 新增: change(rgba, hotx, hoty, w, h); | |
| 18 | 新增: return; | |
| 19 | 新增: } | |
| 20 | 新增: } | |
| 21 | 新增: fallback(); | |
| 22 | 新增: }; | |
| 23 | 新增:} | |
| @@ -0,0 +1,60 @@ | ||
| 1 | 新增:import assert from "node:assert/strict"; | |
| 2 | 新增:import test from "node:test"; | |
| 3 | 新增:import { installLocalCursorFallback } from "./remote-cursor.mjs"; | |
| 4 | 新增: | |
| 5 | 新增:function cursorStub() { | |
| 6 | 新增: return { | |
| 7 | 新增: _target: { style: { cursor: "none" } }, | |
| 8 | 新增: changes: [], | |
| 9 | 新增: change(...args) { | |
| 10 | 新增: this.changes.push(args); | |
| 11 | 新增: this._target.style.cursor = "remote"; | |
| 12 | 新增: }, | |
| 13 | 新增: clear() { | |
| 14 | 新增: this._target.style.cursor = "none"; | |
| 15 | 新增: }, | |
| 16 | 新增: }; | |
| 17 | 新增:} | |
| 18 | 新增: | |
| 19 | 新增:const visibleShape = [0, 0, 0, 255]; | |
| 20 | 新增: | |
| 21 | 新增:test("macOS browser fallback remains visible before a remote cursor arrives", () => { | |
| 22 | 新增: const cursor = cursorStub(); | |
| 23 | 新增: cursor._target = null; // RFB attaches its cursor asynchronously after construction. | |
| 24 | 新增: installLocalCursorFallback(cursor, true); | |
| 25 | 新增: cursor._target = { style: { cursor: "none" } }; | |
| 26 | 新增: cursor.clear(); | |
| 27 | 新增: assert.equal(cursor._target.style.cursor, "default"); | |
| 28 | 新增: assert.deepEqual(cursor.changes, []); | |
| 29 | 新增:}); | |
| 30 | 新增: | |
| 31 | 新增:test("macOS browser fallback replaces an empty or transparent remote cursor", () => { | |
| 32 | 新增: const cursor = cursorStub(); | |
| 33 | 新增: installLocalCursorFallback(cursor, true); | |
| 34 | 新增: for (const rgba of [[], [0, 0, 0, 0], [255, 255, 255, 0, 0, 0, 0, 0]]) { | |
| 35 | 新增: cursor.change(rgba, 0, 0, rgba.length / 4, 1); | |
| 36 | 新增: assert.equal(cursor._target.style.cursor, "default"); | |
| 37 | 新增: } | |
| 38 | 新增: assert.deepEqual(cursor.changes, []); | |
| 39 | 新增:}); | |
| 40 | 新增: | |
| 41 | 新增:test("a real remote cursor shape is preserved without fallback pixels", () => { | |
| 42 | 新增: const cursor = cursorStub(); | |
| 43 | 新增: installLocalCursorFallback(cursor, true); | |
| 44 | 新增: cursor.change(visibleShape, 2, 3, 1, 1); | |
| 45 | 新增: assert.equal(cursor._target.style.cursor, "remote"); | |
| 46 | 新增: assert.deepEqual(cursor.changes, [[visibleShape, 2, 3, 1, 1]]); | |
| 47 | 新增:}); | |
| 48 | 新增: | |
| 49 | 新增:test("non-target displays retain noVNC cursor behavior", () => { | |
| 50 | 新增: const cursor = cursorStub(); | |
| 51 | 新增: const change = cursor.change; | |
| 52 | 新增: const clear = cursor.clear; | |
| 53 | 新增: installLocalCursorFallback(cursor, false); | |
| 54 | 新增: assert.equal(cursor.change, change); | |
| 55 | 新增: assert.equal(cursor.clear, clear); | |
| 56 | 新增: cursor.clear(); | |
| 57 | 新增: assert.equal(cursor._target.style.cursor, "none"); | |
| 58 | 新增: cursor.change([], 0, 0, 0, 0); | |
| 59 | 新增: assert.equal(cursor._target.style.cursor, "remote"); | |
| 60 | 新增:}); | |
| @@ -21,6 +21,7 @@ import { sendFiles, shellFilePaths } from "./file-transfer"; | ||
| 21 | 21 | import { installRemoteInput } from "./remote-input"; |
| 22 | 22 | import { useWindowVisibility } from "./window-visibility"; |
| 23 | 23 | import { displayGeometry, displaySizeSync } from "./remote-display.mjs"; |
| 24 | 新增:import { installLocalCursorFallback } from "./remote-cursor.mjs"; | |
| 24 | 25 | import { RefreshCw, Clipboard, ArrowUpRight } from "lucide-react"; |
| 25 | 26 | import { SessionAccount } from "./session-account"; |
| 26 | 27 | import "@xterm/xterm/css/xterm.css"; |
| @@ -88,6 +89,8 @@ export const RemoteView = forwardRef(function RemoteView( | ||
| 88 | 89 | { credentials: { password }, cageBrowserDisplay: !desktop }, |
| 89 | 90 | ); |
| 90 | 91 | rfb.current = client; |
| 92 | 新增: installLocalCursorFallback(client._cursor, | |
| 93 | 新增: !desktop && ["darwin", "macos"].includes(guestPlatform)); | |
| 91 | 94 | client.scaleViewport = true; |
| 92 | 95 | client.resizeSession = false; |
| 93 | 96 | client.background = "#ffffff"; |
| @@ -413,7 +416,7 @@ export function TerminalView({ session, visible, focused = true, onStatus, onCon | ||
| 413 | 416 | void enqueue(async () => { |
| 414 | 417 | const { value, error } = await ready; |
| 415 | 418 | if (error) throw error; |
| 416 | 删除: if (disposed || !visibleRef.current || !focusedRef.current || ws.readyState !== WebSocket.OPEN) throw new Error("终端已切换或断开,请重新粘贴"); | |
| 419 | 新增: if (disposed || !visibleRef.current || !focusedRef.current) throw new Error("终端已切换或断开,请重新粘贴"); | |
| 417 | 420 | let text = value.text || ""; |
| 418 | 421 | if (value.files || value.fileSelection) { |
| 419 | 422 | const result = await sendFiles(value, "terminal", session.id, { valid: () => !disposed && visibleRef.current && focusedRef.current && ws.readyState === WebSocket.OPEN }); |
| @@ -577,7 +580,6 @@ export function TerminalView({ session, visible, focused = true, onStatus, onCon | ||
| 577 | 580 | if (!instance.current) return; |
| 578 | 581 | instance.current.options.theme = terminalTheme(theme, variant); |
| 579 | 582 | instance.current.options.fontFamily = theme.fonts.code || systemCodeFont; |
| 580 | 删除: instance.current.options.fontSize = appearance.codeFontSize; | |
| 581 | 583 | if (visibleRef.current) fit.current?.fit(); |
| 582 | 584 | }, [theme, variant, appearance.codeFontSize]); |
| 583 | 585 | return ( |

