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): keep viewer heartbeat after control release

Dashe5806b1eb77d
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
index 1a3e95026f..1e2d248664 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
@@ -13,6 +13,8 @@ const h = vi.hoisted(() => ({
stop: vi.fn(),
nativeStop: vi.fn(),
nativeFrame: vi.fn(async () => 'frame'),
+ input: vi.fn(),
+ viewHeartbeat: vi.fn(),
}));
vi.mock('electron', () => ({
app: { on: vi.fn() },
@@ -87,8 +89,8 @@ vi.mock('../controller', () => ({
this.stop();
}
tick() {}
- input = vi.fn();
- viewHeartbeat = vi.fn();
+ input = h.input;
+ viewHeartbeat = h.viewHeartbeat;
},
}));
vi.mock('../nativeCapture', () => ({
@@ -152,6 +154,8 @@ beforeEach(() => {
h.stop.mockClear();
h.nativeStop.mockClear();
h.nativeFrame.mockClear();
+ h.input.mockReset();
+ h.viewHeartbeat.mockClear();
registerRemoteDesktopIpc();
});
afterEach(() => {
@@ -240,6 +244,25 @@ it('denies main/child-frame capture IPC and forces disposal on offer timeout', a
expect(h.nativeStop).toHaveBeenCalled();
});
+it('drops view-only input without breaking heartbeats, but still rejects invalid or revoked input', async () => {
+ const pending = offer();
+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());
+ await flush();
+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), h.owner.send.mock.calls[0][1].id, 'answer');
+ await pending;
+ const input = h.handlers.get(DESKTOP_LOCAL.INPUT);
+ h.input.mockImplementation(() => { throw new Error('DESKTOP_VIEW_ONLY'); });
+ expect(() => input(event(), 'lease', 1, [{ type: 'release' }])).not.toThrow();
+ h.handlers.get(DESKTOP_LOCAL.VIEW_HEARTBEAT)(event(), 'lease');
+ expect(h.viewHeartbeat).toHaveBeenCalledWith('lease');
+ expect(h.owner.dead).toBe(false);
+ expect(() => input(event(), 'old-lease', 2, [])).toThrow('PERMISSION_DENIED');
+ for (const reason of ['DESKTOP_STOPPED', 'DESKTOP_LEASE_EXPIRED', 'INVALID_REQUEST', 'DESKTOP_INPUT_UNAVAILABLE']) {
+ h.input.mockImplementation(() => { throw new Error(reason); });
+ expect(() => input(event(), 'lease', 2, [])).toThrow('PERMISSION_DENIED');
+ }
+});
+
it('retains the capture owner on ICE timeout and rejects old-owner replies after replacement', async () => {
const pending = offer();
h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());
diff --git a/apps/desktop/src/main/remote-desktop/index.ts b/apps/desktop/src/main/remote-desktop/index.ts
index 6fa553f5d3..5385d91a93 100644
--- a/apps/desktop/src/main/remote-desktop/index.ts
+++ b/apps/desktop/src/main/remote-desktop/index.ts
@@ -551,7 +551,10 @@ export function registerRemoteDesktopIpc(): void {
throwIpcError('PERMISSION_DENIED', 'Invalid desktop host input');
try {
remoteDesktop.input(lease, sequence, events);
- } catch {
+ } catch (error) {
+ // PiP can revoke control before an in-flight input arrives. Drop that
+ // input without closing the DataChannel that also carries view heartbeats.
+ if (error instanceof Error && error.message === 'DESKTOP_VIEW_ONLY') return;
throwIpcError('PERMISSION_DENIED', 'Desktop input rejected');
}
},