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): 收尾后台画中画失败并限制权限探测等待

Dash0981a66cd58a
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 2159b3157f..c350eae46b 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
@@ -5,6 +5,7 @@ const h = vi.hoisted(() => ({
handlers: new Map<string, any>(),
windows: [] as any[],
deps: null as any,
+ permissionDeps: null as any,
lease: 'lease',
ready: false,
source: null as null | Promise<any[]>,
@@ -111,6 +112,7 @@ vi.mock('../inputHost', () => ({
}));
vi.mock('../permissions', () => ({
RemoteDesktopPermissionsService: class {
+ constructor(deps: any) { h.permissionDeps = deps; }
dismiss() {}
},
}));
@@ -165,6 +167,17 @@ afterEach(() => {
vi.unstubAllGlobals();
});
+it('bounds a stalled screen permission probe so the guide can finish its request', async () => {
+ h.source = new Promise(() => {});
+ const pending = h.permissionDeps.request('screenRecording', () => true, new AbortController().signal);
+ const rejected = expect(pending).rejects.toThrow('DESKTOP_VIDEO_TIMEOUT');
+ await vi.advanceTimersByTimeAsync(5000);
+ await rejected;
+ h.source = Promise.resolve([]);
+ await expect(h.permissionDeps.request('screenRecording', () => true, new AbortController().signal)).resolves.toBeUndefined();
+ expect(h.stop).not.toHaveBeenCalled();
+});
+
it('drops enumeration timeouts for one relay frame and resumes without stopping the host', async () => {
vi.stubGlobal('process', { ...process, platform: 'linux' });
h.source = new Promise(() => {});
diff --git a/apps/desktop/src/main/remote-desktop/index.ts b/apps/desktop/src/main/remote-desktop/index.ts
index 5090ab1775..3c5811f1aa 100644
--- a/apps/desktop/src/main/remote-desktop/index.ts
+++ b/apps/desktop/src/main/remote-desktop/index.ts
@@ -62,10 +62,13 @@ const permissions = new RemoteDesktopPermissionsService({
request: async (permission, isCurrent, signal) => {
if (permission === 'accessibility') await requestDesktopInputPermission(isCurrent, signal);
else
- await desktopCapturer.getSources({
- types: ['screen'],
- thumbnailSize: { width: 0, height: 0 },
- });
+ await enumerateDesktopSources(
+ () => desktopCapturer.getSources({
+ types: ['screen'],
+ thumbnailSize: { width: 0, height: 0 },
+ }),
+ REMOTE_DESKTOP_OFFER_BUDGET.sourcesMs,
+ );
},
openSettings: (permission) =>
shell.openExternal(
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx
index 9a3e4afe6d..e8621a1811 100644
--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx
+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx
@@ -904,6 +904,7 @@ export default function RemoteDesktopScreen() {
void remotePresentation?.playback(false).catch(() => {});
setSettingNotice(t("remoteDesktop.pipUnavailable"));
setOperations(true);
+ if (AppState.currentState === "background") pause();
break;
case "streaming":
setFrameReady(true);
diff --git a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx
index e4742166a1..37f3f16661 100644
--- a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx
+++ b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx
@@ -965,6 +965,30 @@ describe("remote desktop controls", () => {
});
expect(requests().filter((r) => r.op === "start")).toHaveLength(starts);
});
+ it.each(["active", "background"])("handles failed PiP in %s without keeping a hidden stream alive", async (state) => {
+ fixture.systemAudio = true;
+ await connect();
+ expect(sent().find((m) => m.type === "init")).toMatchObject({ audio: true });
+ act(() => fixture.message!({ nativeEvent: { data: JSON.stringify({ type: "presentation", epoch: "lease", active: true }) } }));
+ act(() => {
+ AppState.currentState = state as typeof AppState.currentState;
+ fixture.appState!(state);
+ });
+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);
+ await act(async () => fixture.message!({ nativeEvent: { data: JSON.stringify({ type: "presentationFailed", epoch: "lease" }) } }));
+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(state === "background" ? 1 : 0);
+ if (state === "background") {
+ expect(fixture.playback).toHaveBeenLastCalledWith(false);
+ const count = requests().length;
+ await act(async () => vi.advanceTimersByTimeAsync(30_000));
+ expect(requests()).toHaveLength(count);
+ await act(async () => {
+ AppState.currentState = "active";
+ fixture.appState!("active");
+ });
+ expect(requests().filter((r) => r.op === "start")).toHaveLength(2);
+ }
+ });
it("releases in background and reconnects only after foreground and focus return", async () => {
await connect();
act(() => {