From a45d9b39a030621b087a728890853a87f6b114cf Mon Sep 17 00:00:00 2001 From: Dash <125997726+dashhuang@users.noreply.github.com> Date: Tue, 20 Oct 2026 12:37:55 +1300 Subject: [PATCH 1/2] =?UTF-8?q?fix(remote-desktop):=20=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E7=94=BB=E4=B8=AD=E7=94=BB=E6=9C=9F=E9=97=B4=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E7=94=B5=E8=84=91=E9=98=B2=E7=AA=A5=E4=B8=8E=E9=9D=99=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 进入画中画只撤回输入与剪贴板同步;防窥遮罩的有效判据改为同一租约与代次, 不再要求仍在操作,避免交出操作权时撤掉遮罩。 Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com> --- .../__tests__/controller.test.ts | 50 ++++++++++++++++--- .../src/main/remote-desktop/controller.ts | 20 +++++--- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts index e6a7c25831..68e0ef9761 100644 --- a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts +++ b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts @@ -1624,9 +1624,7 @@ describe('remote desktop authority and lifecycle', () => { await h.controller.request('phone', { op: 'hostMute', lease, enabled: true }); await h.controller.request('phone', { op: 'clipboardSync', lease, enabled: true }); if (failed) - vi.mocked(h.deps.startInput).mockRejectedValueOnce( - new Error('DESKTOP_INPUT_UNAVAILABLE'), - ); + vi.mocked(h.deps.startInput).mockRejectedValueOnce(new Error('DESKTOP_INPUT_UNAVAILABLE')); await h.controller.releaseControl(true); expect(h.deps.stopPrivacyScreen).toHaveBeenCalledTimes(failed ? 1 : 0); expect(h.deps.stopHostMute).toHaveBeenCalledTimes(failed ? 1 : 0); @@ -1635,7 +1633,7 @@ describe('remote desktop authority and lifecycle', () => { }, ); }); -it.each(['control', 'presentation', 'failure', 'stop'] as const)( +it.each(['control', 'failure', 'stop'] as const)( 'releases input before failing safety restoration on %s, without stopping replacement input', async (kind) => { const h = harness(), @@ -1652,8 +1650,7 @@ it.each(['control', 'presentation', 'failure', 'stop'] as const)( let result: Promise | undefined; if (kind === 'failure') h.controller.releaseControl(); else if (kind === 'stop') h.controller.stop(); - else - result = h.controller.request('phone', { op: kind, lease, enabled: kind === 'presentation' }); + else result = h.controller.request('phone', { op: kind, lease, enabled: false }); // Critical cleanup cannot wait for slow/failing operating-system restoration. expect(h.deps.stopInput).toHaveBeenCalledOnce(); expect(h.deps.stopPrivacyScreen).toHaveBeenCalledOnce(); @@ -1668,7 +1665,7 @@ it.each(['control', 'presentation', 'failure', 'stop'] as const)( expect(h.controller.state?.controlling).toBe(true); }, ); -it.each(['control', 'presentation', 'failure'] as const)( +it.each(['control', 'failure'] as const)( 'revokes safety effects on %s control loss', async (kind) => { const h = harness(), @@ -1687,12 +1684,49 @@ it.each(['control', 'presentation', 'failure'] as const)( await h.controller.request('phone', { op: 'privacyScreen', lease, enabled: true }); await h.controller.request('phone', { op: 'hostMute', lease, enabled: true }); if (kind === 'failure') h.controller.releaseControl(); - else await h.controller.request('phone', { op: kind, lease, enabled: kind === 'presentation' }); + else await h.controller.request('phone', { op: kind, lease, enabled: false }); expect(h.deps.stopPrivacyScreen).toHaveBeenCalledOnce(); expect(h.deps.stopHostMute).toHaveBeenCalledOnce(); expect(h.deps.stopVideo).not.toHaveBeenCalled(); }, ); +it('keeps privacy and host mute through phone picture-in-picture, stopping only clipboard sync', async () => { + const h = harness(), + { lease } = await h.start(); + let privacyCurrent!: () => boolean; + h.deps.privacyScreen = vi.fn(async (_enabled, current) => { + privacyCurrent = current; + }); + h.deps.hostMute = vi.fn(async () => {}); + h.deps.stopPrivacyScreen = vi.fn(); + h.deps.stopHostMute = vi.fn(async () => {}); + h.deps.clipboardVersion = vi.fn(async () => '1'); + h.deps.stopClipboardVersion = vi.fn(); + await h.controller.request('phone', { op: 'control', lease, enabled: true }); + await h.controller.request('phone', { op: 'privacyScreen', lease, enabled: true }); + await h.controller.request('phone', { op: 'hostMute', lease, enabled: true }); + await h.controller.request('phone', { op: 'clipboardSync', lease, enabled: true }); + await h.controller.request('phone', { op: 'presentation', lease, enabled: true }); + expect(h.controller.state?.controlling).toBe(false); + // Long-lived mask owners (Linux) poll this while the phone shows PiP. + expect(privacyCurrent()).toBe(true); + expect(h.deps.stopPrivacyScreen).not.toHaveBeenCalled(); + expect(h.deps.stopHostMute).not.toHaveBeenCalled(); + expect(h.deps.stopClipboardVersion).toHaveBeenCalledOnce(); + await expect(h.controller.request('phone', { op: 'clipboardVersion', lease })).rejects.toThrow( + 'DESKTOP_CLIPBOARD_UNAVAILABLE', + ); + // Returning from PiP re-sends the unchanged preference and joins the live mask. + await h.controller.request('phone', { op: 'presentation', lease, enabled: false }); + await h.controller.request('phone', { op: 'control', lease, enabled: true }); + await expect( + h.controller.request('phone', { op: 'privacyScreen', lease, enabled: true }), + ).resolves.toEqual({ enabled: true }); + expect(h.deps.privacyScreen).toHaveBeenCalledOnce(); + await h.controller.request('phone', { op: 'stop', lease }); + expect(h.deps.stopPrivacyScreen).toHaveBeenCalledOnce(); + expect(privacyCurrent()).toBe(false); +}); it('joins duplicate privacy initialization and invalidates it on control loss', async () => { const h = harness(), { lease } = await h.start(); diff --git a/apps/desktop/src/main/remote-desktop/controller.ts b/apps/desktop/src/main/remote-desktop/controller.ts index 3962a3cee0..2bc494e811 100644 --- a/apps/desktop/src/main/remote-desktop/controller.ts +++ b/apps/desktop/src/main/remote-desktop/controller.ts @@ -222,12 +222,15 @@ export class RemoteDesktopController { private privacyGeneration = 0; private privacyOperation: { enabled: boolean; promise: Promise<{ enabled: boolean }> } | null = null; - private async clearSafety(): Promise { - this.privacyGeneration++; - this.privacyOperation = null; + private stopClipboardSync(): void { this.syncGeneration++; this.deps.stopClipboardVersion?.(); if (this.active) this.active.clipboardSync = false; + } + private async clearSafety(): Promise { + this.privacyGeneration++; + this.privacyOperation = null; + this.stopClipboardSync(); try { this.deps.stopPrivacyScreen?.(); } finally { @@ -956,11 +959,11 @@ export class RemoteDesktopController { if (this.privacyOperation?.enabled === request.enabled) return this.privacyOperation.promise; const generation = ++this.privacyGeneration; + // Masks outlive control while PiP views the lease; every revocation + // that must expose the desktop clears safety and bumps the generation. const current = () => { this.tick(); - return ( - this.active === active && active.controlling && generation === this.privacyGeneration - ); + return this.active === active && generation === this.privacyGeneration; }; const promise = this.deps .privacyScreen(request.enabled, current) @@ -1119,7 +1122,10 @@ export class RemoteDesktopController { case 'presentation': { this.setBackgroundViewing(active, request.enabled); if (request.enabled) { - await this.revokeControl(); + // PiP keeps watching the same lease: the masked, muted desktop stays + // protected; only input and clipboard sync need control. + await this.revokeControl(true); + this.stopClipboardSync(); } else { this.deps.changed(); } From 91180e925e8b362308bc23267fc7b65a318df4cc Mon Sep 17 00:00:00 2001 From: Dash <125997726+dashhuang@users.noreply.github.com> Date: Tue, 20 Oct 2026 12:59:50 +1300 Subject: [PATCH 2/2] =?UTF-8?q?fix(remote-desktop):=20=E7=94=BB=E4=B8=AD?= =?UTF-8?q?=E7=94=BB=E4=BF=9D=E7=95=99=E9=81=AE=E7=BD=A9=E6=97=B6=E8=A1=A5?= =?UTF-8?q?=E9=BD=90=E6=9C=AC=E5=9C=B0=E9=80=80=E5=87=BA=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E4=B8=8E=E9=87=8D=E6=96=B0=E5=8F=96=E5=BE=97=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=9D=83=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=94=B6=E5=B0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 画中画只看不操作期间,本地退出确认无需暂停输入助手,取消也不恢复远程操作权 - 退出画中画后重新取得操作权失败时,清掉为画中画保留的防窥遮罩与静音 Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com> --- .../__tests__/controller.test.ts | 22 +++++++++++++++++++ .../src/main/remote-desktop/controller.ts | 12 ++++++++++ apps/desktop/src/main/remote-desktop/index.ts | 9 ++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts index 68e0ef9761..59ba87214b 100644 --- a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts +++ b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts @@ -1708,6 +1708,7 @@ it('keeps privacy and host mute through phone picture-in-picture, stopping only await h.controller.request('phone', { op: 'clipboardSync', lease, enabled: true }); await h.controller.request('phone', { op: 'presentation', lease, enabled: true }); expect(h.controller.state?.controlling).toBe(false); + expect(h.controller.viewOnlyBackground).toBe(true); // Long-lived mask owners (Linux) poll this while the phone shows PiP. expect(privacyCurrent()).toBe(true); expect(h.deps.stopPrivacyScreen).not.toHaveBeenCalled(); @@ -1727,6 +1728,27 @@ it('keeps privacy and host mute through phone picture-in-picture, stopping only expect(h.deps.stopPrivacyScreen).toHaveBeenCalledOnce(); expect(privacyCurrent()).toBe(false); }); +it('clears masks kept for picture-in-picture when control cannot be reacquired', async () => { + const h = harness(), + { lease } = await h.start(); + h.deps.privacyScreen = vi.fn(async () => {}); + h.deps.hostMute = vi.fn(async () => {}); + h.deps.stopPrivacyScreen = vi.fn(); + h.deps.stopHostMute = vi.fn(async () => {}); + await h.controller.request('phone', { op: 'control', lease, enabled: true }); + await h.controller.request('phone', { op: 'privacyScreen', lease, enabled: true }); + await h.controller.request('phone', { op: 'hostMute', lease, enabled: true }); + await h.controller.request('phone', { op: 'presentation', lease, enabled: true }); + vi.mocked(h.deps.startInput).mockRejectedValueOnce(new Error('DESKTOP_INPUT_UNAVAILABLE')); + await expect( + h.controller.request('phone', { op: 'presentation', lease, enabled: false }), + ).resolves.toEqual({ controlling: false }); + await expect( + h.controller.request('phone', { op: 'control', lease, enabled: true }), + ).rejects.toThrow('DESKTOP_INPUT_UNAVAILABLE'); + expect(h.deps.stopPrivacyScreen).toHaveBeenCalledOnce(); + expect(h.deps.stopHostMute).toHaveBeenCalledOnce(); +}); it('joins duplicate privacy initialization and invalidates it on control loss', async () => { const h = harness(), { lease } = await h.start(); diff --git a/apps/desktop/src/main/remote-desktop/controller.ts b/apps/desktop/src/main/remote-desktop/controller.ts index 2bc494e811..d37f3fba1d 100644 --- a/apps/desktop/src/main/remote-desktop/controller.ts +++ b/apps/desktop/src/main/remote-desktop/controller.ts @@ -298,6 +298,10 @@ export class RemoteDesktopController { if (active?.handoff?.requestId === requestId) void this.stop(active.peer, false, 'handoff-ended'); } + /** Phone picture-in-picture views the lease without input: nothing to pause or restore. */ + get viewOnlyBackground(): boolean { + return this.active?.backgroundViewing === true && !this.active.controlling; + } isBackgroundViewing(lease: string): boolean { return this.active?.lease === lease && this.active.backgroundViewing === true; } @@ -669,6 +673,14 @@ export class RemoteDesktopController { } this.require(peer, active.lease); active.controlling = true; + } catch (error) { + // Leaving picture-in-picture kept the masks for a viewer about to resume + // control. If it cannot, a view-only lease must not stay masked and muted. + if (!recovering && this.active === active && generation === this.controlGeneration) + await this.clearSafety().catch((restoreError) => + log.warn('Safety restoration failed after control reacquisition', restoreError), + ); + throw error; } finally { this.inputStarting = false; } diff --git a/apps/desktop/src/main/remote-desktop/index.ts b/apps/desktop/src/main/remote-desktop/index.ts index 352327644f..b40b8ed737 100644 --- a/apps/desktop/src/main/remote-desktop/index.ts +++ b/apps/desktop/src/main/remote-desktop/index.ts @@ -176,6 +176,11 @@ let privacyExcluded: number[] = []; let overlayExcluded: number[] = []; const applyExcludedWindows = () => nativeCapture.setExcludedWindows([...privacyExcluded, ...overlayExcluded]); +// While the phone shows picture-in-picture the input helper is stopped on purpose; +// the local exit confirmation then has nothing to pause, and cancelling it must not +// bring remote control back. +const pauseInputForPrivacy = (): Promise<() => Promise> => + remoteDesktop.viewOnlyBackground ? Promise.resolve(async () => {}) : input.pauseForPrivacy(); const privacyScreen = new PrivacyScreen( (ids) => { privacyExcluded = ids; @@ -186,11 +191,11 @@ const privacyScreen = new PrivacyScreen( .stopPrivacyByUser() .catch((error) => console.error('[remote-desktop] privacy exit lock failed', error)); }, - () => input.pauseForPrivacy(), + pauseInputForPrivacy, ); const linuxPrivacy = new LinuxPrivacyScreen( () => remoteDesktop.stopPrivacyByUser(), - () => input.pauseForPrivacy(), + pauseInputForPrivacy, ); const supportsPrivacyScreen = (process.platform === 'darwin' &&