Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 修复远程桌面偶发鼠标消失和输入失效 (#6036)
Dash7d1825e3a9e2
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsxindex a9133d8848..b589622e27 100644--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx@@ -456,6 +456,8 @@ export function RemoteDesktopSession({);const [busy, setBusy] = useState(false);const [inputMode, setInputMode] = useInputModePreference();+ const inputModeRef = useRef(inputMode);+ inputModeRef.current = inputMode;const canInput = Boolean(lease?.controlling) && !viewOnlySelected;const mode: Mode = canInput ? inputMode : "pan";const [operations, setOperations] = useState(false);@@ -1228,7 +1230,12 @@ export function RemoteDesktopSession({videoSettingsRef.current.audio &&!audioUnavailable.current,});- send({ type: "mode", mode });+ // Playback/display preparation can yield after React has already sent+ // the controlling mode. Do not overwrite it with connect's old "pan".+ send({+ type: "mode",+ mode: inputAllowed(next.controlling) ? inputModeRef.current : "pan",+ });// Entering remote desktop is the user's intent to control. The existing// host permission and ownership gates still decide whether it is allowed.if (next.controlling) send({ type: "control", enabled: inputAllowed(true) });@@ -1257,7 +1264,6 @@ export function RemoteDesktopSession({fail,handoff,landscape,- mode,request,resolveControlFailure,send,diff --git a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsxindex bb3bd36cb2..6d330d6756 100644--- a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx@@ -4807,6 +4807,46 @@ describe("remote desktop controls", () => {expect(sent()).toContainEqual({ type: "control", enabled: true });expect(button("keyboard").disabled).toBe(false);});+ it.each(["touch", "pointer"])(+ "keeps %s input after native playback preparation yields a render",+ async (inputMode) => {+ act(() => root.unmount());+ storage.items.set("cindy.mobile.remote-desktop.input-mode.v1", inputMode);+ fixture.nativeMedia = true;+ root = createRoot(host);+ await act(async () => root.render(<RemoteDesktopScreen />));+ autoControl();+ let resumePlayback!: () => void;+ fixture.playback.mockImplementation((enabled) =>+ enabled+ ? new Promise<void>((resolve) => {+ resumePlayback = resolve;+ })+ : Promise.resolve(),+ );+ await act(async () => {+ fixture.message!({ nativeEvent: { data: '{"type":"ready"}' } });+ });+ expect(resumePlayback).toBeTypeOf("function");+ expect(requests().find((request) => request.op === "start")).toMatchObject({+ control: true,+ });+ // React has already published the granted input mode before init.+ expect(sent().filter((message) => message.type === "mode").at(-1)).toEqual({+ type: "mode", mode: inputMode,+ });+ await act(async () => resumePlayback());+ const commands = sent();+ const init = commands.findIndex((message) => message.type === "init");+ expect(init).toBeGreaterThanOrEqual(0);+ expect(+ commands.slice(init).filter((message) => message.type === "mode").at(-1),+ ).toEqual({ type: "mode", mode: inputMode });+ expect(commands.slice(init)).toContainEqual({+ type: "control", enabled: true,+ });+ },+ );const viewerInput = (sequence: number, events: object[]) =>act(async () =>fixture.message!({