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): 清除过期防窥产物并同步主干兼容修复
Dash Huangf0ab3915e3d0
diff --cc apps/desktop/forge.config.tsindex 1686417a5d,e5bc8d3d71..c767abecb9--- a/apps/desktop/forge.config.ts+++ b/apps/desktop/forge.config.ts@@@ -1091,91 -1064,7 +1091,94 @@@ function buildSwiftHelperForForgeArchfunction buildRemoteDesktopInput(platform: ForgePlatform, arch: ForgeArch): void {const destDir = path.join(__dirname, 'resources', 'tools', 'remote-desktop');fs.mkdirSync(destDir, { recursive: true });- if (process.platform === 'darwin' && isMacForgePlatform(platform)) {+ if (process.platform === 'linux' && platform === 'linux') {+ if (arch !== process.arch)+ throw new Error('Linux desktop input requires a native architecture build');+ const temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-linux-input-'));+ try {+ const result = spawnSync(+ process.execPath,+ [path.join(__dirname, 'native', 'remote-desktop', 'linux-input', 'build.mjs'), temporary],+ { stdio: 'inherit' },+ );+ if (result.error || result.status !== 0) throw new Error('Linux desktop input build failed');+ fs.copyFileSync(+ path.join(temporary, 'cindy-linux-desktop-input'),+ path.join(destDir, 'cindy-linux-desktop-input'),+ );+ const capture = spawnSync(+ process.execPath,+ [path.join(__dirname, 'native', 'remote-desktop', 'linux-capture', 'build.mjs'), temporary],+ { stdio: 'inherit' },+ );+ if (capture.error || capture.status !== 0)+ throw new Error('Linux desktop capture build failed');+ fs.copyFileSync(+ path.join(temporary, 'cindy-linux-desktop-capture'),+ path.join(destDir, 'cindy-linux-desktop-capture'),+ );+ const clipboard = spawnSync(+ process.execPath,+ [+ path.join(__dirname, 'native', 'remote-desktop', 'linux-clipboard', 'build.mjs'),+ temporary,+ ],+ { stdio: 'inherit' },+ );+ if (clipboard.error || clipboard.status !== 0)+ throw new Error('Linux desktop clipboard build failed');+ fs.copyFileSync(+ path.join(temporary, 'cindy-linux-desktop-clipboard'),+ path.join(destDir, 'cindy-linux-desktop-clipboard'),+ );+ fs.copyFileSync(+ path.join(__dirname, 'native', 'remote-desktop', 'linux-viewer-display.py'),+ path.join(destDir, 'linux-viewer-display.py'),+ );+ // Optional, ABI-pinned compositor integration. Other Linux distributions+ // still package normally and report privacy unavailable.++ // A skipped optional build must not ship an earlier checkout's plugin.++ for (const extension of ['so', 'json'])++ fs.rmSync(path.join(destDir, `cindy-hyprland-privacy.${extension}`), { force: true });+ const privacyHeaders = spawnSync('pkg-config', ['--modversion', 'hyprland'], {+ encoding: 'utf8',+ });+ if (privacyHeaders.status === 0 && privacyHeaders.stdout.trim() === '0.56.2') {+ const privacy = spawnSync(+ process.execPath,+ [+ path.join(__dirname, 'native', 'remote-desktop', 'hyprland-privacy', 'build.mjs'),+ temporary,+ ],+ { stdio: 'inherit' },+ );+ if (privacy.error || privacy.status !== 0)+ throw new Error('Linux desktop privacy build failed');+ for (const extension of ['so', 'json'])+ fs.copyFileSync(+ path.join(temporary, `cindy-hyprland-privacy.${extension}`),+ path.join(destDir, `cindy-hyprland-privacy.${extension}`),+ );+ }+ const credentialsDir = path.join(destDir, 'linux-credentials');+ fs.mkdirSync(credentialsDir, { recursive: true });+ for (const name of [+ 'main.py',+ 'channel.py',+ 'host.py',+ 'storage.py',+ 'platform_linux.py',+ 'requirements.txt',+ ]) {+ fs.copyFileSync(+ path.join(__dirname, 'native', 'remote-desktop', 'linux-credentials', name),+ path.join(credentialsDir, name),+ );+ }+ } finally {+ fs.rmSync(temporary, { recursive: true, force: true });+ }+ } else if (process.platform === 'darwin' && isMacForgePlatform(platform)) {const dest = path.join(destDir, 'cindy-macos-desktop-input');const inputBuild = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-input-build-'));try {diff --cc apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.tsindex f8d2f1f458,6a43b6aa46..85daacea8c--- a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts+++ b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts@@@ -1,16 -1,11 +1,24 @@@import { afterEach, beforeEach, expect, it, vi } from 'vitest';- import { DESKTOP_LOCAL, type DesktopHostCommand } from '../../../shared/remoteDesktop';-import { DESKTOP_AUDIO_RETRY_MS, DESKTOP_LOCAL } from '../../../shared/remoteDesktop';++import {++ DESKTOP_AUDIO_RETRY_MS,++ DESKTOP_LOCAL,++ type DesktopHostCommand,++} from '../../../shared/remoteDesktop';++ vi.hoisted(() => {+ vi.stubGlobal('process', { ...process, platform: 'darwin', getSystemVersion: () => '26.0' });+ });const h = vi.hoisted(() => ({+ wayland: false,+ hyprland: false,+ linuxInput: false,+ linuxAudio: false,+ audioRead: vi.fn(() => new Uint8Array(8)),+ audioStart: vi.fn(),+ audioStop: vi.fn(),+ hyprlandFrame: vi.fn(async () => 'anBlZw=='),+ hyprlandStop: vi.fn(),handlers: new Map<string, any>(),screenHandlers: new Map<string, any>(),geometryMatches: vi.fn(() => true),@@@ -234,16 -187,7 +242,17 @@@ const flush = async () =>const offer = () =>h.deps.offer({ lease: h.lease, display: { id: '1' } }, 'sdp', undefined, false, 'attempt');beforeEach(() => {++ vi.stubGlobal('process', { ...process, platform: 'darwin', getSystemVersion: () => '26.0' });vi.useFakeTimers();+ h.wayland = false;+ h.hyprland = false;+ h.linuxInput = false;+ h.linuxAudio = false;+ h.audioRead.mockClear();+ h.audioStart.mockClear();+ h.audioStop.mockClear();+ h.hyprlandFrame.mockClear();+ h.hyprlandStop.mockClear();h.handlers.clear();h.screenHandlers.clear();h.geometryMatches.mockReset().mockReturnValue(true);@@@ -692,263 -636,86 +701,347 @@@ it('does not advertise or select Windowawait pending;});+it('keeps Wayland authorization and relay frames alive across bounded offer retries', async () => {+ h.wayland = true;+ const frame = h.deps.frame('wayland-portal', false, 'lease');+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const owner = h.owner;+ expect(owner.send.mock.calls[0][1]).toMatchObject({ op: 'prepare', lease: 'lease' });+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, null);+ await expect(frame).resolves.toBeNull();+ const offer = h.deps.offer({ lease: 'lease', display: { id: 'wayland-portal' } }, 'sdp');+ const rejected = expect(offer).rejects.toThrow('DESKTOP_VIDEO_TIMEOUT');+ await flush();+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, 'anBlZw==');+ await flush();+ await vi.advanceTimersByTimeAsync(18_000);+ await rejected;+ expect(owner.dead).toBe(false);+ expect(owner.send.mock.calls.at(-1)[1]).toMatchObject({ op: 'stop' });+ const fallback = h.deps.frame('wayland-portal', false, 'lease');+ await flush();+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, 'anBlZw==');+ await expect(fallback).resolves.toBe('anBlZw==');+ expect(h.windows).toHaveLength(1);+ expect(+ owner.send.mock.calls.filter(+ ([, command]: [string, DesktopHostCommand]) => command.op === 'prepare',+ ),+ ).toHaveLength(1);+ h.deps.stopVideo();+ expect(owner.dead).toBe(true);+});++it('only grants the system-selected Wayland surface once, and never to a replacement lease', async () => {+ h.wayland = true;+ let select!: (sources: any[]) => void;+ h.source = new Promise((resolve) => {+ select = resolve;+ });+ const frame = h.deps.frame('wayland-portal', false, 'lease');+ const rejected = expect(frame).rejects.toThrow('DESKTOP_VIDEO_STOPPED');+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const owner = h.owner;+ const handler = owner.session.setDisplayMediaRequestHandler.mock.calls[0][0];+ const callback = vi.fn();+ handler({ frame: owner.mainFrame, videoRequested: true, audioRequested: false }, callback);+ expect(callback).not.toHaveBeenCalled();+ const duplicate = vi.fn();+ handler({ frame: owner.mainFrame, videoRequested: true, audioRequested: false }, duplicate);+ expect(duplicate).toHaveBeenCalledWith({});+ h.deps.stopVideo();+ h.lease = 'replacement';+ let selectReplacement!: (sources: any[]) => void;+ h.source = new Promise((resolve) => {+ selectReplacement = resolve;+ });+ const replacementFrame = h.deps.frame('wayland-portal', false, 'replacement');+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const replacementOwner = h.owner;+ const replacementHandler =+ replacementOwner.session.setDisplayMediaRequestHandler.mock.calls[0][0];+ const replacementCallback = vi.fn();+ replacementHandler(+ { frame: replacementOwner.mainFrame, videoRequested: true, audioRequested: false },+ replacementCallback,+ );+ expect(replacementCallback).not.toHaveBeenCalled();+ select([{ id: 'screen:0:0', display_id: '' }]);+ await flush();+ await rejected;+ expect(callback).toHaveBeenCalledExactlyOnceWith({});+ expect(owner.dead).toBe(true);+ const source = { id: 'screen:1:0', display_id: '' };+ selectReplacement([source]);+ await flush();+ expect(replacementCallback).toHaveBeenCalledExactlyOnceWith({ video: source });+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), replacementOwner.send.mock.calls.at(-1)[1].id, null);+ await replacementFrame;+});++it('accepts empty PipeWire display IDs only through the authorized portal selection', async () => {+ h.wayland = true;+ const source = { id: 'screen:0:0', display_id: '' };+ h.source = Promise.resolve([source]);+ const frame = h.deps.frame('wayland-portal', false, 'lease');+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const owner = h.owner;+ const handler = owner.session.setDisplayMediaRequestHandler.mock.calls[0][0];+ const denied = vi.fn();+ handler({ frame: {}, videoRequested: true }, denied);+ expect(denied).toHaveBeenCalledWith({});+ const callback = vi.fn();+ handler({ frame: owner.mainFrame, videoRequested: true, audioRequested: false }, callback);+ await flush();+ expect(callback).toHaveBeenCalledExactlyOnceWith({ video: source });+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, null);+ await frame;+});++it('settles a Wayland offer timeout even if its capture owner disappears before peer cleanup', async () => {+ h.wayland = true;+ const pending = h.deps.offer({ lease: 'lease', display: { id: 'wayland-portal' } }, 'sdp');+ const rejected = expect(pending).rejects.toThrow('DESKTOP_VIDEO_TIMEOUT');+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const owner = h.owner;+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, 'anBlZw==');+ await flush();+ owner.send.mockImplementation(() => {+ throw new Error('destroyed');+ });+ await vi.advanceTimersByTimeAsync(18_000);+ await rejected;+ expect(owner.dead).toBe(true);+});++it('keeps consent outside the offer timeout and starts video after a late selection', async () => {+ h.wayland = true;+ const lease = { lease: 'lease', display: { id: 'wayland-portal' } };+ const waiting = h.deps.offer(lease, 'sdp');+ const rejected = expect(waiting).rejects.toThrow('DESKTOP_CAPTURE_PENDING');+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const owner = h.owner;+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, null);+ await rejected;+ await vi.advanceTimersByTimeAsync(90_000);+ expect(owner.dead).toBe(false);+ expect(+ owner.send.mock.calls.some(+ ([, command]: [string, DesktopHostCommand]) => command.op === 'offer',+ ),+ ).toBe(false);+ const next = h.deps.offer(lease, 'sdp');+ await flush();+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, 'anBlZw==');+ await flush();+ expect(owner.send.mock.calls.at(-1)[1].op).toBe('offer');+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls.at(-1)[1].id, 'answer');+ await expect(next).resolves.toBe('answer');+ expect(h.windows).toHaveLength(1);+});++it('uses native Hyprland capture for video and relay without opening a portal picker', async () => {+ h.wayland = h.hyprland = true;+ // Source enumeration would never resolve: neither transport may depend on it.+ h.source = new Promise(() => {});+ await expect(h.deps.frame('wayland-portal', false, 'lease')).resolves.toBe('anBlZw==');+ expect(h.windows).toHaveLength(0);+ await expect(h.deps.frame('wayland-portal', false, 'wrong')).rejects.toThrow(+ 'DESKTOP_LEASE_EXPIRED',+ );+ expect(h.hyprlandFrame).toHaveBeenCalledTimes(1);+ const result = h.deps.offer({ lease: 'lease', display: { id: 'wayland-portal' } }, 'sdp');+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const command = h.owner.send.mock.calls.at(-1)[1];+ expect(command).toMatchObject({+ op: 'offer',+ nativeCapture: true,+ continuousNativeCapture: true,+ });+ expect(() => structuredClone(command)).not.toThrow();+ expect(command.portalCapture).toBeUndefined();+ await expect(h.handlers.get(DESKTOP_LOCAL.NATIVE_FRAME)(event(), 'lease')).resolves.toBe(+ 'anBlZw==',+ );+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), command.id, 'answer');+ await expect(result).resolves.toBe('answer');+ h.deps.stopVideo();+ expect(h.hyprlandStop).toHaveBeenCalled();+});++it('advertises native Wayland geometry to existing viewers without a 16:9 placeholder', async () => {+ h.wayland = h.hyprland = true;+ const settings = await import('../../device-link/settings-store');+ const { screen } = await import('electron');+ vi.spyOn(settings, 'readDeviceLinkSettings').mockReturnValue({+ remoteDesktopEnabled: true,+ remoteControlEnabled: true,+ } as any);+ vi.spyOn(screen, 'getAllDisplays').mockReturnValue([+ { id: 1, bounds: { x: 0, y: 0, width: 1600, height: 1000 } },+ ] as any);+ expect((await h.deps.capabilities()).displays).toEqual([+ { id: 'hyprland:eDP-2', name: 'eDP-2', width: 1600, height: 1000 },+ ]);+});++it.each([true, false])(+ 'advertises Linux control only after the native protocol probe succeeds: %s',+ async (supported) => {+ const platform = process.platform;+ Object.defineProperty(process, 'platform', { value: 'linux' });+ try {+ h.wayland = h.hyprland = true;+ h.linuxInput = supported;+ const settings = await import('../../device-link/settings-store');+ const { screen } = await import('electron');+ vi.spyOn(settings, 'readDeviceLinkSettings').mockReturnValue({+ remoteDesktopEnabled: true,+ remoteControlEnabled: true,+ } as any);+ vi.spyOn(screen, 'getAllDisplays').mockReturnValue([+ { id: 1, bounds: { x: 0, y: 0, width: 1600, height: 1000 } },+ ] as any);+ expect((await h.deps.capabilities()).canControl).toBe(supported);+ } finally {+ Object.defineProperty(process, 'platform', { value: platform });+ }+ },+);++it.each([false, true])(+ 'refuses native input outside the full Hyprland surface: %s',+ async (hyprland) => {+ const platform = process.platform;+ Object.defineProperty(process, 'platform', { value: 'linux' });+ try {+ h.wayland = true;+ h.hyprland = hyprland;+ h.linuxInput = !hyprland;+ h.startInput.mockClear();+ await expect(h.deps.startInput('wayland-portal')).rejects.toThrow(+ 'DESKTOP_INPUT_UNSUPPORTED',+ );+ expect(h.startInput).not.toHaveBeenCalled();+ h.hyprland = h.linuxInput = true;+ await h.deps.startInput('wayland-portal');+ expect(h.startInput).toHaveBeenCalledExactlyOnceWith('wayland-portal');+ } finally {+ Object.defineProperty(process, 'platform', { value: platform });+ }+ },+);++it('binds Linux audio to the exact capture window, opted-in video lease and stop', async () => {+ h.wayland = h.hyprland = h.linuxAudio = true;+ const result = h.deps.offer({ lease: 'lease', display: { id: 'wayland-portal' } }, 'sdp', {+ audio: true,+ });+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const command = h.owner.send.mock.calls.at(-1)[1];+ expect(command.nativeAudio).toBe(true);+ expect(h.audioStart).toHaveBeenCalledOnce();+ const read = h.handlers.get(DESKTOP_LOCAL.NATIVE_AUDIO);+ expect(read(event(), 'lease')).toHaveLength(8);+ expect(() => read(event({ mainFrame: {} }), 'lease')).toThrow('PERMISSION_DENIED');+ expect(() => read(event(), 'old-lease')).toThrow('PERMISSION_DENIED');+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), command.id, 'answer');+ await result;+ const owner = h.owner;+ h.deps.stopVideo();+ expect(h.audioStop).toHaveBeenCalled();+ expect(() => read(event(owner), 'lease')).toThrow('PERMISSION_DENIED');+ expect(h.audioRead).toHaveBeenCalledOnce();+});+++ it.each([true, false])(+ 'bounds same-screen audio recovery after the initial grant was consumed=%s',+ async (consumed) => {+ const pending = h.deps.offer(+ { lease: h.lease, display: { id: '1' } },+ 'sdp',+ { audio: true, fps: 30, bitrate: 0 },+ true,+ 'attempt',+ );+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const owner = h.owner;+ const grant = owner.session.setDisplayMediaRequestHandler.mock.calls[0][0];+ const callback = vi.fn();+ const request = { frame: owner.mainFrame, videoRequested: true, audioRequested: true };+ if (consumed) {+ grant(request, callback);+ expect(callback).toHaveBeenLastCalledWith({+ video: { id: 'screen:1', display_id: '1' },+ audio: 'loopback',+ });+ }+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls[0][1].id, 'answer');+ await pending;+ // An OS denial can happen before the first display grant is consumed.+ // The answered video lease still permits only bounded audio recovery.+ for (const invalid of [+ { ...request, frame: {} },+ { ...request, audioRequested: false },+ { ...request, videoRequested: false },+ ]) {+ grant(invalid, callback);+ expect(callback).toHaveBeenLastCalledWith({});+ }+ for (let i = consumed ? 1 : 0; i < 1 + DESKTOP_AUDIO_RETRY_MS.length; i++) {+ grant(request, callback);+ expect(callback).toHaveBeenLastCalledWith({+ video: { id: 'screen:1', display_id: '1' },+ audio: 'loopback',+ });+ }+ grant(request, callback);+ expect(callback).toHaveBeenLastCalledWith({});+ expect(owner.dead).toBe(false);+ },+ );++ it('revokes audio recovery with the lease and never grants it to an audio-off replacement', async () => {+ const pending = h.deps.offer(+ { lease: h.lease, display: { id: '1' } },+ 'sdp',+ { audio: true, fps: 30, bitrate: 0 },+ true,+ 'attempt',+ );+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const oldOwner = h.owner;+ const oldGrant = oldOwner.session.setDisplayMediaRequestHandler.mock.calls[0][0];+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), oldOwner.send.mock.calls[0][1].id, 'answer');+ await pending;+ h.lease = 'replacement';+ const callback = vi.fn();+ const oldRequest = { frame: oldOwner.mainFrame, videoRequested: true, audioRequested: true };+ oldGrant(oldRequest, callback);+ expect(callback).toHaveBeenLastCalledWith({});+ const replacement = offer();+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());+ await flush();+ const owner = h.owner;+ const grant = owner.session.setDisplayMediaRequestHandler.mock.calls[0][0];+ oldGrant(oldRequest, callback);+ expect(callback).toHaveBeenLastCalledWith({});+ const request = { ...oldRequest, frame: owner.mainFrame };+ grant(request, callback);+ expect(callback).toHaveBeenLastCalledWith({ video: { id: 'screen:1', display_id: '1' } });+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), owner.send.mock.calls[0][1].id, 'answer');+ await replacement;+ grant(request, callback);+ expect(callback).toHaveBeenLastCalledWith({});+ expect(owner.dead).toBe(false);+ });diff --cc apps/desktop/src/main/remote-desktop/__tests__/linuxPackaging.test.tsindex 0000000000,0000000000..0b46022831new file mode 100644--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxPackaging.test.ts@@@ -1,0 -1,0 +1,67 @@@++import fs from 'node:fs';++import os from 'node:os';++import path from 'node:path';++import vm from 'node:vm';++import { expect, it } from 'vitest';++++const forge = fs.readFileSync(++ path.resolve(import.meta.dirname, '../../../../forge.config.ts'),++ 'utf8',++);++const start = forge.indexOf(' // Optional, ABI-pinned compositor integration.');++const end = forge.indexOf(' const credentialsDir', start);++if (start < 0 || end < 0) throw new Error('Missing Linux privacy packaging block');++const privacyBuild = forge.slice(start, end);++++it.each(['missing', 'mismatch', 'failure', 'success'])(++ 'never packages stale privacy artifacts when the optional build is %s',++ (scenario) => {++ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-privacy-package-'));++ const destDir = path.join(directory, 'resources');++ const temporary = path.join(directory, 'build');++ const names = ['cindy-hyprland-privacy.so', 'cindy-hyprland-privacy.json'];++ fs.mkdirSync(destDir);++ fs.mkdirSync(temporary);++ for (const name of names) fs.writeFileSync(path.join(destDir, name), 'old revision');++ fs.writeFileSync(path.join(destDir, 'cindy-linux-desktop-input'), 'unrelated helper');++ let builds = 0;++ try {++ const run = () =>++ vm.runInNewContext(privacyBuild, {++ fs,++ path,++ destDir,++ temporary,++ __dirname: directory,++ process: { execPath: 'fixture-node' },++ spawnSync(command: string) {++ // Cleanup must precede even the header probe (including probe failure).++ for (const name of names) expect(fs.existsSync(path.join(destDir, name))).toBe(false);++ if (command === 'pkg-config')++ return {++ status: scenario === 'missing' ? 1 : 0,++ stdout: scenario === 'mismatch' ? '0.56.3\n' : '0.56.2\n',++ };++ builds++;++ if (scenario === 'failure') return { status: 1 };++ for (const name of names) fs.writeFileSync(path.join(temporary, name), 'new revision');++ return { status: 0 };++ },++ });++ if (scenario === 'failure') expect(run).toThrow('Linux desktop privacy build failed');++ else run();++ expect(builds).toBe(['success', 'failure'].includes(scenario) ? 1 : 0);++ for (const name of names) {++ const destination = path.join(destDir, name);++ if (scenario === 'success')++ expect(fs.readFileSync(destination, 'utf8')).toBe('new revision');++ else expect(fs.existsSync(destination)).toBe(false);++ }++ expect(fs.readFileSync(path.join(destDir, 'cindy-linux-desktop-input'), 'utf8')).toBe(++ 'unrelated helper',++ );++ } finally {++ fs.rmSync(directory, { recursive: true, force: true });++ }++ },++);diff --cc apps/desktop/src/main/remote-desktop/index.tsindex b0e600c3ac,3271d0f740..ef5f2d9c2a--- a/apps/desktop/src/main/remote-desktop/index.ts+++ b/apps/desktop/src/main/remote-desktop/index.ts@@@ -181,9 -121,14 +182,15 @@@ const supportsPrivacyScreenlet displayAwake: number | null = null;let nativeDisplay: string | null = null;let windowsAvailable = false;- let captureGrant: { source: DesktopCapturerSource; lease: string; audio: boolean } | null = null;+ let captureGrant: {+ source: DesktopCapturerSource;+ lease: string;+ audio: boolean;+ remaining: number;+ used: boolean;+ } | null = null;-const supportsSystemAudio =+const supportsSystemAudio = () =>+ (nativeWayland() && supportsLinuxAudio()) ||process.platform === 'win32' ||(process.platform === 'darwin' &&typeof process.getSystemVersion === 'function' &&@@@ -337,19 -238,20 +344,27 @@@ async function offercurrentHost.isDestroyed())throw new Error('DESKTOP_LEASE_EXPIRED');- if (settings?.audio && !supportsSystemAudio) throw new Error('DESKTOP_AUDIO_UNAVAILABLE');+ if (settings?.audio && !supportsSystemAudio()) throw new Error('DESKTOP_AUDIO_UNAVAILABLE');- captureGrant = source ? { source, lease: lease.lease, audio: settings?.audio === true } : null;+ captureGrant = source+ ? {+ source,+ lease: lease.lease,+ audio: settings?.audio === true,+ remaining: settings?.audio ? 1 + DESKTOP_AUDIO_RETRY_MS.length : 1,+ used: false,+ }+ : null;nativeDisplay = nativeAvailable ? lease.display.id : null;- nativeOverlay = cursorOverlay === true && nativeAvailable;+ nativeOverlay =+ cursorOverlay === true &&+ (process.platform === 'darwin' ||+ (process.platform === 'win32' && nativeAvailable) ||+ (hyprland && (await readLinuxCursorSupport())));+ if (!current() || host !== currentHost || currentHost.isDestroyed())+ throw new Error('DESKTOP_LEASE_EXPIRED');nativeSettings = settings;setVideoLease(lease.lease);+ if (hyprland && settings?.audio) linuxAudio.start();videoAttempt = attemptId;const result = await requestHost({diff --cc apps/desktop/src/renderer/features/remote-desktop/captureHost.tsindex f6e70cbfab,80584060d9..b809a19f96--- a/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts+++ b/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts@@@ -7,10 -7,8 +7,10 @@@ importtype DesktopInput,type RemoteDesktopCursor,} from '@cindy/device-link';- import type { DesktopCaptureApi } from '../../../shared/remoteDesktop';+ import { DESKTOP_AUDIO_RETRY_MS, type DesktopCaptureApi } from '../../../shared/remoteDesktop';import { nativeCaptureStream } from './nativeCaptureStream';+import { PortalCaptureStream } from './portalCaptureStream';+import { nativeAudioStream } from './nativeAudioStream';/** Runs exclusively in the isolated capture renderer; never import into the chat entry. */export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {@@@ -236,27 -220,6 +247,23 @@@return;}stream = captured;+ if (command.nativeAudio && command.settings?.audio && api.nativeAudio) {+ const value = await nativeAudioStream(+ () => api.nativeAudio!(lease),+ () => current === generation,+ () => {+ stop();+ void api.stop().catch(() => {});+ },+ );+ if (current !== generation) {+ value.stop();+ return;+ }+ audio = value;+ captured.addTrack(value.track);+ }- if (command.settings?.audio && !captured.getAudioTracks().length) {- captured.getTracks().forEach((track) => track.stop());- throw new Error('DESKTOP_AUDIO_UNAVAILABLE');- }+ stream = captured;const rtc = new RTCPeerConnection({iceServers: command.iceServers ?? REMOTE_DESKTOP_ICE_SERVERS,});diff --cc apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsxindex 05fe81bc1c,ae02ea4876..fb117af819--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx@@@ -312,11 -308,10 +313,14 @@@ export function RemoteDesktopSession(const unlockFrame = useRef<((presented: boolean) => void) | null>(null);const inputBusy = useRef<string | null>(null);const [lease, setLease] = useState<RemoteDesktopLease | null>(null);+ const [windowsOpen, setWindowsOpen] = useState(false);+ useEffect(() => {+ setWindowsOpen(false);+ }, [lease?.lease, lease?.controlling, focused]);- const [viewerDisplayApplied, setViewerDisplayApplied] = useState(false);+ const [fittedDisplay, setFittedDisplay] = useState<{+ width: number;+ height: number;+ } | null>(null);const [viewerViewport, setViewerViewport] = useState({ width: 0, height: 0 });const viewportGeneration = useRef(0);const matchesViewer = (