Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote-desktop): 画中画保留遮罩时补齐本地退出确认与重新取得操作权失败的收尾

Dash91180e925e8b
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<void>> =>
+ 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' &&