Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-desktop): 恢复仅观看主机的前台状态
Dash22803adf029e
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsxindex 068e562a9f..90df912d60 100644--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx@@ -1065,12 +1065,12 @@ export function RemoteDesktopSession({const requestHostControlRef = useRef(requestHostControl);const restoreInlinePresentation = () => {const current = active.current;+ const canControl = capsRef.current?.value.canControl === true;if (!current ||- (current.controlling &&+ ((current.controlling || !canControl) &&!pipPrepared.current &&!foregroundRestorePending.current) ||- !capsRef.current?.value.canControl ||presentation.current ||actualPresentation.current ||!focusedRef.current ||@@ -1094,7 +1094,26 @@ export function RemoteDesktopSession({enabled: pipEnabledRef.current && frameReady,authorized: false,});- // Foreground always retains host control; view only guards input locally.+ if (!canControl) {+ // View-only hosts still need to leave background video/lease policy.+ // A new PiP entry must await this reply before authorizing background again.+ const restoration = request({+ op: "presentation",+ lease: current.lease,+ enabled: false,+ })+ .then(() => {})+ .catch((cause) => {+ if (active.current === current) fail(cause);+ });+ controlRestoration.current = restoration;+ void restoration.finally(() => {+ if (controlRestoration.current === restoration)+ controlRestoration.current = null;+ });+ return;+ }+ // Capable hosts retain foreground control; view only guards input locally.// A temporary release/refusal must not replace that intent. App/route/PiP// events restore immediately; heartbeats retry when a transition was busy// or its request failed, using the same lease and host permission checks.diff --git a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsxindex f832fed3dc..2267f070bb 100644--- a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx@@ -1035,6 +1035,25 @@ describe("remote desktop controls", () => {expect(button("viewOnly").getAttribute("aria-selected")).toBe("false");expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);});+ // Unit regression: portal/view-only hosts still need to leave the host's+ // background video mode. Existing fullscreen tests only used canControl:true.+ it("clears host background viewing immediately on a view-only fullscreen return", async () => {+ fixture.canControl = false;+ fixture.hostPlatform = "linux";+ await retainedViewer();+ expect(+ requests().filter((r) => r.op === "presentation" && r.enabled),+ ).toHaveLength(1);+ await nativePresentation("presentation", { active: false });+ const foregroundRequests = () =>+ requests().filter((r) => r.op === "presentation" && !r.enabled);+ // No heartbeat advance: returning fullscreen must clear background mode.+ expect(foregroundRequests()).toHaveLength(1);+ await act(async () => vi.advanceTimersByTimeAsync(9000));+ expect(foregroundRequests()).toHaveLength(1);+ expect(requests().filter((r) => r.op === "control")).toHaveLength(0);+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);+ });it("does not select view-only or label the viewer as view-only during actual PiP", async () => {await retainedViewer();expect(host.textContent).not.toContain("remoteDesktop.viewOnly");@@ -1368,14 +1387,22 @@ describe("remote desktop controls", () => {expect(button("viewOnly").getAttribute("aria-selected")).toBe("false");},);- it.each(["grant", "timeout"])(- "orders rapid Home entry after pending fullscreen restoration: %s",- async (outcome) => {+ it.each([+ { outcome: "grant", canControl: true },+ { outcome: "timeout", canControl: true },+ { outcome: "grant", canControl: false },+ { outcome: "timeout", canControl: false },+ ])(+ "orders rapid Home entry after pending fullscreen restoration: $outcome, canControl=$canControl",+ async ({ outcome, canControl }) => {+ fixture.canControl = canControl;await retainedViewer();let finish!: (value: unknown) => void;const original = fixture.invoke.getMockImplementation()!;fixture.invoke.mockImplementation((...args) =>- args[2][0].op === "control" && args[2][0].enabled+ (canControl+ ? args[2][0].op === "control" && args[2][0].enabled+ : args[2][0].op === "presentation" && !args[2][0].enabled)? new Promise((resolve) => {finish = resolve;})@@ -1404,31 +1431,43 @@ describe("remote desktop controls", () => {);},);- it("restores fullscreen input as soon as an overlapping sound change settles", async () => {- fixture.systemAudio = true;- await retainedViewer();- const original = fixture.invoke.getMockImplementation()!;- let finish!: () => void;- fixture.invoke.mockImplementation((...args) =>- args[2][0].op === "presentation" && !args[2][0].enabled- ? new Promise((resolve) => {- finish = () => resolve({});- })- : original(...args),- );- act(() => button("operations").click());- await act(async () => button("sound").click());- const controls = () =>- requests().filter((r) => r.op === "control" && r.enabled).length;- const before = controls();- await nativePresentation("presentation", { active: false });- expect(controls()).toBe(before);- await act(async () => finish());- // No timer advance: the settings completion resumes the deferred restore.- expect(controls()).toBe(before + 1);- expect(visibleInputHint()).toBe("remoteDesktop.touchHint");- expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);- });+ it.each([true, false])(+ "restores fullscreen mode after an overlapping sound change, canControl=%s",+ async (canControl) => {+ fixture.canControl = canControl;+ fixture.systemAudio = true;+ await retainedViewer();+ const original = fixture.invoke.getMockImplementation()!;+ let finish!: () => void;+ fixture.invoke.mockImplementation((...args) =>+ args[2][0].op === "presentation" && !args[2][0].enabled+ ? new Promise((resolve) => {+ finish = () => resolve({});+ })+ : original(...args),+ );+ act(() => button("operations").click());+ await act(async () => button("sound").click());+ const restores = () =>+ requests().filter((r) =>+ canControl+ ? r.op === "control" && r.enabled+ : r.op === "presentation" && !r.enabled,+ ).length;+ const before = restores();+ await nativePresentation("presentation", { active: false });+ expect(restores()).toBe(before);+ await act(async () => finish());+ // No timer advance: the settings completion resumes the deferred restore.+ expect(restores()).toBe(before + 1);+ expect(visibleInputHint()).toBe(+ canControl+ ? "remoteDesktop.touchHint"+ : "remoteDesktop.controlUnavailableHint",+ );+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);+ },+ );it("preserves authorized native media while fullscreen signaling reconnects", async () => {const viewer = await retainedViewer();const controls = requests().filter((r) => r.op === "control").length;diff --git a/docs/remote-desktop.md b/docs/remote-desktop.mdindex ec006ddc43..8b3a11e614 100644--- a/docs/remote-desktop.md+++ b/docs/remote-desktop.md@@ -349,15 +349,19 @@ host-side behavior is covered inThe mobile viewer follows the host's control bit instead of rebuilding the session. Arejected input batch, a failed control request or a heartbeat that reports`controlling: false` all stop local input while media and lease identity stay-untouched. In a visible foreground viewer, input rejection and return from PiP-immediately request control through the host's normal permission checks. If+untouched. For control-capable hosts in a visible foreground viewer, input+rejection and return from PiP immediately request control through the host's+normal permission checks. Ifcontrol or settings are still settling, their completion continues the pendingrestore without waiting for a timer. The existing 3-second heartbeat is only afallback after a failed or uncertain attempt; a temporary host refusal does notchange the intent to control. Actual PiP, pending presentation,background/inactive state, route blur, offline signaling and in-flight controlor settings changes defer recovery. The local **View only** choice still blocks-input after host control returns. A dropped+input after host control returns. Hosts without input capability instead send+`presentation enabled:false` on return from PiP, restoring foreground video and+signaling policy without requesting control. A new PiP entry waits for that+reply before authorizing background viewing again. A droppedstalled batch (WebView overflow) also asks the host to drop control: posting`control:false` to the WebView clears its queued release without flushing it, soonly an explicit host `control enabled:false` (which stops the input helper and