Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(remote-desktop): 补齐 Linux 与 Omarchy 主机能力
Dash Huang9ba27e7fe34e
diff --git a/apps/desktop/forge.config.ts b/apps/desktop/forge.config.tsindex fe7ace53cd..1686417a5d 100644--- a/apps/desktop/forge.config.ts+++ b/apps/desktop/forge.config.ts@@ -22,7 +22,10 @@ import {} from '@cindy/maker-shared/brand-identity';import { stageMacIOSSimulatorHelper } from './forge-ios-simulator-helper';import { stagePackagedThirdPartyNotices } from './forge-third-party-notices';-import { swiftTargetTriple, swiftTargetTriplesForForgeArch } from './src/main/remote-desktop/swiftTarget';+import {+ swiftTargetTriple,+ swiftTargetTriplesForForgeArch,+} from './src/main/remote-desktop/swiftTarget';import { READ_SHEET_RUNTIME_PACKAGES } from '../../packages/lizi-mcps/src/cindy-docs/readSheetRuntimeDeps';import { reviewPdfRuntimePackages } from './src/main/reviewer/reviewPdfRuntimeDeps';import {@@ -70,7 +73,9 @@ function stageCindySourceMetadata(): void {`${JSON.stringify({ sourceCommit, builtAt }, null, 2)}\n`,'utf8',);- console.log(`[forge:prePackage] staged Cindy source metadata (${sourceCommit || 'unknown commit'})`);+ console.log(+ `[forge:prePackage] staged Cindy source metadata (${sourceCommit || 'unknown commit'})`,+ );}function removeCindySourceMetadata(): void {@@ -106,9 +111,7 @@ const UPDATER_EXE = `${BRAND_IDENTITY.updaterName}.exe`;// CommonJS graph crashes when Rollup reorders it. Its dependency tree contains// version conflicts, so it is copied with parent-relative node_modules layout// instead of being flattened into the generic runtime dep list below.-const DISCORD_RUNTIME_DEPS = [- 'discord.js',-];+const DISCORD_RUNTIME_DEPS = ['discord.js'];// Workspace 用 pnpm `node-linker=hoisted`,所有依赖都只在根 node_modules/ 下,// apps/desktop/node_modules/ 里连 symlink 都没建。electron-packager 只扫@@ -353,11 +356,7 @@ function copyDependencyTree(*/function copySqliteVecBinary(buildPath: string, targetPlatform: string, targetArch: string): void {const ext =- targetPlatform === 'win32'- ? 'vec0.dll'- : targetPlatform === 'linux'- ? 'vec0.so'- : 'vec0.dylib';+ targetPlatform === 'win32' ? 'vec0.dll' : targetPlatform === 'linux' ? 'vec0.so' : 'vec0.dylib';const platformDir = `${targetPlatform}-${targetArch}`;const src = path.join(__dirname, 'native', 'sqlite-vec', platformDir, ext);if (!fs.existsSync(src)) {@@ -392,9 +391,8 @@ function bundleNativeDeps(buildPath: string, targetPlatform: string, targetArch:// 不能让它退化到 root 可能 hoist 的 1.7.2。以 node-pty 目录为解析起点。const nodePtyDir = resolvePackageDir('node-pty');for (const dep of deps) {- const src = dep === 'node-addon-api'- ? resolvePackageDir(dep, [nodePtyDir])- : resolvePackageDir(dep);+ const src =+ dep === 'node-addon-api' ? resolvePackageDir(dep, [nodePtyDir]) : resolvePackageDir(dep);const dst = path.join(destModules, dep);// Scoped packages (`@protobufjs/aspromise`) need their `@scope` parent// dir created before cpSync — cpSync only mkdir's the leaf.@@ -435,9 +433,7 @@ async function rebuildNativeDepsInPackage('better_sqlite3.node',);if (!fs.existsSync(sqliteNative)) {- throw new Error(- `[forge:afterCopy] rebuild reported success but ${sqliteNative} is missing`,- );+ throw new Error(`[forge:afterCopy] rebuild reported success but ${sqliteNative} is missing`);}// node-pty 的 .node 在 build/Release/pty.node;Windows 上同名,Linux/macOS 同名。// 跟 better-sqlite3 一样,缺了直接抛出,避免发出无法启动 PTY 的包。@@ -450,9 +446,7 @@ async function rebuildNativeDepsInPackage('pty.node',);if (!fs.existsSync(ptyNative)) {- throw new Error(- `[forge:afterCopy] rebuild reported success but ${ptyNative} is missing`,- );+ throw new Error(`[forge:afterCopy] rebuild reported success but ${ptyNative} is missing`);}// node-pty 被整目录纳入 asar.unpack(为放出 spawn-helper / winpty 等运行时二进制),@@ -478,7 +472,10 @@ async function rebuildNativeDepsInPackage(console.log(`[forge:afterCopy] rebuild ok: ${sqliteNative}, ${ptyNative}`);}-const isDev = process.env.NODE_ENV !== 'production' && !process.argv.includes('make') && !process.argv.includes('package');+const isDev =+ process.env.NODE_ENV !== 'production' &&+ !process.argv.includes('make') &&+ !process.argv.includes('package');const isWin = process.platform === 'win32';/**@@ -535,7 +532,9 @@ function buildCindyUpdater(): void {fs.copyFileSync(builtExe, destExe);const sizeMb = (fs.statSync(destExe).size / (1024 * 1024)).toFixed(2);- console.log(`[forge:prePackage] ${UPDATER_EXE} → ${destExe} (${sizeMb} MB, ${Date.now() - t0}ms)`);+ console.log(+ `[forge:prePackage] ${UPDATER_EXE} → ${destExe} (${sizeMb} MB, ${Date.now() - t0}ms)`,+ );}/**@@ -550,7 +549,8 @@ function findMtExe(): string {for (const base of candidates) {if (!fs.existsSync(base)) continue;// 子目录形如 10.0.22621.0, 取版本号最大的- const versions = fs.readdirSync(base)+ const versions = fs+ .readdirSync(base).filter((d) => /^10\.\d+\.\d+\.\d+$/.test(d)).sort().reverse();@@ -564,7 +564,7 @@ function findMtExe(): string {}throw new Error('[forge] mt.exe not found. Install Windows 10/11 SDK and ensure ' +- '"C:\\Program Files (x86)\\Windows Kits\\10\\bin\\<ver>\\x64\\mt.exe" exists.',+ '"C:\\Program Files (x86)\\Windows Kits\\10\\bin\\<ver>\\x64\\mt.exe" exists.',);}@@ -576,11 +576,9 @@ function patchUpdaterManifest(exePath: string): void {const mt = findMtExe();// -outputresource:<exe>;#1 — 替换 exe 里资源 ID 1 (RT_MANIFEST), 不新增。// tauri-build 已经塞过一个默认 manifest 在 ID 1, 这步把它换成我们的版本。- const r = spawnSync(mt, [- '-nologo',- '-manifest', manifestPath,- `-outputresource:${exePath};#1`,- ], { stdio: 'inherit' });+ const r = spawnSync(mt, ['-nologo', '-manifest', manifestPath, `-outputresource:${exePath};#1`], {+ stdio: 'inherit',+ });if (r.error) throw new Error(`[forge] mt.exe spawn failed: ${r.error.message}`);if (r.status !== 0) throw new Error(`[forge] mt.exe exited ${r.status} when patching manifest`);console.log(`[forge:prePackage] manifest patched into ${UPDATER_EXE} (PCA bypass)`);@@ -617,7 +615,8 @@ function signOneExeWithExternalCommand(exePath: string, commandTemplate: string)console.log(`[forge:sign] signing ${path.basename(exePath)}...`);const r = spawnSync(command, { stdio: 'inherit', shell: true });if (r.error) throw new Error(`[forge:sign] sign command spawn failed: ${r.error.message}`);- if (r.status !== 0) throw new Error(`[forge:sign] sign command exited ${r.status} for ${exePath}`);+ if (r.status !== 0)+ throw new Error(`[forge:sign] sign command exited ${r.status} for ${exePath}`);}/**@@ -733,7 +732,11 @@ function applyMacPackagedDisplayName(buildPath: string, platform: string): void// packager 必写该键,Set 即可;Add 兜底防未来 packager 行为变化。const set = spawnSync('/usr/libexec/PlistBuddy', ['-c', `Set :${key} Cindy`, plistPath]);if (set.status !== 0) {- const add = spawnSync('/usr/libexec/PlistBuddy', ['-c', `Add :${key} string Cindy`, plistPath]);+ const add = spawnSync('/usr/libexec/PlistBuddy', [+ '-c',+ `Add :${key} string Cindy`,+ plistPath,+ ]);if (add.status !== 0) {throw new Error(`[forge:postPackage] PlistBuddy failed to set ${key} in ${plistPath}`);}@@ -784,7 +787,9 @@ function stageRipgrep(targetPlatform: string, targetArch: string): void {stdio: 'inherit',});if (r.status !== 0) {- throw new Error(`[forge] failed to ensure pinned ripgrep ${key}; run "pnpm update:ripgrep" before packaging`);+ throw new Error(+ `[forge] failed to ensure pinned ripgrep ${key}; run "pnpm update:ripgrep" before packaging`,+ );}if (!fs.existsSync(src)) {throw new Error(`[forge] ripgrep still missing at ${src} after ensure`);@@ -824,8 +829,7 @@ function extraResourcesForTarget(targetPlatform: string): string[] {'resources/THIRD-PARTY-RESTRICTED.txt',];- const windowsUpdaterRuntimeResource =- windowsUpdaterRuntimeExtraResourceForTarget(targetPlatform);+ const windowsUpdaterRuntimeResource = windowsUpdaterRuntimeExtraResourceForTarget(targetPlatform);if (windowsUpdaterRuntimeResource) {base.unshift(`resources/${UPDATER_EXE}`,@@ -859,9 +863,13 @@ function assertRealAndroidPlatformTool(filePath: string): void {if (stat.size < 4096) {const prefix = fs.readFileSync(filePath, 'utf8').slice(0, 128);if (prefix.includes('git-lfs.github.com/spec/v1')) {- throw new Error(`[forge] bundled Android platform-tools file is a Git LFS pointer; run "git lfs pull": ${filePath}`);+ throw new Error(+ `[forge] bundled Android platform-tools file is a Git LFS pointer; run "git lfs pull": ${filePath}`,+ );}- throw new Error(`[forge] bundled Android platform-tools file is unexpectedly small (${stat.size} bytes): ${filePath}`);+ throw new Error(+ `[forge] bundled Android platform-tools file is unexpectedly small (${stat.size} bytes): ${filePath}`,+ );}}@@ -911,7 +919,9 @@ function stageAndroidPlatformTools(targetPlatform: string, targetArch: string):if (!fs.existsSync(srcDir)) {fs.rmSync(destDir, { recursive: true, force: true });if (targetPlatform !== 'win32') {- console.log(`[forge:prePackage] Android platform-tools ${key} missing; runtime preparation will download it when needed`);+ console.log(+ `[forge:prePackage] Android platform-tools ${key} missing; runtime preparation will download it when needed`,+ );return;}throw new Error(`[forge] bundled Android platform-tools missing at ${srcDir}`);@@ -1024,15 +1034,27 @@ function compileCObjectForTarget(extraArgs: string[],label: string,): void {- const r = spawnSync('clang', ['-c', src, '-target', target, ...extraArgs, '-o', dest], { stdio: 'inherit' });+ const r = spawnSync('clang', ['-c', src, '-target', target, ...extraArgs, '-o', dest], {+ stdio: 'inherit',+ });if (r.error) throw new Error(`[forge] clang spawn failed for ${label}: ${r.error.message}`);- if (r.status !== 0) throw new Error(`[forge] clang failed for ${label} (${target}) with exit code ${r.status}`);+ if (r.status !== 0)+ throw new Error(`[forge] clang failed for ${label} (${target}) with exit code ${r.status}`);}-function runSwiftcForTarget(src: string, dest: string, target: string, extraArgs: string[], label: string): void {- const r = spawnSync('swiftc', ['-target', target, src, ...extraArgs, '-o', dest], { stdio: 'inherit' });+function runSwiftcForTarget(+ src: string,+ dest: string,+ target: string,+ extraArgs: string[],+ label: string,+): void {+ const r = spawnSync('swiftc', ['-target', target, src, ...extraArgs, '-o', dest], {+ stdio: 'inherit',+ });if (r.error) throw new Error(`[forge] swiftc spawn failed for ${label}: ${r.error.message}`);- if (r.status !== 0) throw new Error(`[forge] swiftc failed for ${label} (${target}) with exit code ${r.status}`);+ if (r.status !== 0)+ throw new Error(`[forge] swiftc failed for ${label} (${target}) with exit code ${r.status}`);}function buildSwiftHelperForForgeArch(@@ -1050,12 +1072,17 @@ function buildSwiftHelperForForgeArch(}const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xdt-swift-helper-'));- const outputs = targets.map((target) => path.join(tempDir, `${path.basename(dest)}-${target.split('-')[0]}`));+ const outputs = targets.map((target) =>+ path.join(tempDir, `${path.basename(dest)}-${target.split('-')[0]}`),+ );try {- targets.forEach((target, index) => runSwiftcForTarget(src, outputs[index], target, extraArgs, label));+ targets.forEach((target, index) =>+ runSwiftcForTarget(src, outputs[index], target, extraArgs, label),+ );const r = spawnSync('lipo', ['-create', ...outputs, '-output', dest], { stdio: 'inherit' });if (r.error) throw new Error(`[forge] lipo spawn failed for ${label}: ${r.error.message}`);- if (r.status !== 0) throw new Error(`[forge] lipo failed for ${label} with exit code ${r.status}`);+ if (r.status !== 0)+ throw new Error(`[forge] lipo failed for ${label} with exit code ${r.status}`);} finally {fs.rmSync(tempDir, { recursive: true, force: true });}@@ -1064,64 +1091,233 @@ function buildSwiftHelperForForgeArch(function 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.+ 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 {const main = path.join(inputBuild, 'main.swift');- const caller = fs.readFileSync(path.resolve(__dirname, '../../packages/remote-credentials-native/Sources/DesktopNativeCaller/DesktopNativeCaller.swift'), 'utf8');- fs.writeFileSync(main, caller + '\n' + fs.readFileSync(path.join(__dirname, 'native', 'remote-desktop', 'macos-input.swift'), 'utf8'));+ const caller = fs.readFileSync(+ path.resolve(+ __dirname,+ '../../packages/remote-credentials-native/Sources/DesktopNativeCaller/DesktopNativeCaller.swift',+ ),+ 'utf8',+ );+ fs.writeFileSync(+ main,+ caller ++ '\n' ++ fs.readFileSync(+ path.join(__dirname, 'native', 'remote-desktop', 'macos-input.swift'),+ 'utf8',+ ),+ );buildSwiftHelperForForgeArch(- main,- dest,- arch,- MACOS_REMOTE_DESKTOP_INPUT_DEPLOYMENT_TARGET,- [],- 'remote desktop input',+ main,+ dest,+ arch,+ MACOS_REMOTE_DESKTOP_INPUT_DEPLOYMENT_TARGET,+ [],+ 'remote desktop input',);- } finally { fs.rmSync(inputBuild, { recursive: true, force: true }); }+ } finally {+ fs.rmSync(inputBuild, { recursive: true, force: true });+ }fs.chmodSync(dest, 0o755);const credentialBuild = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-credential-build-'));try {const root = path.resolve(__dirname, '../../packages/remote-credentials-native');const outputs: string[] = [];for (const target of swiftTargetTriplesForForgeArch(arch, 'macos12.0')) {- const args = ['build', '--package-path', root, '-c', 'release', '--product', 'cindy-macos-remote-credentials',- '--triple', target, '--scratch-path', path.join(credentialBuild, target)];+ const args = [+ 'build',+ '--package-path',+ root,+ '-c',+ 'release',+ '--product',+ 'cindy-macos-remote-credentials',+ '--triple',+ target,+ '--scratch-path',+ path.join(credentialBuild, target),+ ];const compiled = spawnSync('swift', args, { stdio: 'inherit' });- if (compiled.error || compiled.status !== 0) throw new Error('Remote credentials native build failed');+ if (compiled.error || compiled.status !== 0)+ throw new Error('Remote credentials native build failed');const location = spawnSync('swift', [...args, '--show-bin-path'], { encoding: 'utf8' });- if (location.error || location.status !== 0) throw new Error('Remote credentials output unavailable');+ if (location.error || location.status !== 0)+ throw new Error('Remote credentials output unavailable');outputs.push(path.join(location.stdout.trim(), 'cindy-macos-remote-credentials'));}const credential = path.join(destDir, 'cindy-macos-remote-credentials');if (outputs.length === 1) fs.copyFileSync(outputs[0], credential);else {- const result = spawnSync('lipo', ['-create', ...outputs, '-output', credential], { stdio: 'inherit' });- if (result.error || result.status !== 0) throw new Error('Remote credentials universal build failed');+ const result = spawnSync('lipo', ['-create', ...outputs, '-output', credential], {+ stdio: 'inherit',+ });+ if (result.error || result.status !== 0)+ throw new Error('Remote credentials universal build failed');}fs.chmodSync(credential, 0o755);- } finally { fs.rmSync(credentialBuild, { recursive: true, force: true }); }+ } finally {+ fs.rmSync(credentialBuild, { recursive: true, force: true });+ }const capture = path.join(destDir, 'cindy-macos-desktop-capture');- const captureArch = arch === 'universal' ? ['-arch', 'arm64', '-arch', 'x86_64'] : ['-arch', arch === 'arm64' ? 'arm64' : 'x86_64'];- const result = spawnSync('xcrun', ['clang', path.join(__dirname, 'native', 'remote-desktop', 'macos-capture.m'),- ...captureArch, '-mmacosx-version-min=10.15', '-fobjc-arc', '-fblocks', '-O2',- '-framework', 'Foundation', '-framework', 'AppKit', '-framework', 'CoreGraphics', '-framework', 'CoreImage',- '-framework', 'IOSurface', '-framework', 'ImageIO', '-framework', 'IOKit',- '-weak_framework', 'ScreenCaptureKit', '-framework', 'CoreMedia', '-framework', 'CoreVideo', '-o', capture], { stdio: 'inherit' });+ const captureArch =+ arch === 'universal'+ ? ['-arch', 'arm64', '-arch', 'x86_64']+ : ['-arch', arch === 'arm64' ? 'arm64' : 'x86_64'];+ const result = spawnSync(+ 'xcrun',+ [+ 'clang',+ path.join(__dirname, 'native', 'remote-desktop', 'macos-capture.m'),+ ...captureArch,+ '-mmacosx-version-min=10.15',+ '-fobjc-arc',+ '-fblocks',+ '-O2',+ '-framework',+ 'Foundation',+ '-framework',+ 'AppKit',+ '-framework',+ 'CoreGraphics',+ '-framework',+ 'CoreImage',+ '-framework',+ 'IOSurface',+ '-framework',+ 'ImageIO',+ '-framework',+ 'IOKit',+ '-weak_framework',+ 'ScreenCaptureKit',+ '-framework',+ 'CoreMedia',+ '-framework',+ 'CoreVideo',+ '-o',+ capture,+ ],+ { stdio: 'inherit' },+ );if (result.error || result.status !== 0) throw new Error('Remote desktop capture build failed');fs.chmodSync(capture, 0o755);} else if (process.platform === 'win32' && platform === 'win32') {- if (arch !== 'x64' && arch !== 'arm64') throw new Error('Unsupported Windows desktop architecture');+ if (arch !== 'x64' && arch !== 'arm64')+ throw new Error('Unsupported Windows desktop architecture');const target = arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc';for (const helper of ['windows-input', 'windows-host']) {const root = path.join(__dirname, 'native', 'remote-desktop', helper);- const result = spawnSync('cargo', ['build', '--release', '--locked', '--target', target, '--manifest-path', path.join(root, 'Cargo.toml')], { stdio: 'inherit' });- if (result.error || result.status !== 0) throw new Error(`Remote desktop ${helper} build failed`);+ const result = spawnSync(+ 'cargo',+ [+ 'build',+ '--release',+ '--locked',+ '--target',+ target,+ '--manifest-path',+ path.join(root, 'Cargo.toml'),+ ],+ { stdio: 'inherit' },+ );+ if (result.error || result.status !== 0)+ throw new Error(`Remote desktop ${helper} build failed`);const output = path.join(root, 'target', target, 'release');const name = `cindy-windows-desktop-${helper === 'windows-input' ? 'input' : 'host'}`;fs.copyFileSync(path.join(output, `${name}.exe`), path.join(destDir, `${name}.exe`));- if (helper === 'windows-host') fs.copyFileSync(path.join(output, 'cindy_windows_desktop_host.dll'), path.join(destDir, `${name}.node`));+ if (helper === 'windows-host')+ fs.copyFileSync(+ path.join(output, 'cindy_windows_desktop_host.dll'),+ path.join(destDir, `${name}.node`),+ );}}}@@ -1133,36 +1329,74 @@ function buildWindowsGamepadHelper(platform: ForgePlatform, arch: ForgeArch): vofunction buildWindowsTaskbarAddon(platform: ForgePlatform, arch: ForgeArch): void {if (process.platform !== 'win32' || platform !== 'win32') return;- const target = arch === 'arm64' ? 'aarch64-pc-windows-msvc' : arch === 'x64' ? 'x86_64-pc-windows-msvc' : null;+ const target =+ arch === 'arm64' ? 'aarch64-pc-windows-msvc' : arch === 'x64' ? 'x86_64-pc-windows-msvc' : null;if (!target) throw new Error(`[forge] Unsupported Windows taskbar architecture: ${arch}`);const source = path.join(__dirname, 'native', 'windows-taskbar');const build = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-taskbar-build-'));try {const userCargo = path.join(os.homedir(), '.cargo', 'bin', 'cargo.exe');- const result = spawnSync(fs.existsSync(userCargo) ? userCargo : 'cargo', [- 'build', '--release', '--locked', '--target', target,- '--manifest-path', path.join(source, 'Cargo.toml'), '--target-dir', build,- ], { stdio: 'inherit', windowsHide: true });- if (result.error || result.status !== 0) throw new Error(`[forge] Windows taskbar build failed: ${result.error?.message ?? result.status}`);+ const result = spawnSync(+ fs.existsSync(userCargo) ? userCargo : 'cargo',+ [+ 'build',+ '--release',+ '--locked',+ '--target',+ target,+ '--manifest-path',+ path.join(source, 'Cargo.toml'),+ '--target-dir',+ build,+ ],+ { stdio: 'inherit', windowsHide: true },+ );+ if (result.error || result.status !== 0)+ throw new Error(+ `[forge] Windows taskbar build failed: ${result.error?.message ?? result.status}`,+ );const dest = path.join(__dirname, 'resources', 'tools', 'windows-taskbar');fs.mkdirSync(dest, { recursive: true });- fs.copyFileSync(path.join(build, target, 'release', 'cindy_windows_taskbar.dll'), path.join(dest, 'cindy-windows-taskbar.node'));+ fs.copyFileSync(+ path.join(build, target, 'release', 'cindy_windows_taskbar.dll'),+ path.join(dest, 'cindy-windows-taskbar.node'),+ );} finally {fs.rmSync(build, { recursive: true, force: true });}}-function buildWindowsInputHelper(kind: 'gamepad' | 'micro', platform: ForgePlatform, arch: ForgeArch): void {+function buildWindowsInputHelper(+ kind: 'gamepad' | 'micro',+ platform: ForgePlatform,+ arch: ForgeArch,+): void {if (process.platform !== 'win32' || platform !== 'win32') return;- const target = arch === 'arm64' ? 'aarch64-pc-windows-msvc' : arch === 'x64' ? 'x86_64-pc-windows-msvc' : null;+ const target =+ arch === 'arm64' ? 'aarch64-pc-windows-msvc' : arch === 'x64' ? 'x86_64-pc-windows-msvc' : null;if (!target) throw new Error(`[forge] Unsupported Windows gamepad helper architecture: ${arch}`);const group = kind === 'gamepad' ? 'xbox-gamepad' : 'worklouder';const source = path.join(__dirname, 'native', group, `windows-${kind}-helper`);- const userCargo = process.env.USERPROFILE ? path.join(process.env.USERPROFILE, '.cargo', 'bin', 'cargo.exe') : 'cargo';- const result = spawnSync(fs.existsSync(userCargo) ? userCargo : 'cargo', [- 'build', '--locked', '--release', '--target', target, '--manifest-path', path.join(source, 'Cargo.toml'),- ], { stdio: 'inherit', windowsHide: true });- if (result.error || result.status !== 0) throw new Error(`[forge] Windows gamepad helper build failed: ${result.error?.message ?? result.status}`);+ const userCargo = process.env.USERPROFILE+ ? path.join(process.env.USERPROFILE, '.cargo', 'bin', 'cargo.exe')+ : 'cargo';+ const result = spawnSync(+ fs.existsSync(userCargo) ? userCargo : 'cargo',+ [+ 'build',+ '--locked',+ '--release',+ '--target',+ target,+ '--manifest-path',+ path.join(source, 'Cargo.toml'),+ ],+ { stdio: 'inherit', windowsHide: true },+ );+ if (result.error || result.status !== 0)+ throw new Error(+ `[forge] Windows gamepad helper build failed: ${result.error?.message ?? result.status}`,+ );const name = `cindy-windows-${kind}-helper.exe`;const dest = path.join(__dirname, 'resources', 'tools', group);fs.mkdirSync(dest, { recursive: true });@@ -1191,7 +1425,15 @@ function buildMacXboxGamepadHelper(platform: ForgePlatform, arch: ForgeArch): vosrc,output,target,- [object, '-import-objc-header', switch2UsbH, '-framework', 'GameController', '-framework', 'IOKit'],+ [+ object,+ '-import-objc-header',+ switch2UsbH,+ '-framework',+ 'GameController',+ '-framework',+ 'IOKit',+ ],'Xbox gamepad helper',);};@@ -1200,11 +1442,15 @@ function buildMacXboxGamepadHelper(platform: ForgePlatform, arch: ForgeArch): voif (targets.length === 1) {compileOne(dest, targets[0], tempDir);} else {- const outputs = targets.map((target) => path.join(tempDir, `${path.basename(dest)}-${target.split('-')[0]}`));+ const outputs = targets.map((target) =>+ path.join(tempDir, `${path.basename(dest)}-${target.split('-')[0]}`),+ );targets.forEach((target, index) => compileOne(outputs[index], target, tempDir));const r = spawnSync('lipo', ['-create', ...outputs, '-output', dest], { stdio: 'inherit' });- if (r.error) throw new Error(`[forge] lipo spawn failed for Xbox gamepad helper: ${r.error.message}`);- if (r.status !== 0) throw new Error(`[forge] lipo failed for Xbox gamepad helper with exit code ${r.status}`);+ if (r.error)+ throw new Error(`[forge] lipo spawn failed for Xbox gamepad helper: ${r.error.message}`);+ if (r.status !== 0)+ throw new Error(`[forge] lipo failed for Xbox gamepad helper with exit code ${r.status}`);}} finally {fs.rmSync(tempDir, { recursive: true, force: true });@@ -1231,16 +1477,28 @@ function buildMacVoiceInputTextInsertionHelper(platform: ForgePlatform, arch: Fo);fs.chmodSync(dest, 0o755);const sizeMb = (fs.statSync(dest).size / (1024 * 1024)).toFixed(2);- console.log(`[forge:prePackage] macOS voice input text insertion helper (${swiftArchLabel(arch, MACOS_VOICE_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`);+ console.log(+ `[forge:prePackage] macOS voice input text insertion helper (${swiftArchLabel(arch, MACOS_VOICE_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`,+ );}-function buildMacVoiceInputModifierShortcutListener(platform: ForgePlatform, arch: ForgeArch): void {+function buildMacVoiceInputModifierShortcutListener(+ platform: ForgePlatform,+ arch: ForgeArch,+): void {if (process.platform !== 'darwin' || !isMacForgePlatform(platform)) return;- const src = path.join(__dirname, 'native', 'voice-input', 'macos-modifier-shortcut-listener.swift');+ const src = path.join(+ __dirname,+ 'native',+ 'voice-input',+ 'macos-modifier-shortcut-listener.swift',+ );const destDir = path.join(__dirname, 'resources', 'tools', 'voice-input');const dest = path.join(destDir, 'xdt-macos-modifier-shortcut-listener');if (!fs.existsSync(src)) {- throw new Error(`[forge] macOS voice input modifier shortcut listener source missing at ${src}`);+ throw new Error(+ `[forge] macOS voice input modifier shortcut listener source missing at ${src}`,+ );}fs.mkdirSync(destDir, { recursive: true });buildSwiftHelperForForgeArch(@@ -1253,7 +1511,9 @@ function buildMacVoiceInputModifierShortcutListener(platform: ForgePlatform, arc);fs.chmodSync(dest, 0o755);const sizeMb = (fs.statSync(dest).size / (1024 * 1024)).toFixed(2);- console.log(`[forge:prePackage] macOS voice input modifier shortcut listener (${swiftArchLabel(arch, MACOS_VOICE_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`);+ console.log(+ `[forge:prePackage] macOS voice input modifier shortcut listener (${swiftArchLabel(arch, MACOS_VOICE_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`,+ );}function buildWindowsVoiceInputFunctionKeyListener(targetPlatform: string): void {@@ -1342,7 +1602,9 @@ function buildMacAgentIslandHelper(platform: ForgePlatform, arch: ForgeArch): vofs.cpSync(mascotsSrc, mascotsDest, { recursive: true });fs.chmodSync(dest, 0o755);const sizeMb = (fs.statSync(dest).size / (1024 * 1024)).toFixed(2);- console.log(`[forge:prePackage] macOS agent island helper (${swiftArchLabel(arch, MACOS_AGENT_ISLAND_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`);+ console.log(+ `[forge:prePackage] macOS agent island helper (${swiftArchLabel(arch, MACOS_AGENT_ISLAND_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`,+ );}function buildMacComputerPermissionGuideHelper(platform: ForgePlatform, arch: ForgeArch): void {@@ -1369,7 +1631,9 @@ function buildMacComputerPermissionGuideHelper(platform: ForgePlatform, arch: Fo);fs.chmodSync(dest, 0o755);const sizeMb = (fs.statSync(dest).size / (1024 * 1024)).toFixed(2);- console.log(`[forge:prePackage] macOS computer permission guide helper (${swiftArchLabel(arch, MACOS_COMPUTER_PERMISSION_GUIDE_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`);+ console.log(+ `[forge:prePackage] macOS computer permission guide helper (${swiftArchLabel(arch, MACOS_COMPUTER_PERMISSION_GUIDE_HELPER_DEPLOYMENT_TARGET)}) -> ${dest} (${sizeMb} MB)`,+ );}function buildMacSessionDragReleaseHelper(platform: ForgePlatform, arch: ForgeArch): void {@@ -1405,19 +1669,22 @@ function buildMacSessionDragReleaseHelper(platform: ForgePlatform, arch: ForgeAr// avoid import errors on macOS / Linux.const makers: ForgeConfig['makers'] = [new MakerZIP({}, ['darwin']),- new MakerDeb({- options: {- categories: ['Development'],- icon: path.join(__dirname, 'resources', 'icon.png'),- // 双 scheme:cindy 主 + xdt-maker 兼容(老分享链接不死)。- mimeType: allDeepLinkSchemes().map((s) => `x-scheme-handler/${s}`),- maintainer: 'Lizi <[email protected]>',- // deb 包名规范要求小写;跟随区域 exe 名(cn/global cindy / dev cindydev)。- name: CINDY_EXE.toLowerCase(),- bin: CINDY_EXE,- productName: CINDY_EXE,+ new MakerDeb(+ {+ options: {+ categories: ['Development'],+ icon: path.join(__dirname, 'resources', 'icon.png'),+ // 双 scheme:cindy 主 + xdt-maker 兼容(老分享链接不死)。+ mimeType: allDeepLinkSchemes().map((s) => `x-scheme-handler/${s}`),+ maintainer: 'Lizi <[email protected]>',+ // deb 包名规范要求小写;跟随区域 exe 名(cn/global cindy / dev cindydev)。+ name: CINDY_EXE.toLowerCase(),+ bin: CINDY_EXE,+ productName: CINDY_EXE,+ },},- }, ['linux']),+ ['linux'],+ ),];if (isWin) {// eslint-disable-next-line @typescript-eslint/no-require-imports@@ -1441,7 +1708,9 @@ if (isWin) {sign: async (cfg: { path: string }) => {const signCmd = process.env.CINDY_WIN_SIGN_CMD;if (!signCmd) {- console.log(`[forge:nsis:sign] CINDY_WIN_SIGN_CMD not set — skipping ${path.basename(cfg.path)}`);+ console.log(+ `[forge:nsis:sign] CINDY_WIN_SIGN_CMD not set — skipping ${path.basename(cfg.path)}`,+ );return;}signOneExeWithExternalCommand(cfg.path, signCmd);@@ -1516,7 +1785,9 @@ const config: ForgeConfig = {// Windows 上也带 winpty-agent.exe / DLL 等非 .node 二进制;这些都必须 unpack// 到 asar 外才能被 spawn / 动态加载。AutoUnpackNativesPlugin 只 unpack .node,// 所以这里显式覆盖 loudness / node-pty 整个目录。- asar: { unpack: '**/{@img/{sharp-libvips-*,sharp-win32-*},loudness,native/sqlite-vec,node-pty}/**' },+ asar: {+ unpack: '**/{@img/{sharp-libvips-*,sharp-win32-*},loudness,native/sqlite-vec,node-pty}/**',+ },// 打包名(out 目录 / mac .app 包名 / Helper 目录名 / 主 plist CFBundleName)// 按区域派生:cn/global 'Cindy'(2026-07-26 显示名统一,.app 撞名双装// 互覆已被 owner 接受)/ dev 'CindyDev'(显式设值防 packager 回落@@ -1711,8 +1982,13 @@ const config: ForgeConfig = {postPackage: async (_forgeConfig, opts) => {try {for (const buildPath of opts.outputPaths) {- stageLinuxBuildInfo(buildPath, opts.platform, opts.arch,- process.env.APP_VERSION || DESKTOP_PACKAGE_VERSION, CINDY_REGION);+ stageLinuxBuildInfo(+ buildPath,+ opts.platform,+ opts.arch,+ process.env.APP_VERSION || DESKTOP_PACKAGE_VERSION,+ CINDY_REGION,+ );const noticeName = stagePackagedThirdPartyNotices(buildPath, opts.platform);console.log(`[forge:postPackage] staged ${noticeName} + restricted component disclosure`);signPackagedExes(buildPath);@@ -1865,7 +2141,11 @@ const config: ForgeConfig = {config: 'vite.preload.config.ts',target: 'preload',},- { entry: 'src/preload/remoteDesktopViewerPreload.ts', config: 'vite.preload.config.ts', target: 'preload' },+ {+ entry: 'src/preload/remoteDesktopViewerPreload.ts',+ config: 'vite.preload.config.ts',+ target: 'preload',+ },{// 右侧栏独立子窗口专用 preload:最小权限 bridge,不加载主 preload 完整桥。entry: 'src/preload/sidebarWindowPreload.ts',@@ -1904,17 +2184,19 @@ const config: ForgeConfig = {],}),// FusesPlugin conflicts with VitePlugin on `start` command — only load for package/make- ...(isDev ? [] : [- new FusesPlugin({- version: FuseVersion.V1,- [FuseV1Options.RunAsNode]: false,- [FuseV1Options.EnableCookieEncryption]: true,- [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,- [FuseV1Options.EnableNodeCliInspectArguments]: false,- [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,- [FuseV1Options.OnlyLoadAppFromAsar]: true,- }),- ]),+ ...(isDev+ ? []+ : [+ new FusesPlugin({+ version: FuseVersion.V1,+ [FuseV1Options.RunAsNode]: false,+ [FuseV1Options.EnableCookieEncryption]: true,+ [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,+ [FuseV1Options.EnableNodeCliInspectArguments]: false,+ [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,+ [FuseV1Options.OnlyLoadAppFromAsar]: true,+ }),+ ]),],};diff --git a/apps/desktop/native/remote-desktop/hyprland-privacy/build.mjs b/apps/desktop/native/remote-desktop/hyprland-privacy/build.mjsnew file mode 100644index 0000000000..7cd98c405c--- /dev/null+++ b/apps/desktop/native/remote-desktop/hyprland-privacy/build.mjs@@ -0,0 +1,63 @@+import fs from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { spawnSync } from 'node:child_process';+import { createHash } from 'node:crypto';+import sharp from 'sharp';+const root = path.dirname(fileURLToPath(import.meta.url));+const [output] = process.argv.slice(2);+if (!output || !path.isAbsolute(output)) throw new Error('Absolute output directory required');+fs.mkdirSync(output, { recursive: true });+function run(command, args) {+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 120000 });+ if (result.status !== 0) throw new Error(result.stderr || String(result.error));+ return result.stdout.trim();+}+const version = run('pkg-config', ['--modversion', 'hyprland']);+// Internal render/input hooks are deliberately version-bound, never best-effort.+if (version !== '0.56.2') throw new Error('Unsupported Hyprland headers');+const flags = run('pkg-config', ['--cflags', 'hyprland']).split(/\s+/);+const digest = createHash('sha256');+for (const name of ['main.cpp', 'gate.hpp', 'build.mjs'])+ digest.update(fs.readFileSync(path.join(root, name)));+// Embed the exact Mac artwork; no runtime file or network access in Hyprland.+const artwork = [];+for (const [symbol, name] of [+ ['hero', 'illustration.webp'],+ ['wordmarkDark', 'wordmark.png'],+ ['wordmarkLight', 'wordmark-light.png'],+]) {+ const bytes = fs.readFileSync(path.join(root, '../../../src/renderer/assets/splash', name));+ digest.update(bytes);+ const png = await sharp(bytes).png().toBuffer();+ artwork.push(`static const unsigned char ${symbol}Png[] = {${Array.from(png).join(',')}};`);+}+fs.writeFileSync(path.join(output, 'privacy-artwork.hpp'), artwork.join('\n'));+const source = digest.digest('hex');+const temporary = path.join(output, `privacy-${process.pid}.so`);+run('c++', [+ '-std=c++26',+ '-shared',+ '-fPIC',+ '-O2',+ '-Wall',+ '-Wextra',+ `-DCINDY_PRIVACY_SOURCE="${source}"`,+ '-Wno-unused-parameter',+ '-Wno-missing-field-initializers',+ ...flags,+ '-I',+ output,+ path.join(root, 'main.cpp'),+ '-ljson-c',+ '-o',+ temporary,+]);+fs.renameSync(temporary, path.join(output, 'cindy-hyprland-privacy.so'));+const header = fs.readFileSync('/usr/include/hyprland/src/version.h', 'utf8');+const hash = header.match(/#define GIT_COMMIT_HASH\s+"([a-f0-9]+)"/)?.[1];+if (!hash) throw new Error('Missing Hyprland build identity');+fs.writeFileSync(+ path.join(output, 'cindy-hyprland-privacy.json'),+ JSON.stringify({ version, hash, source }),+);diff --git a/apps/desktop/native/remote-desktop/hyprland-privacy/gate.hpp b/apps/desktop/native/remote-desktop/hyprland-privacy/gate.hppnew file mode 100644index 0000000000..b8d91a2dda--- /dev/null+++ b/apps/desktop/native/remote-desktop/hyprland-privacy/gate.hpp@@ -0,0 +1,41 @@+#pragma once+#include <set>++// Only status crosses the process boundary. Never retain text or pointer paths.+struct PrivacyGate {+ enum Phase {+ Off,+ Active,+ Pending,+ Confirming,+ Resume,+ Disconnect+ } phase = Off;+ std::set<unsigned> held;+ bool consume(bool physical, unsigned key, bool down, bool trigger) {+ if (phase == Off)+ return false;+ // Main drains its old helper before presenting confirmation. Let that+ // helper release already-held input, but reject any new press immediately.+ if (!physical)+ return phase != Active && !(phase == Pending && !down && !trigger);+ if (held.contains(key)) {+ if (!down)+ held.erase(key);+ return true;+ }+ // Release a key/button pressed before privacy started. Dropping that edge+ // would leave the underlying application with a permanently held input.+ if (phase == Active && !down && !trigger)+ return false;+ if (phase == Active && trigger)+ phase = Pending;+ if (down)+ held.insert(key);+ return true;+ }+ void stop() {+ phase = Off;+ held.clear();+ }+};diff --git a/apps/desktop/native/remote-desktop/hyprland-privacy/main.cpp b/apps/desktop/native/remote-desktop/hyprland-privacy/main.cppnew file mode 100644index 0000000000..5d4d3f0d88--- /dev/null+++ b/apps/desktop/native/remote-desktop/hyprland-privacy/main.cpp@@ -0,0 +1,695 @@+#include "gate.hpp"+#include "privacy-artwork.hpp"+#include <chrono>+#include <dlfcn.h>+#include <hyprland/src/Compositor.hpp>+#include <hyprland/src/managers/input/InputManager.hpp>+#include <hyprland/src/plugins/PluginAPI.hpp>+#include <hyprland/src/pointer/PointerManager.hpp>+#include <hyprland/src/pointer/cursor/CursorManager.hpp>+#include <hyprland/src/render/OpenGL.hpp>+#include <hyprland/src/render/Renderer.hpp>+#include <hyprland/src/state/MonitorState.hpp>+#include <json-c/json.h>+#include <linux/input-event-codes.h>+#include <unistd.h>++using namespace Render;+using namespace Render::GL;+using Monitor::CMonitor;+static std::string stringValue(json_object *value) {+ if (!value || !json_object_is_type(value, json_type_string))+ throw std::runtime_error("string");+ std::string result = json_object_get_string(value);+ if (result.size() != static_cast<size_t>(json_object_get_string_len(value)))+ throw std::runtime_error("nul");+ return result;+}+static HANDLE owner;+static PrivacyGate gate;+static bool retired = false;+static bool loading = true;+static std::string token;+static std::chrono::steady_clock::time_point heartbeat;+static wl_event_source *watchdog = nullptr;+static SP<SHyprCtlCommand> command;+static std::vector<CHyprSignalListener> listeners;+static CFunctionHook *copyHook, *needsCopyHook, *keyHook, *modHook, *buttonHook, *axisHook,+ *moveHook, *warpHook, *scanoutHook;+static CFunctionHook *sharedModsHook, *allModsHook, *sharedKeysHook;+static CFunctionHook *cursorRenderHook, *cursorClearHook, *cursorReadHook;+static bool renderingCursor = false, cursorAllowed = false;+static WP<IFramebuffer> cursorFramebuffer;+static CFunctionHook *cursorConstraintsHook;+static void (*sendCursorEvents)(void *);+static CFunctionHook *softwareCursorHook;+static CRenderPass deferredCursor;+static PHLMONITORREF deferredCursorMonitor;+static void mirroredCursor() {+ auto monitor = g_pHyprRenderer->m_renderData.pMonitor.lock();+ if (!monitor || !monitor->m_mirrorOf || !g_pHyprRenderer->shouldRenderCursor())+ return;+ auto source = monitor->m_mirrorOf.lock();+ auto texture = Pointer::mgr()->getCurrentCursorTexture();+ if (!texture)+ return;+ // Mirrors now receive a cursor-free source too. Restore their visible cursor+ // using the same centered aspect-fit placement as the mirrored desktop.+ auto box = Pointer::mgr()->getCursorBoxGlobal();+ if (!box.overlaps(CBox{source->m_position, source->m_size}))+ return;+ const double fit = std::min(monitor->m_transformedSize.x / source->m_transformedSize.x,+ monitor->m_transformedSize.y / source->m_transformedSize.y);+ box.translate(-source->m_position).scale(source->m_scale * fit)+ .translate((monitor->m_transformedSize - source->m_transformedSize * fit) / 2);+ if (!texture->m_imageDescription)+ texture->m_imageDescription = NColorManagement::DEFAULT_SRGB_IMAGE_DESCRIPTION;+ auto element = makeUnique<CTexPassElement>(CTexPassElement::SRenderData{.tex = texture, .box = box.round()});+ if (monitor->needsACopyFB()) {+ deferredCursor.clear();+ deferredCursorMonitor = monitor;+ deferredCursor.add(std::move(element));+ } else+ g_pHyprRenderer->m_renderPass.add(std::move(element));+}+static void softwareCursor(Pointer::CPointerManager *self, PHLMONITOR monitor,+ const Time::steady_tp &now, CRegion &damage,+ std::optional<Vector2D> position, bool screencopy,+ bool force) {+ auto original = reinterpret_cast<void (*)(+ Pointer::CPointerManager *, PHLMONITOR, const Time::steady_tp &, CRegion &,+ std::optional<Vector2D>, bool, bool)>(softwareCursorHook->m_original);+ if (screencopy) {+ // The mirror no longer contains a software cursor. Explicit overlay+ // requests must draw one, just like hardware-cursor captures do.+ original(self, monitor, now, damage, position, true, true);+ return;+ }+ if (!monitor->needsACopyFB()) {+ original(self, monitor, now, damage, position, false, force);+ return;+ }+ deferredCursor.clear();+ deferredCursorMonitor = monitor;+ if (auto texture = self->getCurrentCursorTexture();+ texture && !texture->m_imageDescription)+ texture->m_imageDescription = NColorManagement::DEFAULT_SRGB_IMAGE_DESCRIPTION;+ std::swap(deferredCursor, g_pHyprRenderer->m_renderPass);+ original(self, monitor, now, damage, position, false, force);+ std::swap(deferredCursor, g_pHyprRenderer->m_renderPass);+}+static void cursorConstraints(void *session) {+ // The cursor shape change can finish a pending frame before the next output+ // commit. Send its hotspot before ready, as the Wayland protocol requires.+ sendCursorEvents(session);+ reinterpret_cast<void (*)(void *)>(cursorConstraintsHook->m_original)(session);+}+// Keep Hyprland's permission and source-overlap decision. Its opaque clear is+// the denied/outside-source path; a transparent clear can be a system cursor+// incorrectly classified as hidden because it has no wl_surface.+static void renderCursor(void *session) {+ const bool previous = renderingCursor;+ renderingCursor = true;+ cursorAllowed = true;+ cursorFramebuffer = g_pHyprRenderer->m_renderData.outFB;+ reinterpret_cast<void (*)(void *)>(cursorRenderHook->m_original)(session);+ renderingCursor = previous;+}+static void clearCursor(IHyprRenderer *renderer,+ const CClearPassElement::SClearData &data,+ const CRegion &damage) {+ reinterpret_cast<void (*)(+ IHyprRenderer *, const CClearPassElement::SClearData &, const CRegion &)>(+ cursorClearHook->m_original)(renderer, data, damage);+ if (renderingCursor && data.color.a != 0)+ cursorAllowed = false;+}+static bool readCursor(void *fb, CHLBufferReference buffer, uint32_t x,+ uint32_t y, uint32_t width, uint32_t height) {+ const auto &cursor = Pointer::mgr()->currentCursorImage();+ const bool cursorRead = cursorFramebuffer.lock().get() == fb;+ if (cursorRead)+ cursorFramebuffer.reset();+ if (cursorRead && cursorAllowed && cursor.pBuffer && !x && !y && width &&+ height && width <= 256 && height <= 256) {+ const auto source = cursor.pBuffer->shm(), target = buffer->shm();+ if (source.success && target.success && source.format == target.format &&+ source.format == DRM_FORMAT_ARGB8888 &&+ source.size == Vector2D(int(width), int(height)) &&+ target.size == source.size && source.stride >= int(width * 4) &&+ target.stride >= int(width * 4)) {+ auto [src, srcFormat, srcLength] = cursor.pBuffer->beginDataPtr(0);+ auto [dst, dstFormat, dstLength] = buffer->beginDataPtr(0);+ // CCursorBuffer's third field is stride, whereas wl_shm buffers report+ // allocation length. Its owned vector is stride * height in 0.56.2.+ const bool sourceFits =+ dynamic_cast<Pointer::Cursor::CCursorBuffer *>(cursor.pBuffer.get())+ ? srcLength == size_t(source.stride)+ : srcLength >= size_t(source.stride) * height;+ const bool valid = src && dst && sourceFits &&+ dstLength >= size_t(target.stride) * height;+ if (valid)+ for (uint32_t row = 0; row < height; row++)+ std::copy_n(src + size_t(row) * source.stride, width * 4,+ dst + size_t(row) * target.stride);+ buffer->endDataPtr();+ cursor.pBuffer->endDataPtr();+ if (valid)+ return true;+ }+ }+ return reinterpret_cast<bool (*)(void *, CHLBufferReference, uint32_t,+ uint32_t, uint32_t, uint32_t)>(+ cursorReadHook->m_original)(fb, buffer, x, y, width, height);+}+static std::set<MONITORID> covered;+// Isolated native surface: Cindy surface/text/selection semantic palette,+// matching privacyScreenHtml. No desktop content is used to style the mask.+static bool dark = true;+static CHyprColor surface() {+ return CHyprColor(dark ? 0xFF1F1F1E : 0xFFF8F8F6);+}+static CHyprColor foreground() {+ return CHyprColor(dark ? 0xFFD4D4D4 : 0xFF262626);+}+static bool selectedDisconnect = false;+static std::vector<std::string> labels;+static std::vector<SP<ITexture>> texts;+static SP<ITexture> heroTexture, wordmarkTexture;+static SP<ITexture> artwork(const unsigned char *bytes, size_t size) {+ struct Reader { const unsigned char *data; size_t remaining; } reader{bytes, size};+ auto surface = cairo_image_surface_create_from_png_stream(+ [](void *context, unsigned char *out, unsigned int count) {+ auto &reader = *static_cast<Reader *>(context);+ if (count > reader.remaining)+ return CAIRO_STATUS_READ_ERROR;+ std::copy_n(reader.data, count, out);+ reader.data += count;+ reader.remaining -= count;+ return CAIRO_STATUS_SUCCESS;+ }, &reader);+ SP<ITexture> texture;+ if (cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS) {+ texture = g_pHyprRenderer->createTexture(surface);+ texture->m_imageDescription = NColorManagement::DEFAULT_SRGB_IMAGE_DESCRIPTION;+ }+ cairo_surface_destroy(surface);+ return texture;+}+static bool active() { return gate.phase != PrivacyGate::Off; }+static bool physicalOutput(PHLMONITOR monitor) {+ return monitor->m_output->getBackend()->type() !=+ Aquamarine::AQ_BACKEND_HEADLESS;+}+static void damage() {+ for (const auto &monitor : State::monitorState()->allMonitors()) {+ if (!monitor->enabled())+ continue;+ // Renderer::damageMonitor intentionally skips mirrored physical outputs.+ // Privacy must cover them too, including phone-fit headless/mirror layouts.+ monitor->addDamage(CBox{0, 0, INT16_MAX, INT16_MAX});+ monitor->scheduleFrame(Aquamarine::IOutput::AQ_SCHEDULE_DAMAGE);+ }+}+static void stop() {+ gate.stop();+ token.clear();+ covered.clear();+ selectedDisconnect = false;+ damage();+}+static bool consume(bool physical, unsigned key, bool down, bool trigger) {+ auto old = gate.phase;+ bool result = gate.consume(physical, key, down, trigger);+ if (old != gate.phase)+ damage();+ return result;+}+static void choose(bool disconnect) {+ gate.phase = disconnect ? PrivacyGate::Disconnect : PrivacyGate::Resume;+ damage();+}+static double dialogScale(PHLMONITOR monitor) {+ return std::min({static_cast<double>(monitor->m_scale),+ monitor->m_transformedSize.x / 600.,+ monitor->m_transformedSize.y / 300.});+}+static void clickDialog(PHLMONITOR monitor, Vector2D point) {+ if (gate.phase != PrivacyGate::Confirming)+ return;+ const auto scale = dialogScale(monitor);+ const auto p = point / scale;+ const double left = (monitor->m_transformedSize.x / scale - 560) / 2;+ const double top = (monitor->m_transformedSize.y / scale - 220) / 2;+ if (p.y >= top + 150 && p.y <= top + 202) {+ if (p.x >= left + 20 && p.x <= left + 270)+ choose(false);+ else if (p.x >= left + 280 && p.x <= left + 530)+ choose(true);+ }+}+static void keyboard(CInputManager *self, const IKeyboard::SKeyEvent &event,+ SP<IKeyboard> keyboard) {+ bool physical = !keyboard->isVirtual();+ bool down = event.state == WL_KEYBOARD_KEY_STATE_PRESSED;+ bool dialog = gate.phase == PrivacyGate::Confirming && physical &&+ !gate.held.contains(event.keycode);+ if (consume(physical, event.keycode, down, down)) {+ if (dialog && down) {+ if (event.keycode == KEY_ESC)+ choose(false);+ else if (event.keycode == KEY_TAB || event.keycode == KEY_LEFT ||+ event.keycode == KEY_RIGHT) {+ selectedDisconnect = !selectedDisconnect;+ damage();+ } else if (event.keycode == KEY_ENTER)+ choose(selectedDisconnect);+ }+ return;+ }+ reinterpret_cast<void (*)(CInputManager *, const IKeyboard::SKeyEvent &,+ SP<IKeyboard>)>(keyHook->m_original)(self, event,+ keyboard);+}+static void modifiers(CInputManager *self, SP<IKeyboard> keyboard) {+ if (active() &&+ (!keyboard->isVirtual() || (gate.phase != PrivacyGate::Active &&+ gate.phase != PrivacyGate::Pending)))+ return;+ reinterpret_cast<void (*)(CInputManager *, SP<IKeyboard>)>(+ modHook->m_original)(self, keyboard);+}+static uint32_t virtualModifiers(CInputManager *self) {+ uint32_t result = 0;+ for (const auto &keyboard : self->m_keyboards)+ if (keyboard->isVirtual() && keyboard->m_enabled && keyboard->shareStates())+ result |= keyboard->getModifiers();+ return result;+}+static uint32_t sharedModifiers(CInputManager *self, uint32_t depressed) {+ if (active())+ return depressed | virtualModifiers(self);+ return reinterpret_cast<uint32_t (*)(CInputManager *, uint32_t)>(+ sharedModsHook->m_original)(self, depressed);+}+static uint32_t allModifiers(CInputManager *self) {+ if (active())+ return virtualModifiers(self);+ return reinterpret_cast<uint32_t (*)(CInputManager *)>(+ allModsHook->m_original)(self);+}+static bool sharedKeys(CInputManager *self, uint32_t key, bool pressed) {+ if (active()) {+ if (pressed)+ return true;+ for (const auto &keyboard : self->m_keyboards)+ if (keyboard->isVirtual() && keyboard->m_enabled &&+ keyboard->shareStates() && keyboard->getPressed(key))+ return true;+ return false;+ }+ return reinterpret_cast<bool (*)(CInputManager *, uint32_t, bool)>(+ sharedKeysHook->m_original)(self, key, pressed);+}+static void button(CInputManager *self, IPointer::SButtonEvent event,+ SP<IPointer> pointer) {+ bool physical = !pointer || !pointer->isVirtual();+ bool down = event.state == WL_POINTER_BUTTON_STATE_PRESSED;+ bool dialog = gate.phase == PrivacyGate::Confirming && physical &&+ !gate.held.contains(event.button + 1024);+ if (consume(physical, event.button + 1024, down, down)) {+ if (dialog && down && event.button == BTN_LEFT) {+ auto point = Pointer::mgr()->position();+ for (auto monitor : State::monitorState()->allMonitors()) {+ if (!monitor->enabled() || !physicalOutput(monitor))+ continue;+ auto source =+ monitor->m_mirrorOf ? monitor->m_mirrorOf.lock() : monitor;+ auto p = (point - source->m_position) * source->m_scale;+ if (p.x < 0 || p.y < 0 || p.x >= source->m_transformedSize.x ||+ p.y >= source->m_transformedSize.y)+ continue;+ if (source != monitor) {+ const auto scale = std::min(+ monitor->m_transformedSize.x / source->m_transformedSize.x,+ monitor->m_transformedSize.y / source->m_transformedSize.y);+ p = p * scale ++ (monitor->m_transformedSize - source->m_transformedSize * scale) /+ 2;+ }+ clickDialog(monitor, p);+ }+ }+ return;+ }+ reinterpret_cast<void (*)(CInputManager *, IPointer::SButtonEvent,+ SP<IPointer>)>(buttonHook->m_original)(self, event,+ pointer);+}+static void axis(CInputManager *self, IPointer::SAxisEvent event,+ SP<IPointer> pointer) {+ if (consume(!pointer || !pointer->isVirtual(), 2048, false, true))+ return;+ reinterpret_cast<void (*)(CInputManager *, IPointer::SAxisEvent,+ SP<IPointer>)>(axisHook->m_original)(self, event,+ pointer);+}+static void motion(CInputManager *self, IPointer::SMotionEvent event) {+ if (active() && ((!event.device || !event.device->isVirtual())+ ? gate.phase != PrivacyGate::Confirming+ : gate.phase != PrivacyGate::Active))+ return;+ reinterpret_cast<void (*)(CInputManager *, IPointer::SMotionEvent)>(+ moveHook->m_original)(self, event);+}+static void warp(CInputManager *self, IPointer::SMotionAbsoluteEvent event) {+ auto pointer = dynamicPointerCast<IPointer>(event.device);+ if (active() && ((!pointer || !pointer->isVirtual())+ ? gate.phase != PrivacyGate::Confirming+ : gate.phase != PrivacyGate::Active))+ return;+ reinterpret_cast<void (*)(CInputManager *, IPointer::SMotionAbsoluteEvent)>(+ warpHook->m_original)(self, event);+}+static bool scanout(CMonitor *self) {+ return !active() &&+ reinterpret_cast<bool (*)(CMonitor *)>(scanoutHook->m_original)(self);+}+static bool needsCopy(CMonitor *self) {+ return active() || reinterpret_cast<bool (*)(CMonitor *)>(+ needsCopyHook->m_original)(self);+}+// Save the unmasked image first, then mask the working framebuffer while the+// normal render context is still alive. Drawing after end() has invalidated+// framebuffer state is not safe on the physical DRM render path.+static bool copy(CHyprOpenGLImpl *self, const CBox &box) {+ const bool copied = reinterpret_cast<bool (*)(CHyprOpenGLImpl *, const CBox &)>(+ copyHook->m_original)(self, box);+ auto saved = g_pHyprRenderer->m_renderData;+ if (deferredCursorMonitor == saved.pMonitor) {+ // Paint only after the capture/mirror copy, preserving the local pointer.+ deferredCursor.render(saved.damage);+ deferredCursor.clear();+ deferredCursorMonitor.reset();+ g_pHyprRenderer->m_renderData = saved;+ }+ // Hyprland calls this only for non-fake output frames in end().+ if (!active() || !saved.pMonitor || !physicalOutput(saved.pMonitor.lock()))+ return copied;+ auto monitor = saved.pMonitor.lock();+ CBox full{0, 0, monitor->m_transformedSize.x, monitor->m_transformedSize.y};+ g_pHyprRenderer->m_renderData.damage = CRegion(full);+ g_pHyprRenderer->pushMonitorTransformEnabled(true);+ self->renderRect(full, surface(), {});+ self->blend(true);+ if (texts.empty()) {+ for (auto &label : labels) {+ auto texture = g_pHyprRenderer->renderText(label, foreground(), 18, false, "", 510);+ // Cairo text is sRGB. The final-copy renderer needs an explicit image+ // description, unlike the ordinary surface pass's implicit fallback.+ texture->m_imageDescription = NColorManagement::DEFAULT_SRGB_IMAGE_DESCRIPTION;+ texts.push_back(texture);+ }+ }+ bool dialog = gate.phase == PrivacyGate::Confirming;+ const auto scale = dialogScale(monitor);+ double left = (full.w / scale - 560) / 2, top = (full.h / scale - 220) / 2;+ auto text = [&](size_t index, double x, double y) {+ if (index >= texts.size() || !texts[index])+ return;+ auto size = texts[index]->m_size;+ self->renderTexture(+ texts[index],+ CBox{x * scale, y * scale, size.x * scale, size.y * scale}, {});+ };+ if (!dialog) {+ if (!heroTexture)+ heroTexture = artwork(heroPng, sizeof(heroPng));+ if (!wordmarkTexture)+ wordmarkTexture = dark ? artwork(wordmarkDarkPng, sizeof(wordmarkDarkPng))+ : artwork(wordmarkLightPng, sizeof(wordmarkLightPng));+ const double w = full.w / scale, h = full.h / scale;+ const bool portrait = w <= h;+ const double heroWidth = portrait ? std::min(w * .68, h * .46)+ : std::min({w * .48, h * .62, 600.});+ const double heroHeight = heroTexture ? heroWidth * heroTexture->m_size.y / heroTexture->m_size.x : heroWidth;+ const double gap = portrait ? 16. : std::clamp(w * .04, 24., 72.);+ const double copyWidth = std::min(460., portrait ? w * .85 : w * .92 - heroWidth - gap);+ const double markWidth = std::clamp(w * .18, 160., 230.);+ const double markHeight = wordmarkTexture ? markWidth * wordmarkTexture->m_size.y / wordmarkTexture->m_size.x : 60.;+ const double copyHeight = markHeight + 32 + 48 + 20 + 32;+ const double heroX = portrait ? (w - heroWidth) / 2 : (w - heroWidth - gap - copyWidth) / 2;+ const double heroY = portrait ? (h - heroHeight - gap - copyHeight) / 2 : (h - heroHeight) / 2;+ const double copyX = portrait ? (w - copyWidth) / 2 : heroX + heroWidth + gap;+ const double copyY = portrait ? heroY + heroHeight + gap : (h - copyHeight) / 2;+ if (heroTexture)+ self->renderTexture(heroTexture, CBox{heroX * scale, heroY * scale, heroWidth * scale, heroHeight * scale}, {});+ if (wordmarkTexture)+ self->renderTexture(wordmarkTexture, CBox{(portrait ? (w - markWidth) / 2 : copyX) * scale, copyY * scale, markWidth * scale, markHeight * scale}, {});+ text(0, portrait ? (w - texts[0]->m_size.x) / 2 : copyX, copyY + markHeight + 32);+ text(1, portrait ? (w - texts[1]->m_size.x) / 2 : copyX, copyY + markHeight + 100);+ } else {+ text(2, left + 24, top + 30);+ text(3, left + 24, top + 78);+ }+ if (dialog) {+ for (int i = 0; i < 2; i++) {+ double shade = selectedDisconnect == (i == 1) ? (dark ? .35 : .75)+ : (dark ? .15 : .9);+ self->renderRect(CBox{(left + 20 + i * 260) * scale, (top + 150) * scale,+ 250 * scale, 52 * scale},+ CHyprColor(shade, shade, shade, 1.), {});+ text(4 + i, left + 36 + i * 260, top + 164);+ }+ }+ g_pHyprRenderer->popMonitorTransformEnabled();+ g_pHyprRenderer->m_renderData = saved;+ covered.insert(monitor->m_id);+ return copied;+}+static void *symbol(const std::string &name) {+ auto qualified = name.substr(0, name.find('('));+ auto query = qualified.substr(qualified.rfind("::") + 2);+ auto matches = HyprlandAPI::findFunctionsByName(owner, query);+ std::erase_if(matches, [&](const auto &match) {+ return match.demangled.find(name) == std::string::npos;+ });+ if (matches.size() != 1)+ throw std::runtime_error("Unsupported compositor symbol: " + name + " (" ++ std::to_string(matches.size()) + ")");+ return matches[0].address;+}+static CFunctionHook *hook(const std::string &name, void *replacement) {+ auto h = HyprlandAPI::createFunctionHook(owner, symbol(name), replacement);+ if (!h || !h->hook())+ throw std::runtime_error("Compositor hook unavailable");+ return h;+}+static std::string state() {+ if (gate.phase == PrivacyGate::Active)+ for (const auto &monitor : State::monitorState()->allMonitors())+ if (monitor->enabled() && physicalOutput(monitor) &&+ monitor->m_dpmsStatus && !covered.contains(monitor->m_id))+ return "starting";+ static const char *names[] = {"off", "active", "pending",+ "confirming", "resume", "disconnect"};+ return names[gate.phase];+}+static int tick(void *) {+ if (active() &&+ std::chrono::steady_clock::now() - heartbeat > std::chrono::seconds(6))+ stop();+ wl_event_source_timer_update(watchdog, 500);+ return 0;+}+APICALL EXPORT std::string PLUGIN_API_VERSION() { return HYPRLAND_API_VERSION; }+APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {+ owner = handle;+ retired = false;+ loading = true;+ if (std::string(__hyprland_api_get_hash()) !=+ __hyprland_api_get_client_hash())+ throw std::runtime_error("Hyprland ABI mismatch");+ copyHook = hook("CHyprOpenGLImpl::saveBufferForMirror", reinterpret_cast<void *>(copy));+ needsCopyHook = hook("CMonitor::needsACopyFB()", reinterpret_cast<void *>(needsCopy));+ softwareCursorHook = hook("CPointerManager::renderSoftwareCursorsFor(",+ reinterpret_cast<void *>(softwareCursor));+ cursorRenderHook = hook("CCursorshareSession::render()",+ reinterpret_cast<void *>(renderCursor));+ cursorClearHook =+ hook("IHyprRenderer::draw(CClearPassElement::SClearData const&",+ reinterpret_cast<void *>(clearCursor));+ cursorReadHook =+ hook("CGLFramebuffer::readPixels(", reinterpret_cast<void *>(readCursor));+ sendCursorEvents = reinterpret_cast<void (*)(void *)>(+ symbol("CImageCopyCaptureCursorSession::sendCursorEvents()"));+ cursorConstraintsHook =+ hook("CImageCopyCaptureCursorSession::sendConstraints()",+ reinterpret_cast<void *>(cursorConstraints));+ keyHook =+ hook("CInputManager::onKeyboardKey", reinterpret_cast<void *>(keyboard));+ modHook =+ hook("CInputManager::onKeyboardMod", reinterpret_cast<void *>(modifiers));+ sharedModsHook = hook("CInputManager::shareModsFromAllKBs",+ reinterpret_cast<void *>(sharedModifiers));+ allModsHook = hook("CInputManager::getModsFromAllKBs",+ reinterpret_cast<void *>(allModifiers));+ sharedKeysHook = hook("CInputManager::shareKeyFromAllKBs",+ reinterpret_cast<void *>(sharedKeys));+ buttonHook =+ hook("CInputManager::onMouseButton", reinterpret_cast<void *>(button));+ axisHook =+ hook("CInputManager::onMouseWheel", reinterpret_cast<void *>(axis));+ moveHook =+ hook("CInputManager::onMouseMoved", reinterpret_cast<void *>(motion));+ warpHook = hook("CInputManager::onMouseWarp", reinterpret_cast<void *>(warp));+ scanoutHook =+ hook("CMonitor::attemptDirectScanout", reinterpret_cast<void *>(scanout));+ listeners.push_back(+ Event::bus()->m_events.config.reloaded.listen([] { loading = false; }));+ listeners.push_back(+ Event::bus()->m_events.render.stage.listen([](eRenderStage stage) {+ if (stage == RENDER_POST_MIRROR)+ mirroredCursor();+ if (active() && stage == RENDER_PRE)+ for (const auto &monitor : State::monitorState()->allMonitors())+ if (monitor->enabled())+ // The working image was masked last frame. Repaint it fully+ // before saving the next unmasked capture; do not schedule an+ // extra frame here or turn idle privacy into a render loop.+ monitor->addDamage(CBox{0, 0, INT16_MAX, INT16_MAX});+ }));+ auto block = [](auto event, Event::SCallbackInfo &info) {+ if (active()) {+ consume(true, 4096, false, true);+ info.cancelled = true;+ }+ };+ listeners.push_back(Event::bus()->m_events.input.touch.down.listen(+ [](ITouch::SDownEvent event, Event::SCallbackInfo &info) {+ if (!active())+ return;+ info.cancelled = true;+ if (!event.device || event.device->isVirtual())+ return;+ if (gate.phase == PrivacyGate::Confirming) {+ for (const auto &monitor : State::monitorState()->allMonitors())+ if (monitor->m_name == event.device->m_boundOutput)+ clickDialog(monitor, event.pos * monitor->m_transformedSize);+ } else+ consume(true, 4096, false, true);+ }));+ listeners.push_back(Event::bus()->m_events.input.touch.up.listen(block));+ listeners.push_back(Event::bus()->m_events.input.touch.motion.listen(block));+ listeners.push_back(Event::bus()->m_events.input.tablet.axis.listen(block));+ listeners.push_back(Event::bus()->m_events.input.tablet.button.listen(block));+ listeners.push_back(Event::bus()->m_events.input.tablet.tip.listen(block));+ listeners.push_back(Event::bus()->m_events.gesture.swipe.begin.listen(block));+ listeners.push_back(+ Event::bus()->m_events.gesture.swipe.update.listen(block));+ listeners.push_back(Event::bus()->m_events.gesture.swipe.end.listen(block));+ listeners.push_back(Event::bus()->m_events.gesture.pinch.begin.listen(block));+ listeners.push_back(+ Event::bus()->m_events.gesture.pinch.update.listen(block));+ listeners.push_back(Event::bus()->m_events.gesture.pinch.end.listen(block));+ watchdog = wl_event_loop_add_timer(+ wl_display_get_event_loop(g_pCompositor->m_wlDisplay), tick, nullptr);+ if (!watchdog)+ throw std::runtime_error("Compositor timer unavailable");+ wl_event_source_timer_update(watchdog, 500);+ command = HyprlandAPI::registerHyprCtlCommand(+ owner,+ {"cindy-privacy", false, [](eHyprCtlOutputFormat, std::string request) {+ try {+ if (request.size() > 8192)+ throw std::runtime_error("size");+ auto body = request.substr(request.find(' ') + 1);+ auto parser = json_tokener_new();+ json_tokener_set_flags(parser, JSON_TOKENER_STRICT |+ JSON_TOKENER_VALIDATE_UTF8);+ auto raw = json_tokener_parse_ex(parser, body.c_str(), body.size());+ auto parsed =+ json_tokener_get_error(parser) == json_tokener_success &&+ json_tokener_get_parse_end(parser) == body.size();+ json_tokener_free(parser);+ std::unique_ptr<json_object, decltype(&json_object_put)> value(+ raw, json_object_put);+ if (!parsed || !raw || !json_object_is_type(raw, json_type_object))+ throw std::runtime_error("json");+ auto op = stringValue(json_object_object_get(raw, "op"));+ if (op == "probe")+ return std::string(loading ? "loading:" : "ready:") ++ CINDY_PRIVACY_SOURCE;+ if (op == "retire") {+ if (active())+ throw std::runtime_error("owned");+ Dl_info library{};+ if (!dladdr(reinterpret_cast<void *>(state), &library) ||+ !library.dli_fname)+ throw std::runtime_error("library");+ retired = true;+ return std::string(library.dli_fname);+ }+ if (retired || loading)+ throw std::runtime_error("retired");+ auto key = stringValue(json_object_object_get(raw, "token"));+ if (key.size() != 32 ||+ key.find_first_not_of("0123456789abcdef") != std::string::npos)+ throw std::runtime_error("token");+ if (op == "start" && !active()) {+ auto items = json_object_object_get(raw, "labels");+ if (!items || !json_object_is_type(items, json_type_array) ||+ json_object_array_length(items) != 6)+ throw std::runtime_error("labels");+ std::vector<std::string> next;+ for (size_t i = 0; i < 6; i++)+ next.push_back(stringValue(json_object_array_get_idx(items, i)));+ for (auto &label : next)+ if (label.size() > 1024)+ throw std::runtime_error("label");+ auto theme = json_object_object_get(raw, "dark");+ if (!theme || !json_object_is_type(theme, json_type_boolean))+ throw std::runtime_error("theme");+ dark = json_object_get_boolean(theme);+ wordmarkTexture.reset();+ token = key;+ labels = next;+ texts.clear();+ covered.clear();+ gate.phase = PrivacyGate::Active;+ damage();+ }+ if (key != token)+ throw std::runtime_error("owner");+ heartbeat = std::chrono::steady_clock::now();+ if (op == "stop")+ stop();+ else if (op == "confirm" && gate.phase == PrivacyGate::Pending) {+ gate.phase = PrivacyGate::Confirming;+ selectedDisconnect = false;+ damage();+ } else if (op == "resume" && gate.phase == PrivacyGate::Resume) {+ gate.phase = PrivacyGate::Active;+ damage();+ } else if (op != "start" && op != "ping")+ throw std::runtime_error("operation");+ return state();+ } catch (...) {+ return std::string("unavailable");+ }+ }});+ return {"cindy-privacy", "Lease-scoped physical privacy, capture preserved",+ "Cindy", "1"};+}+APICALL EXPORT void PLUGIN_EXIT() {+ stop();+ listeners.clear();+ texts.clear();+ heroTexture.reset();+ wordmarkTexture.reset();+ deferredCursor.clear();+ deferredCursorMonitor.reset();+ if (watchdog)+ wl_event_source_remove(watchdog);+ watchdog = nullptr;+}diff --git a/apps/desktop/native/remote-desktop/hyprland-privacy/test.mjs b/apps/desktop/native/remote-desktop/hyprland-privacy/test.mjsnew file mode 100644index 0000000000..492905b87f--- /dev/null+++ b/apps/desktop/native/remote-desktop/hyprland-privacy/test.mjs@@ -0,0 +1,71 @@+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import test from 'node:test';++test('physical triggers and held edges never reach the remote application or confirm themselves', () => {+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-privacy-gate-'));+ const root = path.dirname(fileURLToPath(import.meta.url));+ try {+ const source = path.join(directory, 'test.cpp');+ fs.writeFileSync(+ source,+ `+#include "gate.hpp"+#include <cassert>+int main() {+ PrivacyGate gate;+ assert(!gate.consume(true, 28, true, true));+ gate.phase=PrivacyGate::Active;+ assert(!gate.consume(false, 28, true, true)); // remote Enter is ordinary input+ assert(gate.phase==PrivacyGate::Active);+ assert(!gate.consume(true, 42, false, false)); // release held before activation+ assert(gate.consume(true, 28, true, true));+ assert(gate.phase==PrivacyGate::Pending && gate.held.contains(28));+ assert(gate.consume(false, 28, true, true));+ assert(!gate.consume(false, 30, false, false)); // drain old helper before dialog+ gate.phase=PrivacyGate::Confirming;+ assert(gate.consume(true, 28, true, true)); // repeated initiating Enter+ assert(gate.held.contains(28));+ assert(gate.consume(true, 28, false, false));+ assert(!gate.held.contains(28));+ assert(gate.consume(false, 28, true, true)); // injected Enter cannot confirm+ assert(gate.consume(false, 30, false, false)); // full fence while confirming+ gate.phase=PrivacyGate::Resume;+ assert(gate.consume(true, 1, true, true));+ gate.phase=PrivacyGate::Active;+ assert(gate.consume(true, 1, false, false)); // dialog release cannot leak+ assert(gate.phase==PrivacyGate::Active);+ gate.phase=PrivacyGate::Disconnect;+ assert(gate.consume(false, 30, true, true));+ gate.stop();+ assert(gate.held.empty() && !gate.consume(true, 30, true, true));+}+`,+ );+ for (const [command, args] of [+ [+ 'c++',+ [+ '-std=c++20',+ '-fsanitize=address,undefined',+ '-g',+ '-I',+ root,+ source,+ '-o',+ path.join(directory, 'test'),+ ],+ ],+ [path.join(directory, 'test'), []],+ ]) {+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 60000 });+ assert.equal(result.status, 0, result.stderr || String(result.error));+ }+ } finally {+ fs.rmSync(directory, { recursive: true, force: true });+ }+});diff --git a/apps/desktop/native/remote-desktop/linux-capture/build.mjs b/apps/desktop/native/remote-desktop/linux-capture/build.mjsnew file mode 100644index 0000000000..3d2e2ce902--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/build.mjs@@ -0,0 +1,56 @@+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+const source = path.dirname(fileURLToPath(import.meta.url));+const [output] = process.argv.slice(2);+if (!output || !path.isAbsolute(output)) throw new Error('Absolute output directory required');+fs.mkdirSync(output, { recursive: true });+function run(command, args) {+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 60000 });+ if (result.error || result.status !== 0)+ throw new Error(`Linux capture build failed: ${command}: ${result.stderr || result.error}`);+ return result.stdout.trim();+}+const protocols = [+ 'wlr-screencopy-unstable-v1',+ 'ext-image-copy-capture-v1',+ 'ext-image-capture-source-v1',+ 'ext-foreign-toplevel-list-v1',+];+for (const name of protocols) {+ run('wayland-scanner', [+ 'client-header',+ path.join(source, name + '.xml'),+ path.join(output, name + '.h'),+ ]);+ run('wayland-scanner', [+ 'private-code',+ path.join(source, name + '.xml'),+ path.join(output, name + '.c'),+ ]);+}+const flags = run('pkg-config', [+ '--cflags',+ '--libs',+ 'wayland-client',+ 'libturbojpeg',+ 'libpng',+]).split(/\s+/);+const binary = path.join(output, 'cindy-linux-desktop-capture');+run('cc', [+ '-std=c11',+ '-Wall',+ '-Wextra',+ '-Werror',+ '-O2',+ path.join(source, 'main.c'),+ ...protocols.map((name) => path.join(output, name + '.c')),+ '-I',+ output,+ ...flags,+ '-lm',+ '-o',+ binary + '.tmp',+]);+fs.renameSync(binary + '.tmp', binary);diff --git a/apps/desktop/native/remote-desktop/linux-capture/cursor.h b/apps/desktop/native/remote-desktop/linux-capture/cursor.hnew file mode 100644index 0000000000..040025c945--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/cursor.h@@ -0,0 +1,353 @@+/* Cursor images and hotspot updates share the video child's Wayland connection.+ * A pending cursor frame waits for damage without blocking desktop frames. */+#include "ext-image-capture-source-v1.h"+#include "ext-image-copy-capture-v1.h"+#include <math.h>+#include <png.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>+#include <sys/mman.h>+#include <unistd.h>++struct cursor_capture {+ struct wl_seat *seat;+ struct wl_pointer *pointer;+ struct ext_image_copy_capture_manager_v1 *manager;+ struct ext_output_image_capture_source_manager_v1 *sources;+ struct ext_image_capture_source_v1 *source;+ struct ext_image_copy_capture_cursor_session_v1 *cursor;+ struct ext_image_copy_capture_session_v1 *session;+ struct ext_image_copy_capture_frame_v1 *frame;+ struct wl_shm *shm;+ struct wl_buffer *buffer;+ void *pixels;+ size_t size;+ uint32_t width, height, allocated_width, allocated_height, format, transform;+ int visible, failed, constraints, batch, has_image, x, y, hot_x, hot_y,+ pending_hot_x, pending_hot_y;+ char *png;+ double scale;+};+static struct cursor_capture cc;+static char *base64(const unsigned char *bytes, size_t length) {+ static const char abc[] =+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";+ char *out = malloc(4 * ((length + 2) / 3) + 1);+ if (!out)+ return NULL;+ size_t j = 0;+ for (size_t i = 0; i < length; i += 3) {+ uint32_t n = (uint32_t)bytes[i] << 16;+ if (i + 1 < length)+ n |= (uint32_t)bytes[i + 1] << 8;+ if (i + 2 < length)+ n |= bytes[i + 2];+ out[j++] = abc[n >> 18];+ out[j++] = abc[(n >> 12) & 63];+ out[j++] = i + 1 < length ? abc[(n >> 6) & 63] : '=';+ out[j++] = i + 2 < length ? abc[n & 63] : '=';+ }+ out[j] = 0;+ return out;+}+static void cursor_request(void);+static void cursor_transform(void *d, struct ext_image_copy_capture_frame_v1 *f,+ uint32_t t) {+ (void)d;+ (void)f;+ cc.transform = t;+}+static void cursor_damage(void *d, struct ext_image_copy_capture_frame_v1 *f,+ int32_t x, int32_t y, int32_t w, int32_t h) {+ (void)d;+ (void)f;+ (void)x;+ (void)y;+ (void)w;+ (void)h;+}+static void cursor_time(void *d, struct ext_image_copy_capture_frame_v1 *f,+ uint32_t a, uint32_t b, uint32_t c) {+ (void)d;+ (void)f;+ (void)a;+ (void)b;+ (void)c;+}+static void cursor_ready(void *d, struct ext_image_copy_capture_frame_v1 *f) {+ (void)d;+ ext_image_copy_capture_frame_v1_destroy(f);+ cc.frame = NULL;+ if (cc.transform != WL_OUTPUT_TRANSFORM_NORMAL) {+ cc.failed = 1;+ return;+ }+ png_image image = {.version = PNG_IMAGE_VERSION,+ .width = cc.allocated_width,+ .height = cc.allocated_height,+ .format = PNG_FORMAT_RGBA};+ size_t count = cc.allocated_width * cc.allocated_height;+ unsigned char *rgba = malloc(count * 4);+ if (!rgba) {+ cc.failed = 1;+ return;+ }+ /* Wayland ARGB is native-endian and premultiplied; PNG is straight RGBA. */+ cc.has_image = 0;+ for (size_t i = 0; i < count; i++) {+ uint32_t p = ((uint32_t *)cc.pixels)[i], a = p >> 24;+ if (a)+ cc.has_image = 1;+ rgba[i * 4 + 3] = (unsigned char)a;+ for (unsigned k = 0; k < 3; k++) {+ unsigned v = (p >> (16 - 8 * k)) & 255;+ rgba[i * 4 + k] =+ (unsigned char)(a ? fmin(255, (v * 255 + a / 2) / a) : 0);+ }+ }+ png_alloc_size_t size = 0;+ if (!png_image_write_to_memory(&image, NULL, &size, 0, rgba, 0, NULL) ||+ size > 49152)+ cc.failed = 1;+ else {+ unsigned char *png = malloc(size);+ if (!png ||+ !png_image_write_to_memory(&image, png, &size, 0, rgba, 0, NULL))+ cc.failed = 1;+ else {+ free(cc.png);+ cc.png = base64(png, size);+ cc.hot_x = cc.pending_hot_x;+ cc.hot_y = cc.pending_hot_y;+ if (!cc.png)+ cc.failed = 1;+ }+ free(png);+ }+ free(rgba);+ png_image_free(&image);+ cursor_request();+}+static void cursor_failed(void *d, struct ext_image_copy_capture_frame_v1 *f,+ uint32_t reason) {+ (void)d;+ ext_image_copy_capture_frame_v1_destroy(f);+ cc.frame = NULL;+ if (reason !=+ EXT_IMAGE_COPY_CAPTURE_FRAME_V1_FAILURE_REASON_BUFFER_CONSTRAINTS)+ cc.failed = 1;+ cursor_request();+}+static const struct ext_image_copy_capture_frame_v1_listener+ cursor_frame_listener = {.transform = cursor_transform,+ .damage = cursor_damage,+ .presentation_time = cursor_time,+ .ready = cursor_ready,+ .failed = cursor_failed};+static void cursor_request(void) {+ if (cc.failed || cc.frame || !cc.constraints)+ return;+ if (!cc.width || !cc.height || cc.width > 256 || cc.height > 256 ||+ cc.format != WL_SHM_FORMAT_ARGB8888) {+ cc.failed = 1;+ return;+ }+ if (!cc.buffer || cc.allocated_width != cc.width ||+ cc.allocated_height != cc.height) {+ if (cc.buffer)+ wl_buffer_destroy(cc.buffer);+ if (cc.pixels)+ munmap(cc.pixels, cc.size);+ cc.buffer = NULL;+ cc.pixels = NULL;+ cc.size = (size_t)cc.width * cc.height * 4;+ int fd = memfd_create("cindy-cursor", MFD_CLOEXEC);+ if (fd < 0 || ftruncate(fd, (off_t)cc.size) < 0) {+ if (fd >= 0)+ close(fd);+ cc.failed = 1;+ return;+ }+ cc.pixels = mmap(NULL, cc.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);+ if (cc.pixels == MAP_FAILED) {+ cc.pixels = NULL;+ close(fd);+ cc.failed = 1;+ return;+ }+ struct wl_shm_pool *pool = wl_shm_create_pool(cc.shm, fd, (int32_t)cc.size);+ cc.buffer = wl_shm_pool_create_buffer(pool, 0, (int32_t)cc.width,+ (int32_t)cc.height,+ (int32_t)cc.width * 4, cc.format);+ wl_shm_pool_destroy(pool);+ close(fd);+ cc.allocated_width = cc.width;+ cc.allocated_height = cc.height;+ }+ cc.frame = ext_image_copy_capture_session_v1_create_frame(cc.session);+ ext_image_copy_capture_frame_v1_add_listener(cc.frame, &cursor_frame_listener,+ NULL);+ ext_image_copy_capture_frame_v1_attach_buffer(cc.frame, cc.buffer);+ ext_image_copy_capture_frame_v1_damage_buffer(+ cc.frame, 0, 0, (int32_t)cc.width, (int32_t)cc.height);+ ext_image_copy_capture_frame_v1_capture(cc.frame);+}+static void cursor_constraints(void) {+ if (!cc.batch) {+ cc.batch = 1;+ cc.constraints = 0;+ cc.format = UINT32_MAX;+ }+}+static void cursor_size(void *d, struct ext_image_copy_capture_session_v1 *s,+ uint32_t w, uint32_t h) {+ (void)d;+ (void)s;+ cursor_constraints();+ cc.width = w;+ cc.height = h;+}+static void cursor_format(void *d, struct ext_image_copy_capture_session_v1 *s,+ uint32_t f) {+ (void)d;+ (void)s;+ cursor_constraints();+ if (f == WL_SHM_FORMAT_ARGB8888)+ cc.format = f;+}+static void cursor_device(void *d, struct ext_image_copy_capture_session_v1 *s,+ struct wl_array *a) {+ (void)d;+ (void)s;+ (void)a;+}+static void cursor_dmabuf(void *d, struct ext_image_copy_capture_session_v1 *s,+ uint32_t f, struct wl_array *a) {+ (void)d;+ (void)s;+ (void)f;+ (void)a;+}+static void cursor_done(void *d, struct ext_image_copy_capture_session_v1 *s) {+ (void)d;+ (void)s;+ cc.constraints = 1;+ cc.batch = 0;+ cursor_request();+}+static void cursor_stopped(void *d,+ struct ext_image_copy_capture_session_v1 *s) {+ (void)d;+ (void)s;+ cc.failed = 1;+}+static const struct ext_image_copy_capture_session_v1_listener+ cursor_session_listener = {.buffer_size = cursor_size,+ .shm_format = cursor_format,+ .dmabuf_device = cursor_device,+ .dmabuf_format = cursor_dmabuf,+ .done = cursor_done,+ .stopped = cursor_stopped};+static void cursor_enter(void *d,+ struct ext_image_copy_capture_cursor_session_v1 *s) {+ (void)d;+ (void)s;+ cc.visible = 1;+}+static void cursor_leave(void *d,+ struct ext_image_copy_capture_cursor_session_v1 *s) {+ (void)d;+ (void)s;+ cc.visible = 0;+}+static void cursor_position(void *d,+ struct ext_image_copy_capture_cursor_session_v1 *s,+ int32_t x, int32_t y) {+ (void)d;+ (void)s;+ cc.x = x;+ cc.y = y;+}+static void cursor_hotspot(void *d,+ struct ext_image_copy_capture_cursor_session_v1 *s,+ int32_t x, int32_t y) {+ (void)d;+ (void)s;+ cc.pending_hot_x = x;+ cc.pending_hot_y = y;+}+static const struct ext_image_copy_capture_cursor_session_v1_listener+ cursor_listener = {.enter = cursor_enter,+ .leave = cursor_leave,+ .position = cursor_position,+ .hotspot = cursor_hotspot};+static void cursor_global(struct wl_registry *registry, uint32_t name,+ const char *interface) {+ if (!strcmp(interface, wl_seat_interface.name) && !cc.seat)+ cc.seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);+ if (!strcmp(interface, ext_image_copy_capture_manager_v1_interface.name))+ cc.manager = wl_registry_bind(+ registry, name, &ext_image_copy_capture_manager_v1_interface, 1);+ if (!strcmp(interface,+ ext_output_image_capture_source_manager_v1_interface.name))+ cc.sources = wl_registry_bind(+ registry, name, &ext_output_image_capture_source_manager_v1_interface,+ 1);+}+static int cursor_begin(struct wl_shm *shm, struct wl_output *output) {+ if (!cc.manager || !cc.sources || !cc.seat)+ return -1;+ cc.shm = shm;+ cc.pointer = wl_seat_get_pointer(cc.seat);+ cc.source = ext_output_image_capture_source_manager_v1_create_source(+ cc.sources, output);+ cc.cursor = ext_image_copy_capture_manager_v1_create_pointer_cursor_session(+ cc.manager, cc.source, cc.pointer);+ ext_image_copy_capture_cursor_session_v1_add_listener(cc.cursor,+ &cursor_listener, NULL);+ cc.session =+ ext_image_copy_capture_cursor_session_v1_get_capture_session(cc.cursor);+ ext_image_copy_capture_session_v1_add_listener(+ cc.session, &cursor_session_listener, NULL);+ return 0;+}+static void cursor_json(uint32_t width, uint32_t height) {+ if (!cc.png || cc.failed) {+ fputs("null", stdout);+ return;+ }+ double scale = cc.scale > 0 ? cc.scale : 1;+ printf("{\"visible\":%s,\"x\":%.6f,\"y\":%.6f,\"width\":%.3f,\"height\":%.3f,"+ "\"hotX\":%.3f,\"hotY\":%.3f,\"png\":\"%s\"}",+ /* Hyprland 0.56 exports positions in source logical coordinates. */+ cc.visible ? "true" : "false", fmax(0, fmin(1, cc.x * scale / width)),+ fmax(0, fmin(1, cc.y * scale / height)), cc.allocated_width / scale,+ cc.allocated_height / scale,+ fmax(0, fmin(cc.allocated_width, cc.hot_x)) / scale,+ fmax(0, fmin(cc.allocated_height, cc.hot_y)) / scale, cc.png);+}+static void cursor_destroy(void) {+ if (cc.frame)+ ext_image_copy_capture_frame_v1_destroy(cc.frame);+ if (cc.session)+ ext_image_copy_capture_session_v1_destroy(cc.session);+ if (cc.cursor)+ ext_image_copy_capture_cursor_session_v1_destroy(cc.cursor);+ if (cc.source)+ ext_image_capture_source_v1_destroy(cc.source);+ if (cc.buffer)+ wl_buffer_destroy(cc.buffer);+ if (cc.pointer)+ wl_pointer_destroy(cc.pointer);+ if (cc.seat)+ wl_seat_destroy(cc.seat);+ if (cc.sources)+ ext_output_image_capture_source_manager_v1_destroy(cc.sources);+ if (cc.manager)+ ext_image_copy_capture_manager_v1_destroy(cc.manager);+ if (cc.pixels)+ munmap(cc.pixels, cc.size);+ free(cc.png);+ memset(&cc, 0, sizeof(cc));+}diff --git a/apps/desktop/native/remote-desktop/linux-capture/cursor.integration.py b/apps/desktop/native/remote-desktop/linux-capture/cursor.integration.pynew file mode 100644index 0000000000..f1772fefb6--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/cursor.integration.py@@ -0,0 +1,116 @@+"""Opt-in Hyprland cursor regression in a disposable nested compositor.++Usage: python cursor.integration.py /absolute/plugin.so /absolute/capture+Requires Hyprland 0.56.2, foot and ImageMagick on a Wayland desktop.+Never loads plugins, moves pointers or changes settings in the parent compositor.+"""+import base64+import json+import os+from pathlib import Path+import select+import subprocess as sp+import sys+import tempfile+import time+++def output(args, **kwargs):+ return sp.check_output(args, timeout=8, **kwargs)+++def stop(process):+ if process and process.poll() is None:+ process.terminate()+ try:+ process.wait(timeout=5)+ except sp.TimeoutExpired:+ process.kill()+ process.wait(timeout=5)+++def exercise(root, scale, plugin, capture):+ config = root / 'hyprland.lua'+ config.write_text(+ f'hl.monitor({{output="",mode="1280x800@60",position="0x0",scale={scale}}})\n'+ 'hl.config({misc={disable_hyprland_logo=true,disable_splash_rendering=true},'+ 'animations={enabled=false},xwayland={enabled=false},'+ 'cursor={no_hardware_cursors=1}})\n'+ )+ compositor = foot = child = None+ with (root / 'hyprland.log').open('w') as log:+ try:+ compositor = sp.Popen(+ ['Hyprland', '--config', str(config)],+ env=dict(os.environ, AQ_BACKEND='wayland', XDG_CACHE_HOME=str(root / 'cache')),+ stdout=log, stderr=sp.STDOUT,+ )+ instance = None+ for _ in range(50):+ instances = json.loads(output(['hyprctl', '-j', 'instances']))+ instance = next((i for i in instances if i['pid'] == compositor.pid), None)+ if instance:+ break+ assert compositor.poll() is None, 'Nested compositor exited'+ time.sleep(.1)+ assert instance, 'Nested compositor not ready'+ env = dict(os.environ, WAYLAND_DISPLAY=instance['wl_socket'],+ HYPRLAND_INSTANCE_SIGNATURE=instance['instance'])++ def ctl(*args):+ return output(['hyprctl', '-i', instance['instance'], *args], text=True).strip()++ assert ctl('plugin', 'load', plugin) == 'ok'+ foot = sp.Popen(['foot', '--config=/dev/null', 'sh', '-c',+ 'printf "CURSOR REGRESSION\\n"; sleep 120'], env=env,+ stdout=sp.DEVNULL, stderr=sp.DEVNULL)+ time.sleep(.8)+ monitor = json.loads(ctl('-j', 'monitors'))[0]+ assert monitor['scale'] == scale+ for mode in ['cursor-overlay', 'video']:+ child = sp.Popen([capture, mode, str(scale), '95', monitor['name']],+ env=env, stdin=sp.PIPE, stdout=sp.PIPE)+ paths = []+ for fraction in [.3, .7]:+ x = int(monitor['width'] / scale * fraction)+ y = int(monitor['height'] / scale * .6)+ assert ctl('eval', f'hl.dispatch(hl.dsp.cursor.move({{x={x},y={y}}}))') == 'ok'+ for _ in range(8):+ child.stdin.write(b'f')+ child.stdin.flush()+ assert select.select([child.stdout], [], [], 5)[0], 'Frame timeout'+ line = child.stdout.readline()+ assert line, 'Capture exited'+ frame = json.loads(line) if mode == 'cursor-overlay' else {'jpeg': line}+ time.sleep(.06)+ if mode == 'cursor-overlay':+ cursor = frame['cursor']+ assert cursor and cursor['visible'] and cursor['png']+ assert abs(cursor['x'] - x * scale / monitor['width']) < .002+ assert abs(cursor['y'] - y * scale / monitor['height']) < .002+ path = root / f'{mode}-{fraction}.jpg'+ path.write_bytes(base64.b64decode(frame['jpeg']))+ paths.append(str(path))+ stop(child)+ child = None+ diff = str(root / 'diff.png')+ output(['magick', *paths, '-compose', 'difference', '-composite', diff])+ for fraction in [.3, .7]:+ x, y = int(monitor['width'] * fraction), int(monitor['height'] * .6)+ mean = float(output(['magick', diff, '-crop', f'100x100+{x-50}+{y-50}',+ '-format', '%[fx:mean]', 'info:']))+ # Separate cursor: neither the old nor new pointer may be+ # burned into video. Legacy video must still include it.+ assert (mean < .001 if mode == 'cursor-overlay' else mean > .001), (mode, mean)+ print(f'PASS scale={scale} {mode}: coordinates / video pixels', flush=True)+ finally:+ stop(child)+ stop(foot)+ stop(compositor)+++if __name__ == '__main__':+ plugin, capture = (str(Path(p).resolve(strict=True)) for p in sys.argv[1:])+ for scale in [1, 1.6]:+ with tempfile.TemporaryDirectory(prefix='cindy-cursor-regression-') as directory:+ exercise(Path(directory), scale, plugin, capture)diff --git a/apps/desktop/native/remote-desktop/linux-capture/ext-foreign-toplevel-list-v1.xml b/apps/desktop/native/remote-desktop/linux-capture/ext-foreign-toplevel-list-v1.xmlnew file mode 100644index 0000000000..f1bbe0ea7e--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/ext-foreign-toplevel-list-v1.xml@@ -0,0 +1,219 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="ext_foreign_toplevel_list_v1">+ <copyright>+ Copyright © 2018 Ilia Bozhinov+ Copyright © 2020 Isaac Freund+ Copyright © 2022 wb9688+ Copyright © 2023 i509VCB++ Permission to use, copy, modify, distribute, and sell this+ software and its documentation for any purpose is hereby granted+ without fee, provided that the above copyright notice appear in+ all copies and that both that copyright notice and this permission+ notice appear in supporting documentation, and that the name of+ the copyright holders not be used in advertising or publicity+ pertaining to distribution of the software without specific,+ written prior permission. The copyright holders make no+ representations about the suitability of this software for any+ purpose. It is provided "as is" without express or implied+ warranty.++ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF+ THIS SOFTWARE.+ </copyright>++ <description summary="list toplevels">+ The purpose of this protocol is to provide protocol object handles for+ toplevels, possibly originating from another client.++ This protocol is intentionally minimalistic and expects additional+ functionality (e.g. creating a screencopy source from a toplevel handle,+ getting information about the state of the toplevel) to be implemented+ in extension protocols.++ The compositor may choose to restrict this protocol to a special client+ launched by the compositor itself or expose it to all clients,+ this is compositor policy.++ The key words "must", "must not", "required", "shall", "shall not",+ "should", "should not", "recommended", "may", and "optional" in this+ document are to be interpreted as described in IETF RFC 2119.++ Warning! The protocol described in this file is currently in the testing+ phase. Backward compatible changes may be added together with the+ corresponding interface version bump. Backward incompatible changes can+ only be done by creating a new major version of the extension.+ </description>++ <interface name="ext_foreign_toplevel_list_v1" version="1">+ <description summary="list toplevels">+ A toplevel is defined as a surface with a role similar to xdg_toplevel.+ XWayland surfaces may be treated like toplevels in this protocol.++ After a client binds the ext_foreign_toplevel_list_v1, each mapped+ toplevel window will be sent using the ext_foreign_toplevel_list_v1.toplevel+ event.++ Clients which only care about the current state can perform a roundtrip after+ binding this global.++ For each instance of ext_foreign_toplevel_list_v1, the compositor must+ create a new ext_foreign_toplevel_handle_v1 object for each mapped toplevel.++ If a compositor implementation sends the ext_foreign_toplevel_list_v1.finished+ event after the global is bound, the compositor must not send any+ ext_foreign_toplevel_list_v1.toplevel events.+ </description>++ <event name="toplevel">+ <description summary="a toplevel has been created">+ This event is emitted whenever a new toplevel window is created. It is+ emitted for all toplevels, regardless of the app that has created them.++ All initial properties of the toplevel (identifier, title, app_id) will be sent+ immediately after this event using the corresponding events for+ ext_foreign_toplevel_handle_v1. The compositor will use the+ ext_foreign_toplevel_handle_v1.done event to indicate when all data has+ been sent.+ </description>+ <arg name="toplevel" type="new_id" interface="ext_foreign_toplevel_handle_v1"/>+ </event>++ <event name="finished">+ <description summary="the compositor has finished with the toplevel manager">+ This event indicates that the compositor is done sending events+ to this object. The client should destroy the object.+ See ext_foreign_toplevel_list_v1.destroy for more information.++ The compositor must not send any more toplevel events after this event.+ </description>+ </event>++ <request name="stop">+ <description summary="stop sending events">+ This request indicates that the client no longer wishes to receive+ events for new toplevels.++ The Wayland protocol is asynchronous, meaning the compositor may send+ further toplevel events until the stop request is processed.+ The client should wait for a ext_foreign_toplevel_list_v1.finished+ event before destroying this object.+ </description>+ </request>++ <request name="destroy" type="destructor">+ <description summary="destroy the ext_foreign_toplevel_list_v1 object">+ This request should be called either when the client will no longer+ use the ext_foreign_toplevel_list_v1 or after the finished event+ has been received to allow destruction of the object.++ If a client wishes to destroy this object it should send a+ ext_foreign_toplevel_list_v1.stop request and wait for a ext_foreign_toplevel_list_v1.finished+ event, then destroy the handles and then this object.+ </description>+ </request>+ </interface>++ <interface name="ext_foreign_toplevel_handle_v1" version="1">+ <description summary="a mapped toplevel">+ A ext_foreign_toplevel_handle_v1 object represents a mapped toplevel+ window. A single app may have multiple mapped toplevels.+ </description>++ <request name="destroy" type="destructor">+ <description summary="destroy the ext_foreign_toplevel_handle_v1 object">+ This request should be used when the client will no longer use the handle+ or after the closed event has been received to allow destruction of the+ object.++ When a handle is destroyed, a new handle may not be created by the server+ until the toplevel is unmapped and then remapped. Destroying a toplevel handle+ is not recommended unless the client is cleaning up child objects+ before destroying the ext_foreign_toplevel_list_v1 object, the toplevel+ was closed or the toplevel handle will not be used in the future.++ Other protocols which extend the ext_foreign_toplevel_handle_v1+ interface should require destructors for extension interfaces be+ called before allowing the toplevel handle to be destroyed.+ </description>+ </request>++ <event name="closed">+ <description summary="the toplevel has been closed">+ The server will emit no further events on the ext_foreign_toplevel_handle_v1+ after this event. Any requests received aside from the destroy request must+ be ignored. Upon receiving this event, the client should destroy the handle.++ Other protocols which extend the ext_foreign_toplevel_handle_v1+ interface must also ignore requests other than destructors.+ </description>+ </event>++ <event name="done">+ <description summary="all information about the toplevel has been sent">+ This event is sent after all changes in the toplevel state have+ been sent.++ This allows changes to the ext_foreign_toplevel_handle_v1 properties+ to be atomically applied. Other protocols which extend the+ ext_foreign_toplevel_handle_v1 interface may use this event to also+ atomically apply any pending state.++ This event must not be sent after the ext_foreign_toplevel_handle_v1.closed+ event.+ </description>+ </event>++ <event name="title">+ <description summary="title change">+ The title of the toplevel has changed.++ The configured state must not be applied immediately. See+ ext_foreign_toplevel_handle_v1.done for details.+ </description>+ <arg name="title" type="string"/>+ </event>++ <event name="app_id">+ <description summary="app_id change">+ The app id of the toplevel has changed.++ The configured state must not be applied immediately. See+ ext_foreign_toplevel_handle_v1.done for details.+ </description>+ <arg name="app_id" type="string"/>+ </event>++ <event name="identifier">+ <description summary="a stable identifier for a toplevel">+ This identifier is used to check if two or more toplevel handles belong+ to the same toplevel.++ The identifier is useful for command line tools or privileged clients+ which may need to reference an exact toplevel across processes or+ instances of the ext_foreign_toplevel_list_v1 global.++ The compositor must only send this event when the handle is created.++ The identifier must be unique per toplevel and its handles. Two different+ toplevels must not have the same identifier. The identifier is only valid+ as long as the toplevel is mapped. If the toplevel is unmapped the identifier+ must not be reused. An identifier must not be reused by the compositor to+ ensure there are no races when sharing identifiers between processes.++ An identifier is a string that contains up to 32 printable ASCII bytes.+ An identifier must not be an empty string. It is recommended that a+ compositor includes an opaque generation value in identifiers. How the+ generation value is used when generating the identifier is implementation+ dependent.+ </description>+ <arg name="identifier" type="string"/>+ </event>+ </interface>+</protocol>diff --git a/apps/desktop/native/remote-desktop/linux-capture/ext-image-capture-source-v1.xml b/apps/desktop/native/remote-desktop/linux-capture/ext-image-capture-source-v1.xmlnew file mode 100644index 0000000000..e0808c25a8--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/ext-image-capture-source-v1.xml@@ -0,0 +1,109 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="ext_image_capture_source_v1">+ <copyright>+ Copyright © 2022 Andri Yngvason+ Copyright © 2024 Simon Ser++ Permission is hereby granted, free of charge, to any person obtaining a+ copy of this software and associated documentation files (the "Software"),+ to deal in the Software without restriction, including without limitation+ the rights to use, copy, modify, merge, publish, distribute, sublicense,+ and/or sell copies of the Software, and to permit persons to whom the+ Software is furnished to do so, subject to the following conditions:++ The above copyright notice and this permission notice (including the next+ paragraph) shall be included in all copies or substantial portions of the+ Software.++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+ DEALINGS IN THE SOFTWARE.+ </copyright>++ <description summary="opaque image capture source objects">+ This protocol serves as an intermediary between capturing protocols and+ potential image capture sources such as outputs and toplevels.++ This protocol may be extended to support more image capture sources in the+ future, thereby adding those image capture sources to other protocols that+ use the image capture source object without having to modify those+ protocols.++ Warning! The protocol described in this file is currently in the testing+ phase. Backward compatible changes may be added together with the+ corresponding interface version bump. Backward incompatible changes can+ only be done by creating a new major version of the extension.+ </description>++ <interface name="ext_image_capture_source_v1" version="1" frozen="true">+ <description summary="opaque image capture source object">+ The image capture source object is an opaque descriptor for a capturable+ resource. This resource may be any sort of entity from which an image+ may be derived.++ Note, because ext_image_capture_source_v1 objects are created from multiple+ independent factory interfaces, the ext_image_capture_source_v1 interface is+ frozen at version 1.+ </description>++ <request name="destroy" type="destructor">+ <description summary="delete this object">+ Destroys the image capture source. This request may be sent at any time+ by the client.+ </description>+ </request>+ </interface>++ <interface name="ext_output_image_capture_source_manager_v1" version="1">+ <description summary="image capture source manager for outputs">+ A manager for creating image capture source objects for wl_output objects.+ </description>++ <request name="create_source">+ <description summary="create source object for output">+ Creates a source object for an output. Images captured from this source+ will show the same content as the output. Some elements may be omitted,+ such as cursors and overlays that have been marked as transparent to+ capturing.+ </description>+ <arg name="source" type="new_id" interface="ext_image_capture_source_v1"/>+ <arg name="output" type="object" interface="wl_output"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="delete this object">+ Destroys the manager. This request may be sent at any time by the client+ and objects created by the manager will remain valid after its+ destruction.+ </description>+ </request>+ </interface>++ <interface name="ext_foreign_toplevel_image_capture_source_manager_v1" version="1">+ <description summary="image capture source manager for foreign toplevels">+ A manager for creating image capture source objects for+ ext_foreign_toplevel_handle_v1 objects.+ </description>++ <request name="create_source">+ <description summary="create source object for foreign toplevel">+ Creates a source object for a foreign toplevel handle. Images captured+ from this source will show the same content as the toplevel.+ </description>+ <arg name="source" type="new_id" interface="ext_image_capture_source_v1"/>+ <arg name="toplevel_handle" type="object" interface="ext_foreign_toplevel_handle_v1"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="delete this object">+ Destroys the manager. This request may be sent at any time by the client+ and objects created by the manager will remain valid after its+ destruction.+ </description>+ </request>+ </interface>+</protocol>diff --git a/apps/desktop/native/remote-desktop/linux-capture/ext-image-copy-capture-v1.xml b/apps/desktop/native/remote-desktop/linux-capture/ext-image-copy-capture-v1.xmlnew file mode 100644index 0000000000..1ac43696a0--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/ext-image-copy-capture-v1.xml@@ -0,0 +1,456 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="ext_image_copy_capture_v1">+ <copyright>+ Copyright © 2021-2023 Andri Yngvason+ Copyright © 2024 Simon Ser++ Permission is hereby granted, free of charge, to any person obtaining a+ copy of this software and associated documentation files (the "Software"),+ to deal in the Software without restriction, including without limitation+ the rights to use, copy, modify, merge, publish, distribute, sublicense,+ and/or sell copies of the Software, and to permit persons to whom the+ Software is furnished to do so, subject to the following conditions:++ The above copyright notice and this permission notice (including the next+ paragraph) shall be included in all copies or substantial portions of the+ Software.++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+ DEALINGS IN THE SOFTWARE.+ </copyright>++ <description summary="image capturing into client buffers">+ This protocol allows clients to ask the compositor to capture image sources+ such as outputs and toplevels into user submitted buffers.++ Warning! The protocol described in this file is currently in the testing+ phase. Backward compatible changes may be added together with the+ corresponding interface version bump. Backward incompatible changes can+ only be done by creating a new major version of the extension.+ </description>++ <interface name="ext_image_copy_capture_manager_v1" version="1">+ <description summary="manager to inform clients and begin capturing">+ This object is a manager which offers requests to start capturing from a+ source.+ </description>++ <enum name="error">+ <entry name="invalid_option" value="1" summary="invalid option flag"/>+ </enum>++ <enum name="options" bitfield="true">+ <entry name="paint_cursors" value="1" summary="paint cursors onto captured frames"/>+ </enum>++ <request name="create_session">+ <description summary="capture an image capture source">+ Create a capturing session for an image capture source.++ If the paint_cursors option is set, cursors shall be composited onto+ the captured frame. The cursor must not be composited onto the frame+ if this flag is not set.++ If the options bitfield is invalid, the invalid_option protocol error+ is sent.+ </description>+ <arg name="session" type="new_id" interface="ext_image_copy_capture_session_v1"/>+ <arg name="source" type="object" interface="ext_image_capture_source_v1"/>+ <arg name="options" type="uint" enum="options"/>+ </request>++ <request name="create_pointer_cursor_session">+ <description summary="capture the pointer cursor of an image capture source">+ Create a cursor capturing session for the pointer of an image capture+ source.+ </description>+ <arg name="session" type="new_id" interface="ext_image_copy_capture_cursor_session_v1"/>+ <arg name="source" type="object" interface="ext_image_capture_source_v1"/>+ <arg name="pointer" type="object" interface="wl_pointer"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="destroy the manager">+ Destroy the manager object.++ Other objects created via this interface are unaffected.+ </description>+ </request>+ </interface>++ <interface name="ext_image_copy_capture_session_v1" version="1">+ <description summary="image copy capture session">+ This object represents an active image copy capture session.++ After a capture session is created, buffer constraint events will be+ emitted from the compositor to tell the client which buffer types and+ formats are supported for reading from the session. The compositor may+ re-send buffer constraint events whenever they change.++ To advertise buffer constraints, the compositor must send in no+ particular order: zero or more shm_format and dmabuf_format events, zero+ or one dmabuf_device event, and exactly one buffer_size event. Then the+ compositor must send a done event.++ When the client has received all the buffer constraints, it can create a+ buffer accordingly, attach it to the capture session using the+ attach_buffer request, set the buffer damage using the damage_buffer+ request and then send the capture request.+ </description>++ <enum name="error">+ <entry name="duplicate_frame" value="1"+ summary="create_frame sent before destroying previous frame"/>+ </enum>++ <event name="buffer_size">+ <description summary="image capture source dimensions">+ Provides the dimensions of the source image in buffer pixel coordinates.++ The client must attach buffers that match this size.+ </description>+ <arg name="width" type="uint" summary="buffer width"/>+ <arg name="height" type="uint" summary="buffer height"/>+ </event>++ <event name="shm_format">+ <description summary="shm buffer format">+ Provides the format that must be used for shared-memory buffers.++ This event may be emitted multiple times, in which case the client may+ choose any given format.+ </description>+ <arg name="format" type="uint" enum="wl_shm.format" summary="shm format"/>+ </event>++ <event name="dmabuf_device">+ <description summary="dma-buf device">+ This event advertises the device buffers must be allocated on for+ dma-buf buffers.++ In general the device is a DRM node. The DRM node type (primary vs.+ render) is unspecified. Clients must not rely on the compositor sending+ a particular node type. Clients cannot check two devices for equality+ by comparing the dev_t value.+ </description>+ <arg name="device" type="array" summary="device dev_t value"/>+ </event>++ <event name="dmabuf_format">+ <description summary="dma-buf format">+ Provides the format that must be used for dma-buf buffers.++ The client may choose any of the modifiers advertised in the array of+ 64-bit unsigned integers.++ This event may be emitted multiple times, in which case the client may+ choose any given format.+ </description>+ <arg name="format" type="uint" summary="drm format code"/>+ <arg name="modifiers" type="array" summary="drm format modifiers"/>+ </event>++ <event name="done">+ <description summary="all constraints have been sent">+ This event is sent once when all buffer constraint events have been+ sent.++ The compositor must always end a batch of buffer constraint events with+ this event, regardless of whether it sends the initial constraints or+ an update.+ </description>+ </event>++ <event name="stopped">+ <description summary="session is no longer available">+ This event indicates that the capture session has stopped and is no+ longer available. This can happen in a number of cases, e.g. when the+ underlying source is destroyed, if the user decides to end the image+ capture, or if an unrecoverable runtime error has occurred.++ The client should destroy the session after receiving this event.+ </description>+ </event>++ <request name="create_frame">+ <description summary="create a frame">+ Create a capture frame for this session.++ At most one frame object can exist for a given session at any time. If+ a client sends a create_frame request before a previous frame object+ has been destroyed, the duplicate_frame protocol error is raised.+ </description>+ <arg name="frame" type="new_id" interface="ext_image_copy_capture_frame_v1"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="delete this object">+ Destroys the session. This request can be sent at any time by the+ client.++ This request doesn't affect ext_image_copy_capture_frame_v1 objects created by+ this object.+ </description>+ </request>+ </interface>++ <interface name="ext_image_copy_capture_frame_v1" version="1">+ <description summary="image capture frame">+ This object represents an image capture frame.++ The client should attach a buffer, damage the buffer, and then send a+ capture request.++ If the capture is successful, the compositor must send the frame metadata+ (transform, damage, presentation_time in any order) followed by the ready+ event.++ If the capture fails, the compositor must send the failed event.+ </description>++ <enum name="error">+ <entry name="no_buffer" value="1" summary="capture sent without attach_buffer"/>+ <entry name="invalid_buffer_damage" value="2" summary="invalid buffer damage"/>+ <entry name="already_captured" value="3" summary="capture request has been sent"/>+ </enum>++ <request name="destroy" type="destructor">+ <description summary="destroy this object">+ Destroys the frame. This request can be sent at any time by the+ client.+ </description>+ </request>++ <request name="attach_buffer">+ <description summary="attach buffer to session">+ Attach a buffer to the session.++ The wl_buffer.release request is unused.++ The new buffer replaces any previously attached buffer.++ This request must not be sent after capture, or else the+ already_captured protocol error is raised.+ </description>+ <arg name="buffer" type="object" interface="wl_buffer"/>+ </request>++ <request name="damage_buffer">+ <description summary="damage buffer">+ Apply damage to the buffer which is to be captured next. This request+ may be sent multiple times to describe a region.++ The client indicates the accumulated damage since this wl_buffer was+ last captured. During capture, the compositor will update the buffer+ with at least the union of the region passed by the client and the+ region advertised by ext_image_copy_capture_frame_v1.damage.++ When a wl_buffer is captured for the first time, or when the client+ doesn't track damage, the client must damage the whole buffer.++ This is for optimisation purposes. The compositor may use this+ information to reduce copying.++ These coordinates originate from the upper left corner of the buffer.++ If x or y are strictly negative, or if width or height are negative or+ zero, the invalid_buffer_damage protocol error is raised.++ This request must not be sent after capture, or else the+ already_captured protocol error is raised.+ </description>+ <arg name="x" type="int" summary="region x coordinate"/>+ <arg name="y" type="int" summary="region y coordinate"/>+ <arg name="width" type="int" summary="region width"/>+ <arg name="height" type="int" summary="region height"/>+ </request>++ <request name="capture">+ <description summary="capture a frame">+ Capture a frame.++ Unless this is the first successful captured frame performed in this+ session, the compositor may wait an indefinite amount of time for the+ source content to change before performing the copy.++ This request may only be sent once, or else the already_captured+ protocol error is raised. A buffer must be attached before this request+ is sent, or else the no_buffer protocol error is raised.+ </description>+ </request>++ <event name="transform">+ <description summary="buffer transform">+ This event is sent before the ready event and holds the transform that+ the compositor has applied to the buffer contents.+ </description>+ <arg name="transform" type="uint" enum="wl_output.transform"/>+ </event>++ <event name="damage">+ <description summary="buffer damaged region">+ This event is sent before the ready event. It may be generated multiple+ times to describe a region.++ The first captured frame in a session will always carry full damage.+ Subsequent frames' damaged regions describe which parts of the buffer+ have changed since the last ready event.++ These coordinates originate in the upper left corner of the buffer.+ </description>+ <arg name="x" type="int" summary="damage x coordinate"/>+ <arg name="y" type="int" summary="damage y coordinate"/>+ <arg name="width" type="int" summary="damage width"/>+ <arg name="height" type="int" summary="damage height"/>+ </event>++ <event name="presentation_time">+ <description summary="presentation time of the frame">+ This event indicates the time at which the frame is presented to the+ output in system monotonic time. This event is sent before the ready+ event.++ The timestamp is expressed as tv_sec_hi, tv_sec_lo, tv_nsec triples,+ each component being an unsigned 32-bit value. Whole seconds are in+ tv_sec which is a 64-bit value combined from tv_sec_hi and tv_sec_lo,+ and the additional fractional part in tv_nsec as nanoseconds. Hence,+ for valid timestamps tv_nsec must be in [0, 999999999].+ </description>+ <arg name="tv_sec_hi" type="uint"+ summary="high 32 bits of the seconds part of the timestamp"/>+ <arg name="tv_sec_lo" type="uint"+ summary="low 32 bits of the seconds part of the timestamp"/>+ <arg name="tv_nsec" type="uint"+ summary="nanoseconds part of the timestamp"/>+ </event>++ <event name="ready">+ <description summary="frame is available for reading">+ Called as soon as the frame is copied, indicating it is available+ for reading.++ The buffer may be re-used by the client after this event.++ After receiving this event, the client must destroy the object.+ </description>+ </event>++ <enum name="failure_reason">+ <entry name="unknown" value="0">+ <description summary="unknown runtime error">+ An unspecified runtime error has occurred. The client may retry.+ </description>+ </entry>+ <entry name="buffer_constraints" value="1">+ <description summary="buffer constraints mismatch">+ The buffer submitted by the client doesn't match the latest session+ constraints. The client should re-allocate its buffers and retry.+ </description>+ </entry>+ <entry name="stopped" value="2">+ <description summary="session is no longer available">+ The session has stopped. See ext_image_copy_capture_session_v1.stopped.+ </description>+ </entry>+ </enum>++ <event name="failed">+ <description summary="capture failed">+ This event indicates that the attempted frame copy has failed.++ After receiving this event, the client must destroy the object.+ </description>+ <arg name="reason" type="uint" enum="failure_reason"/>+ </event>+ </interface>++ <interface name="ext_image_copy_capture_cursor_session_v1" version="1">+ <description summary="cursor capture session">+ This object represents a cursor capture session. It extends the base+ capture session with cursor-specific metadata.+ </description>++ <enum name="error">+ <entry name="duplicate_session" value="1" summary="get_capture_session sent twice"/>+ </enum>++ <request name="destroy" type="destructor">+ <description summary="delete this object">+ Destroys the session. This request can be sent at any time by the+ client.++ This request doesn't affect ext_image_copy_capture_frame_v1 objects created by+ this object.+ </description>+ </request>++ <request name="get_capture_session">+ <description summary="get image copy capturer session">+ Gets the image copy capture session for this cursor session.++ The session will produce frames of the cursor image. The compositor may+ pause the session when the cursor leaves the captured area.++ This request must not be sent more than once, or else the+ duplicate_session protocol error is raised.+ </description>+ <arg name="session" type="new_id" interface="ext_image_copy_capture_session_v1"/>+ </request>++ <event name="enter">+ <description summary="cursor entered captured area">+ Sent when a cursor enters the captured area. It shall be generated+ before the "position" and "hotspot" events when and only when a cursor+ enters the area.++ The cursor enters the captured area when the cursor image intersects+ with the captured area. Note, this is different from e.g.+ wl_pointer.enter.+ </description>+ </event>++ <event name="leave">+ <description summary="cursor left captured area">+ Sent when a cursor leaves the captured area. No "position" or "hotspot"+ event is generated for the cursor until the cursor enters the captured+ area again.+ </description>+ </event>++ <event name="position">+ <description summary="position changed">+ Cursors outside the image capture source do not get captured and no+ event will be generated for them.++ The given position is the position of the cursor's hotspot and it is+ relative to the main buffer's top left corner in transformed buffer+ pixel coordinates. The coordinates may be negative or greater than the+ main buffer size.+ </description>+ <arg name="x" type="int" summary="position x coordinates"/>+ <arg name="y" type="int" summary="position y coordinates"/>+ </event>++ <event name="hotspot">+ <description summary="hotspot changed">+ The hotspot describes the offset between the cursor image and the+ position of the input device.++ The given coordinates are the hotspot's offset from the origin in+ buffer coordinates.++ Clients should not apply the hotspot immediately: the hotspot becomes+ effective when the next ext_image_copy_capture_frame_v1.ready event is received.++ Compositors may delay this event until the client captures a new frame.+ </description>+ <arg name="x" type="int" summary="hotspot x coordinates"/>+ <arg name="y" type="int" summary="hotspot y coordinates"/>+ </event>+ </interface>+</protocol>diff --git a/apps/desktop/native/remote-desktop/linux-capture/main.c b/apps/desktop/native/remote-desktop/linux-capture/main.cnew file mode 100644index 0000000000..37eacd32fd--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/main.c@@ -0,0 +1,460 @@+#define _GNU_SOURCE+#include "cursor.h"+#include "wlr-screencopy-unstable-v1.h"+#include <errno.h>+#include <signal.h>+#include <stdint.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/mman.h>+#include <turbojpeg.h>+#include <unistd.h>+#include <wayland-client.h>++/* Private, serial protocol: one 'f' request, one bounded base64 JPEG line.+ * The connection and shm buffer survive requests, but no frame history does.+ * Unsupported output layouts exit so the parent can use grim's composition.+ */+struct output_info {+ struct wl_output *output;+ uint32_t id;+ int transform;+ char name[128];+};+struct capture {+ struct wl_display *display;+ struct wl_shm *shm;+ struct wl_output *output;+ struct zwlr_screencopy_manager_v1 *manager;+ struct wl_buffer *buffer;+ uint32_t output_name, outputs, width, height, stride, format;+ int transform, done, failed;+ uint32_t flags;+ void *pixels;+ unsigned char *scaled, *oriented;+ size_t size;+ int overlay, quality, cursor_free;+ struct output_info output_info[32];+ const char *requested_output;+};+static void geometry(void *data, struct wl_output *output, int32_t x, int32_t y,+ int32_t pw, int32_t ph, int32_t subpixel, const char *make,+ const char *model, int32_t transform) {+ (void)output;+ (void)x;+ (void)y;+ (void)pw;+ (void)ph;+ (void)subpixel;+ (void)make;+ (void)model;+ ((struct output_info *)data)->transform = transform;+}+static void mode(void *data, struct wl_output *output, uint32_t flags,+ int32_t width, int32_t height, int32_t refresh) {+ (void)data;+ (void)output;+ (void)flags;+ (void)width;+ (void)height;+ (void)refresh;+}+static void output_done(void *d, struct wl_output *o) {+ (void)d;+ (void)o;+}+static void output_scale(void *d, struct wl_output *o, int32_t s) {+ (void)d;+ (void)o;+ (void)s;+}+static void output_name(void *d, struct wl_output *o, const char *name) {+ (void)o;+ snprintf(((struct output_info *)d)->name, 128, "%s", name);+}+static void output_description(void *d, struct wl_output *o, const char *s) {+ (void)d;+ (void)o;+ (void)s;+}+static const struct wl_output_listener output_listener = {+ .geometry = geometry,+ .mode = mode,+ .done = output_done,+ .scale = output_scale,+ .name = output_name,+ .description = output_description};+static void global(void *data, struct wl_registry *registry, uint32_t name,+ const char *interface, uint32_t version) {+ (void)version;+ struct capture *c = data;+ cursor_global(registry, name, interface);+ if (!strcmp(interface, wl_shm_interface.name))+ c->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);+ else if (!strcmp(interface, zwlr_screencopy_manager_v1_interface.name))+ c->manager = wl_registry_bind(registry, name,+ &zwlr_screencopy_manager_v1_interface, 1);+ else if (!strcmp(interface, wl_output_interface.name)) {+ if (c->outputs >= 32) {+ c->failed = 1;+ return;+ }+ struct output_info *o = &c->output_info[c->outputs++];+ o->id = name;+ o->output = wl_registry_bind(registry, name, &wl_output_interface,+ version < 4 ? version : 4);+ wl_output_add_listener(o->output, &output_listener, o);+ }+}+static void removed(void *data, struct wl_registry *registry, uint32_t name) {+ (void)registry;+ struct capture *c = data;+ /* A changed layout requires the parent to obtain fresh display geometry. */+ if (name == c->output_name)+ c->failed = 1;+}+static const struct wl_registry_listener registry_listener = {global, removed};+static void release_buffer(struct capture *c) {+ if (c->buffer)+ wl_buffer_destroy(c->buffer);+ if (c->pixels)+ munmap(c->pixels, c->size);+ c->buffer = NULL;+ c->pixels = NULL;+ c->size = 0;+}+static void frame_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame,+ uint32_t format, uint32_t width, uint32_t height,+ uint32_t stride) {+ struct capture *c = data;+ if (!width || !height || width > 8192 || height > 8192 ||+ (uint64_t)width * height > 16777216 || stride < width * 4 ||+ (uint64_t)stride * height > 67108864 ||+ (format != WL_SHM_FORMAT_XRGB8888 && format != WL_SHM_FORMAT_ARGB8888 &&+ format != WL_SHM_FORMAT_XBGR8888 && format != WL_SHM_FORMAT_ABGR8888)) {+ c->failed = 1;+ return;+ }+ if (!c->buffer || c->width != width || c->height != height ||+ c->stride != stride || c->format != format) {+ release_buffer(c);+ size_t size = (size_t)stride * height;+ int fd = memfd_create("cindy-capture", MFD_CLOEXEC);+ if (fd < 0) {+ c->failed = 1;+ return;+ }+ if (ftruncate(fd, (off_t)size)) {+ close(fd);+ c->failed = 1;+ return;+ }+ void *pixels = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);+ if (pixels == MAP_FAILED) {+ close(fd);+ c->failed = 1;+ return;+ }+ struct wl_shm_pool *pool = wl_shm_create_pool(c->shm, fd, (int32_t)size);+ c->buffer = wl_shm_pool_create_buffer(+ pool, 0, (int32_t)width, (int32_t)height, (int32_t)stride, format);+ wl_shm_pool_destroy(pool);+ close(fd);+ c->pixels = pixels;+ c->size = size;+ c->width = width;+ c->height = height;+ c->stride = stride;+ c->format = format;+ }+ zwlr_screencopy_frame_v1_copy(frame, c->buffer);+}+static void frame_flags(void *data, struct zwlr_screencopy_frame_v1 *frame,+ uint32_t flags) {+ (void)frame;+ ((struct capture *)data)->flags = flags;+}+static void frame_ready(void *data, struct zwlr_screencopy_frame_v1 *frame,+ uint32_t high, uint32_t low, uint32_t ns) {+ (void)frame;+ (void)high;+ (void)low;+ (void)ns;+ ((struct capture *)data)->done = 1;+}+static void frame_failed(void *data, struct zwlr_screencopy_frame_v1 *frame) {+ (void)frame;+ ((struct capture *)data)->failed = 1;+}+static const struct zwlr_screencopy_frame_v1_listener frame_listener = {+ .buffer = frame_buffer,+ .flags = frame_flags,+ .ready = frame_ready,+ .failed = frame_failed};+/* Match the normal desktop video's 1920-pixel long-edge cap before IPC and+ * decoding. Bilinear sampling preserves aspect ratio and supports padded rows.+ * The one scratch buffer is reused for the lifetime of this capture child. */+static const unsigned char *video_pixels(struct capture *c, int *width,+ int *height, int *stride) {+ *width = (int)c->width;+ *height = (int)c->height;+ *stride = (int)c->stride;+ uint32_t edge = c->width > c->height ? c->width : c->height;+ if (edge <= 1920)+ return c->pixels;+ *width = (int)(c->width * 1920 / edge);+ *height = (int)(c->height * 1920 / edge);+ if (*width < 1)+ *width = 1;+ if (*height < 1)+ *height = 1;+ *stride = *width * 4;+ if (!c->scaled)+ c->scaled = malloc(1920 * 1920 * 4);+ if (!c->scaled)+ return NULL;+ uint32_t xs[1920], weights[1920];+ for (int x = 0; x < *width; x++) {+ uint32_t pos =+ *width > 1+ ? (uint32_t)((uint64_t)x * (c->width - 1) * 256 / (*width - 1))+ : 0;+ xs[x] = pos >> 8;+ weights[x] = pos & 255;+ }+ for (int y = 0; y < *height; y++) {+ uint32_t pos =+ *height > 1+ ? (uint32_t)((uint64_t)y * (c->height - 1) * 256 / (*height - 1))+ : 0;+ uint32_t sy = pos >> 8, wy = pos & 255;+ uint32_t next = sy + 1 < c->height ? sy + 1 : sy;+ const unsigned char *a = (const unsigned char *)c->pixels + sy * c->stride;+ const unsigned char *b =+ (const unsigned char *)c->pixels + next * c->stride;+ unsigned char *dest = c->scaled + y * *stride;+ for (int x = 0; x < *width; x++) {+ uint32_t sx = xs[x], wx = weights[x],+ nx = sx + 1 < c->width ? sx + 1 : sx;+ for (int channel = 0; channel < 3; channel++) {+ uint32_t top =+ a[sx * 4 + channel] * (256 - wx) + a[nx * 4 + channel] * wx;+ uint32_t bottom =+ b[sx * 4 + channel] * (256 - wx) + b[nx * 4 + channel] * wx;+ dest[x * 4 + channel] =+ (unsigned char)((top * (256 - wy) + bottom * wy + 32768) >> 16);+ }+ dest[x * 4 + 3] = 255;+ }+ }+ return c->scaled;+}+/* Screencopy buffers use output-buffer coordinates. Rotate into the displayed+ * orientation after bounded scaling, applying Y_INVERT in buffer coordinates.+ * Keep the normal output's zero-copy path and reuse at most one extra buffer. */+static const unsigned char *oriented_pixels(struct capture *c, int *width,+ int *height, int *stride) {+ const unsigned char *source = video_pixels(c, width, height, stride);+ if (!source || c->transform == WL_OUTPUT_TRANSFORM_NORMAL)+ return source;+ if (c->transform < 0 || c->transform > WL_OUTPUT_TRANSFORM_FLIPPED_270)+ return NULL;+ int sw = *width, sh = *height, ss = *stride;+ int rotation = c->transform & 3;+ if (rotation & 1) {+ *width = sh;+ *height = sw;+ }+ *stride = *width * 4;+ if (!c->oriented)+ c->oriented = malloc(1920 * 1920 * 4);+ if (!c->oriented)+ return NULL;+ for (int y = 0; y < sh; y++) {+ int sy = c->flags & ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT ? sh - 1 - y : y;+ for (int x = 0; x < sw; x++) {+ int dx = x, dy = y;+ switch (rotation) {+ case 1: dx = sh - 1 - y; dy = x; break;+ case 2: dx = sw - 1 - x; dy = sh - 1 - y; break;+ case 3: dx = y; dy = sw - 1 - x; break;+ }+ if (c->transform & WL_OUTPUT_TRANSFORM_FLIPPED)+ dx = *width - 1 - dx;+ memcpy(c->oriented + dy * *stride + dx * 4, source + sy * ss + x * 4, 4);+ }+ }+ return c->oriented;+}+static int send_jpeg(struct capture *c, tjhandle encoder) {+ unsigned char *jpeg = NULL;+ unsigned long length = 0;+ int format = (c->format == WL_SHM_FORMAT_XRGB8888 ||+ c->format == WL_SHM_FORMAT_ARGB8888)+ ? TJPF_BGRX+ : TJPF_RGBX;+ int flags = TJFLAG_FASTDCT;+ if (c->transform == WL_OUTPUT_TRANSFORM_NORMAL &&+ (c->flags & ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT))+ flags |= TJFLAG_BOTTOMUP;+ int width, height, stride;+ const unsigned char *pixels = oriented_pixels(c, &width, &height, &stride);+ if (!pixels)+ return -1;+ int status = -1;+ for (int quality = c->quality ? c->quality : 65; quality >= 25;+ quality -= 20) {+ if (tjCompress2(encoder, pixels, width, stride, height, format, &jpeg,+ &length, TJSAMP_420, quality, flags))+ goto done;+ if (length <= 1000000)+ break;+ }+ if (!length || length > 1000000)+ goto done;+ static const char alphabet[] =+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";+ size_t count = 4 * ((length + 2) / 3);+ char *line = malloc(count + 1);+ if (!line)+ goto done;+ for (size_t i = 0, j = 0; i < length; i += 3) {+ uint32_t value = (uint32_t)jpeg[i] << 16;+ if (i + 1 < length)+ value |= (uint32_t)jpeg[i + 1] << 8;+ if (i + 2 < length)+ value |= jpeg[i + 2];+ line[j++] = alphabet[value >> 18];+ line[j++] = alphabet[(value >> 12) & 63];+ line[j++] = i + 1 < length ? alphabet[(value >> 6) & 63] : '=';+ line[j++] = i + 2 < length ? alphabet[value & 63] : '=';+ }+ line[count] = 0;+ if (c->overlay) {+ printf("{\"jpeg\":\"%s\",\"cursor\":", line);+ if (c->cursor_free)+ cursor_json(c->width, c->height);+ else+ fputs("null", stdout);+ fputs("}\n", stdout);+ } else {+ fwrite(line, 1, count, stdout);+ fputc('\n', stdout);+ }+ status = ferror(stdout) || fflush(stdout) ? -1 : 0;+ free(line);+done:+ tjFree(jpeg);+ return status;+}+int main(int argc, char **argv) {+ if (argc != 1 && argc != 4 && argc != 5 && argc != 2)+ return 2;+ struct capture c = {0};+ int probe = argc == 2 && !strcmp(argv[1], "--cursor-check");+ if (argc == 2 && !probe)+ return 2;+ if (argc == 4 || argc == 5) {+ c.overlay = !strcmp(argv[1], "cursor-overlay");+ if (!c.overlay && strcmp(argv[1], "video"))+ return 2;+ cc.scale = strtod(argv[2], NULL);+ c.quality = atoi(argv[3]);+ if (!isfinite(cc.scale) || cc.scale < 0.25 || cc.scale > 8 ||+ c.quality < 25 || c.quality > 95)+ return 2;+ if (argc == 5)+ c.requested_output = argv[4];+ }+ /* Bound compositor stalls, blocked writes and orphaned idle children. No+ * files survive a signal exit: memfd and Wayland objects belong to this+ * process. */+ alarm(3);+ c.display = wl_display_connect(NULL);+ if (!c.display)+ return 1;+ struct wl_registry *registry = wl_display_get_registry(c.display);+ wl_registry_add_listener(registry, ®istry_listener, &c);+ int status = 1;+ tjhandle encoder = NULL;+ if (wl_display_roundtrip(c.display) < 0 ||+ wl_display_roundtrip(c.display) < 0 || !c.shm || !c.manager || c.failed)+ goto done;+ if (probe) {+ status = cc.manager && cc.sources && cc.seat ? 0 : 1;+ if (!status)+ puts("ready");+ goto done;+ }+ for (uint32_t i = 0; i < c.outputs; i++) {+ struct output_info *o = &c.output_info[i];+ if ((c.requested_output && !strcmp(o->name, c.requested_output)) ||+ (!c.requested_output && c.outputs == 1)) {+ c.output = o->output;+ c.output_name = o->id;+ c.transform = o->transform;+ break;+ }+ }+ if (!c.output)+ goto done;+ if (c.overlay && cursor_begin(c.shm, c.output))+ goto done;+ encoder = tjInitCompress();+ if (!encoder)+ goto done;+ for (;;) {+ alarm(10);+ char command;+ ssize_t n = read(STDIN_FILENO, &command, 1);+ if (!n) {+ status = 0;+ break;+ }+ if (n != 1 || command != 'f')+ break;+ alarm(3);+ c.done = 0;+ c.flags = 0;+ if (c.failed)+ break;+ /* Hyprland 0.56 can return a transparent image for compositor-owned+ * cursors. Keep the baked OS cursor until a real image is available. */+ c.cursor_free = c.overlay && cc.has_image && !cc.failed &&+ c.transform == WL_OUTPUT_TRANSFORM_NORMAL;+ struct zwlr_screencopy_frame_v1 *frame =+ zwlr_screencopy_manager_v1_capture_output(c.manager, !c.cursor_free,+ c.output);+ zwlr_screencopy_frame_v1_add_listener(frame, &frame_listener, &c);+ while (!c.done && !c.failed) {+ if (wl_display_dispatch(c.display) < 0) {+ c.failed = 1;+ break;+ }+ }+ zwlr_screencopy_frame_v1_destroy(frame);+ for (uint32_t i = 0; i < c.outputs; i++)+ if (c.output_info[i].id == c.output_name &&+ c.output_info[i].transform != c.transform)+ c.failed = 1; // Layout changed during this capture; obtain fresh geometry.+ if (c.failed || send_jpeg(&c, encoder))+ break;+ }+done:+ cursor_destroy();+ if (encoder)+ tjDestroy(encoder);+ release_buffer(&c);+ free(c.scaled);+ free(c.oriented);+ for (uint32_t i = 0; i < c.outputs; i++)+ wl_output_destroy(c.output_info[i].output);+ if (c.manager)+ zwlr_screencopy_manager_v1_destroy(c.manager);+ if (c.shm)+ wl_shm_destroy(c.shm);+ wl_registry_destroy(registry);+ wl_display_disconnect(c.display);+ return status;+}diff --git a/apps/desktop/native/remote-desktop/linux-capture/test.mjs b/apps/desktop/native/remote-desktop/linux-capture/test.mjsnew file mode 100644index 0000000000..6a095fd44c--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/test.mjs@@ -0,0 +1,131 @@+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import test from 'node:test';++// Synthetic pixels only: no compositor connection, screenshot or input event.+test('native capture bounds buffers and scales padded rows without distortion', () => {+ const output = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-capture-test-'));+ const source = path.dirname(fileURLToPath(import.meta.url));+ function run(command, args) {+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 60000 });+ assert.equal(result.status, 0, result.stderr || String(result.error));+ return result.stdout.trim();+ }+ try {+ run(process.execPath, [path.join(source, 'build.mjs'), output]);+ // Including the implementation exercises actual pixel/bounds code while+ // leaving its normal main (and all Wayland calls) unexecuted.+ const testSource = path.join(output, 'test.c');+ fs.writeFileSync(+ testSource,+ `+#define main capture_entry+#include ${JSON.stringify(path.join(source, 'main.c'))}+#undef main+#include <assert.h>+int main(void) {+ uint32_t invalid[][4] = {+ {WL_SHM_FORMAT_XRGB8888,0,10,40},+ {WL_SHM_FORMAT_XRGB8888,100,100,399},+ {WL_SHM_FORMAT_XRGB8888,8193,1,32772},+ {WL_SHM_FORMAT_XRGB8888,8192,8192,32768},+ {WL_SHM_FORMAT_XRGB8888,100,100,UINT32_MAX},+ {WL_SHM_FORMAT_RGB565,100,100,400}+ };+ for (unsigned i=0;i<sizeof(invalid)/sizeof(invalid[0]);i++) {+ struct capture c={0};+ frame_buffer(&c,NULL,invalid[i][0],invalid[i][1],invalid[i][2],invalid[i][3]);+ assert(c.failed && !c.buffer && !c.pixels);+ }+ struct capture c={.width=2560,.height=1600,.stride=2560*4+32};+ c.pixels=calloc(c.height,c.stride); assert(c.pixels);+ for (uint32_t y=0;y<c.height;y++) for(uint32_t x=0;x<c.width;x++) {+ unsigned char *p=(unsigned char*)c.pixels+y*c.stride+x*4;+ p[0]=(unsigned char)(x*255/(c.width-1)); p[1]=(unsigned char)(y*255/(c.height-1)); p[2]=42;+ }+ int w,h,stride; const unsigned char *p=video_pixels(&c,&w,&h,&stride);+ assert(p && w==1920 && h==1200 && stride==7680);+ assert(p[0]==0 && p[1]==0 && p[2]==42);+ size_t last=(size_t)(h-1)*stride+(w-1)*4;+ assert(p[last]==255 && p[last+1]==255 && p[last+2]==42);+ assert(video_pixels(&c,&w,&h,&stride)==p);+ c.width=100;c.height=50;c.stride=432;+ assert(video_pixels(&c,&w,&h,&stride)==c.pixels && w==100 && h==50 && stride==432);+ free(c.pixels);free(c.scaled);+ // A non-square, padded raster detects swapped axes, wrong rotation order and+ // reading padding as pixels. Expectations are in displayed row-major order.+ const unsigned char expected[8][6] = {+ {1,2,3,4,5,6}, {4,1,5,2,6,3}, {6,5,4,3,2,1}, {3,6,2,5,1,4},+ {3,2,1,6,5,4}, {1,4,2,5,3,6}, {4,5,6,1,2,3}, {6,3,5,2,4,1}+ };+ for(int invert=0;invert<2;invert++) for(int transform=0;transform<8;transform++) {+ struct capture r={.width=3,.height=2,.stride=16,.transform=transform,+ .flags=invert ? ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT : 0};+ unsigned char raster[32]={0}; r.pixels=raster;+ for(int y=0;y<2;y++) for(int x=0;x<3;x++)+ raster[(invert ? 1-y : y)*16+x*4]=(unsigned char)(y*3+x+1);+ p=oriented_pixels(&r,&w,&h,&stride);+ assert(p && w==(transform%2 ? 2 : 3) && h==(transform%2 ? 3 : 2));+ for(int y=0;y<h;y++) for(int x=0;x<w;x++) {+ // The zero-copy path deliberately leaves normal Y_INVERT to TurboJPEG.+ int py=transform==0 && invert ? h-1-y : y;+ assert(p[py*stride+x*4]==expected[transform][y*w+x]);+ }+ assert(oriented_pixels(&r,&w,&h,&stride)==p);+ free(r.oriented);+ }+ // Hyprland's cursor position is logical even when video is physical pixels.+ cc.png="AA==";cc.visible=1;cc.allocated_width=32;cc.allocated_height=32;+ cc.scale=1;cc.x=1280;cc.y=800;cursor_json(2560,1600);puts("");+ cc.scale=1.6;cc.x=800;cc.y=500;cursor_json(2560,1600);puts("");+ cc.x=-20;cc.y=2000;cursor_json(2560,1600);puts("");+ return 0;+}+`,+ );+ const flags = run('pkg-config', [+ '--cflags',+ '--libs',+ 'wayland-client',+ 'libturbojpeg',+ 'libpng',+ ]).split(/\s+/);+ run('cc', [+ '-std=c11',+ '-Wall',+ '-Wextra',+ '-Werror',+ '-O2',+ '-fsanitize=address,undefined',+ testSource,+ ...[+ 'wlr-screencopy-unstable-v1',+ 'ext-image-copy-capture-v1',+ 'ext-image-capture-source-v1',+ 'ext-foreign-toplevel-list-v1',+ ].map((name) => path.join(output, name + '.c')),+ '-I',+ output,+ ...flags,+ '-o',+ path.join(output, 'test'),+ ]);+ const cursors = run(path.join(output, 'test'), [])+ .split('\n')+ .map((line) => JSON.parse(line));+ assert.deepEqual(+ cursors.map(({ x, y }) => [x, y]),+ [+ [0.5, 0.5],+ [0.5, 0.5],+ [0, 1],+ ],+ );+ } finally {+ fs.rmSync(output, { recursive: true, force: true });+ }+});diff --git a/apps/desktop/native/remote-desktop/linux-capture/wlr-screencopy-unstable-v1.xml b/apps/desktop/native/remote-desktop/linux-capture/wlr-screencopy-unstable-v1.xmlnew file mode 100644index 0000000000..50b1b7d2a5--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-capture/wlr-screencopy-unstable-v1.xml@@ -0,0 +1,232 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="wlr_screencopy_unstable_v1">+ <copyright>+ Copyright © 2018 Simon Ser+ Copyright © 2019 Andri Yngvason++ Permission is hereby granted, free of charge, to any person obtaining a+ copy of this software and associated documentation files (the "Software"),+ to deal in the Software without restriction, including without limitation+ the rights to use, copy, modify, merge, publish, distribute, sublicense,+ and/or sell copies of the Software, and to permit persons to whom the+ Software is furnished to do so, subject to the following conditions:++ The above copyright notice and this permission notice (including the next+ paragraph) shall be included in all copies or substantial portions of the+ Software.++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+ DEALINGS IN THE SOFTWARE.+ </copyright>++ <description summary="screen content capturing on client buffers">+ This protocol allows clients to ask the compositor to copy part of the+ screen content to a client buffer.++ Warning! The protocol described in this file is experimental and+ backward incompatible changes may be made. Backward compatible changes+ may be added together with the corresponding interface version bump.+ Backward incompatible changes are done by bumping the version number in+ the protocol and interface names and resetting the interface version.+ Once the protocol is to be declared stable, the 'z' prefix and the+ version number in the protocol and interface names are removed and the+ interface version number is reset.+ </description>++ <interface name="zwlr_screencopy_manager_v1" version="3">+ <description summary="manager to inform clients and begin capturing">+ This object is a manager which offers requests to start capturing from a+ source.+ </description>++ <request name="capture_output">+ <description summary="capture an output">+ Capture the next frame of an entire output.+ </description>+ <arg name="frame" type="new_id" interface="zwlr_screencopy_frame_v1"/>+ <arg name="overlay_cursor" type="int"+ summary="composite cursor onto the frame"/>+ <arg name="output" type="object" interface="wl_output"/>+ </request>++ <request name="capture_output_region">+ <description summary="capture an output's region">+ Capture the next frame of an output's region.++ The region is given in output logical coordinates, see+ xdg_output.logical_size. The region will be clipped to the output's+ extents.+ </description>+ <arg name="frame" type="new_id" interface="zwlr_screencopy_frame_v1"/>+ <arg name="overlay_cursor" type="int"+ summary="composite cursor onto the frame"/>+ <arg name="output" type="object" interface="wl_output"/>+ <arg name="x" type="int"/>+ <arg name="y" type="int"/>+ <arg name="width" type="int"/>+ <arg name="height" type="int"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="destroy the manager">+ All objects created by the manager will still remain valid, until their+ appropriate destroy request has been called.+ </description>+ </request>+ </interface>++ <interface name="zwlr_screencopy_frame_v1" version="3">+ <description summary="a frame ready for copy">+ This object represents a single frame.++ When created, a series of buffer events will be sent, each representing a+ supported buffer type. The "buffer_done" event is sent afterwards to+ indicate that all supported buffer types have been enumerated. The client+ will then be able to send a "copy" request. If the capture is successful,+ the compositor will send a "flags" followed by a "ready" event.++ For objects version 2 or lower, wl_shm buffers are always supported, ie.+ the "buffer" event is guaranteed to be sent.++ If the capture failed, the "failed" event is sent. This can happen anytime+ before the "ready" event.++ Once either a "ready" or a "failed" event is received, the client should+ destroy the frame.+ </description>++ <event name="buffer">+ <description summary="wl_shm buffer information">+ Provides information about wl_shm buffer parameters that need to be+ used for this frame. This event is sent once after the frame is created+ if wl_shm buffers are supported.+ </description>+ <arg name="format" type="uint" enum="wl_shm.format" summary="buffer format"/>+ <arg name="width" type="uint" summary="buffer width"/>+ <arg name="height" type="uint" summary="buffer height"/>+ <arg name="stride" type="uint" summary="buffer stride"/>+ </event>++ <request name="copy">+ <description summary="copy the frame">+ Copy the frame to the supplied buffer. The buffer must have a the+ correct size, see zwlr_screencopy_frame_v1.buffer and+ zwlr_screencopy_frame_v1.linux_dmabuf. The buffer needs to have a+ supported format.++ If the frame is successfully copied, a "flags" and a "ready" events are+ sent. Otherwise, a "failed" event is sent.+ </description>+ <arg name="buffer" type="object" interface="wl_buffer"/>+ </request>++ <enum name="error">+ <entry name="already_used" value="0"+ summary="the object has already been used to copy a wl_buffer"/>+ <entry name="invalid_buffer" value="1"+ summary="buffer attributes are invalid"/>+ </enum>++ <enum name="flags" bitfield="true">+ <entry name="y_invert" value="1" summary="contents are y-inverted"/>+ </enum>++ <event name="flags">+ <description summary="frame flags">+ Provides flags about the frame. This event is sent once before the+ "ready" event.+ </description>+ <arg name="flags" type="uint" enum="flags" summary="frame flags"/>+ </event>++ <event name="ready">+ <description summary="indicates frame is available for reading">+ Called as soon as the frame is copied, indicating it is available+ for reading. This event includes the time at which presentation happened+ at.++ The timestamp is expressed as tv_sec_hi, tv_sec_lo, tv_nsec triples,+ each component being an unsigned 32-bit value. Whole seconds are in+ tv_sec which is a 64-bit value combined from tv_sec_hi and tv_sec_lo,+ and the additional fractional part in tv_nsec as nanoseconds. Hence,+ for valid timestamps tv_nsec must be in [0, 999999999]. The seconds part+ may have an arbitrary offset at start.++ After receiving this event, the client should destroy the object.+ </description>+ <arg name="tv_sec_hi" type="uint"+ summary="high 32 bits of the seconds part of the timestamp"/>+ <arg name="tv_sec_lo" type="uint"+ summary="low 32 bits of the seconds part of the timestamp"/>+ <arg name="tv_nsec" type="uint"+ summary="nanoseconds part of the timestamp"/>+ </event>++ <event name="failed">+ <description summary="frame copy failed">+ This event indicates that the attempted frame copy has failed.++ After receiving this event, the client should destroy the object.+ </description>+ </event>++ <request name="destroy" type="destructor">+ <description summary="delete this object, used or not">+ Destroys the frame. This request can be sent at any time by the client.+ </description>+ </request>++ <!-- Version 2 additions -->+ <request name="copy_with_damage" since="2">+ <description summary="copy the frame when it's damaged">+ Same as copy, except it waits until there is damage to copy.+ </description>+ <arg name="buffer" type="object" interface="wl_buffer"/>+ </request>++ <event name="damage" since="2">+ <description summary="carries the coordinates of the damaged region">+ This event is sent right before the ready event when copy_with_damage is+ requested. It may be generated multiple times for each copy_with_damage+ request.++ The arguments describe a box around an area that has changed since the+ last copy request that was derived from the current screencopy manager+ instance.++ The union of all regions received between the call to copy_with_damage+ and a ready event is the total damage since the prior ready event.+ </description>+ <arg name="x" type="uint" summary="damaged x coordinates"/>+ <arg name="y" type="uint" summary="damaged y coordinates"/>+ <arg name="width" type="uint" summary="current width"/>+ <arg name="height" type="uint" summary="current height"/>+ </event>++ <!-- Version 3 additions -->+ <event name="linux_dmabuf" since="3">+ <description summary="linux-dmabuf buffer information">+ Provides information about linux-dmabuf buffer parameters that need to+ be used for this frame. This event is sent once after the frame is+ created if linux-dmabuf buffers are supported.+ </description>+ <arg name="format" type="uint" summary="fourcc pixel format"/>+ <arg name="width" type="uint" summary="buffer width"/>+ <arg name="height" type="uint" summary="buffer height"/>+ </event>++ <event name="buffer_done" since="3">+ <description summary="all buffer types reported">+ This event is sent once after all buffer events have been sent.++ The client should proceed to create a buffer of one of the supported+ types, and send a "copy" request.+ </description>+ </event>+ </interface>+</protocol>diff --git a/apps/desktop/native/remote-desktop/linux-clipboard/build.mjs b/apps/desktop/native/remote-desktop/linux-clipboard/build.mjsnew file mode 100644index 0000000000..3353bc5aa7--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-clipboard/build.mjs@@ -0,0 +1,41 @@+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+const source = path.dirname(fileURLToPath(import.meta.url));+const [output] = process.argv.slice(2);+if (!output || !path.isAbsolute(output)) throw new Error('Absolute output directory required');+fs.mkdirSync(output, { recursive: true });+function run(command, args) {+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 60000 });+ if (result.error || result.status !== 0)+ throw new Error(`Clipboard build failed: ${result.stderr || result.error}`);+ return result.stdout.trim();+}+const protocol = 'wlr-data-control-unstable-v1';+for (const [mode, extension] of [+ ['client-header', 'h'],+ ['private-code', 'c'],+])+ run('wayland-scanner', [+ mode,+ path.join(source, protocol + '.xml'),+ path.join(output, protocol + '.' + extension),+ ]);+const flags = run('pkg-config', ['--cflags', '--libs', 'wayland-client', 'json-c']).split(/\s+/);+const binary = path.join(output, 'cindy-linux-desktop-clipboard');+run('cc', [+ '-std=c11',+ '-Wall',+ '-Wextra',+ '-Werror',+ '-O2',+ path.join(source, 'main.c'),+ path.join(output, protocol + '.c'),+ '-I',+ output,+ ...flags,+ '-o',+ binary + '.tmp',+]);+fs.renameSync(binary + '.tmp', binary);diff --git a/apps/desktop/native/remote-desktop/linux-clipboard/main.c b/apps/desktop/native/remote-desktop/linux-clipboard/main.cnew file mode 100644index 0000000000..8a9ea4e979--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-clipboard/main.c@@ -0,0 +1,258 @@+#define _GNU_SOURCE+#include "wlr-data-control-unstable-v1.h"+#include <json-c/json.h>+#include <poll.h>+#include <signal.h>+#include <stdint.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <unistd.h>+#include <wayland-client.h>++/* One portable clipboard offer, supplied through stdin, never argv or a file.+ * No observation of clipboard contents. The compositor requests only offered+ * MIME types; replacement or parent EOF destroys the in-memory offer. */+struct item {+ const char *mime;+ unsigned char *bytes;+ size_t length;+};+static struct item items[4];+static struct wl_seat *seat;+static struct zwlr_data_control_manager_v1 *manager;+static int cancelled;+static void global(void *d, struct wl_registry *r, uint32_t n, const char *i,+ uint32_t v) {+ (void)d;+ (void)v;+ if (!strcmp(i, wl_seat_interface.name) && !seat)+ seat = wl_registry_bind(r, n, &wl_seat_interface, 1);+ if (!strcmp(i, zwlr_data_control_manager_v1_interface.name))+ manager =+ wl_registry_bind(r, n, &zwlr_data_control_manager_v1_interface, 1);+}+static void removed(void *d, struct wl_registry *r, uint32_t n) {+ (void)d;+ (void)r;+ (void)n;+}+static const struct wl_registry_listener registry_listener = {global, removed};+static void send_data(void *d, struct zwlr_data_control_source_v1 *s,+ const char *mime, int32_t fd) {+ (void)d;+ (void)s;+ alarm(3);+ for (unsigned i = 0; i < 4; i++)+ if (items[i].mime && !strcmp(mime, items[i].mime)) {+ size_t sent = 0;+ while (sent < items[i].length) {+ ssize_t n = write(fd, items[i].bytes + sent, items[i].length - sent);+ if (n <= 0)+ break;+ sent += (size_t)n;+ }+ break;+ }+ close(fd);+ alarm(0);+}+static void replaced(void *d, struct zwlr_data_control_source_v1 *s) {+ (void)d;+ (void)s;+ cancelled = 1;+}+static const struct zwlr_data_control_source_v1_listener source_listener = {+ send_data, replaced};+static void offer(void *d, struct zwlr_data_control_device_v1 *s,+ struct zwlr_data_control_offer_v1 *o) {+ (void)d;+ (void)s;+ zwlr_data_control_offer_v1_destroy(o);+}+static void selection(void *d, struct zwlr_data_control_device_v1 *s,+ struct zwlr_data_control_offer_v1 *o) {+ (void)d;+ (void)s;+ (void)o;+}+static void finished(void *d, struct zwlr_data_control_device_v1 *s) {+ (void)d;+ (void)s;+ cancelled = 1;+}+static const struct zwlr_data_control_device_v1_listener device_listener = {+ .data_offer = offer,+ .selection = selection,+ .finished = finished,+ .primary_selection = selection};+static int decode(const char *text, size_t size, unsigned char **out,+ size_t *length) {+ static const char alphabet[] =+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";+ if (size % 4 || size > 11184812)+ return -1;+ unsigned char *bytes = malloc(size / 4 * 3 + 1);+ if (!bytes)+ return -1;+ size_t n = 0;+ for (size_t i = 0; i < size; i += 4) {+ uint32_t value = 0;+ unsigned padding = 0;+ for (unsigned j = 0; j < 4; j++) {+ const char *p = strchr(alphabet, text[i + j]);+ if (text[i + j] == '=' && i + 4 == size && j >= 2) {+ padding++;+ value <<= 6;+ } else if (p && text[i + j] && !padding)+ value = (value << 6) | (uint32_t)(p - alphabet);+ else {+ free(bytes);+ return -1;+ }+ }+ bytes[n++] = (unsigned char)(value >> 16);+ if (padding < 2)+ bytes[n++] = (unsigned char)(value >> 8);+ if (!padding)+ bytes[n++] = (unsigned char)value;+ }+ *out = bytes;+ *length = n;+ return n <= 8388608 ? 0 : -1;+}+static int payload(const char *line) {+ struct json_tokener *tok = json_tokener_new_ex(8);+ if (!tok)+ return -1;+ json_object *root = json_tokener_parse_ex(tok, line, (int)strlen(line));+ int valid = json_tokener_get_error(tok) == json_tokener_success && root &&+ json_object_is_type(root, json_type_object);+ json_tokener_free(tok);+ if (!valid) {+ if (root)+ json_object_put(root);+ return -1;+ }+ const char *keys[] = {"text", "html", "rtf", "png"};+ const char *mimes[] = {"text/plain;charset=utf-8", "text/html", "text/rtf",+ "image/png"};+ unsigned found = 0;+ for (unsigned i = 0; i < 4; i++) {+ json_object *value = NULL;+ if (!json_object_object_get_ex(root, keys[i], &value))+ continue;+ if (!json_object_is_type(value, json_type_string)) {+ valid = 0;+ break;+ }+ size_t length = (size_t)json_object_get_string_len(value);+ const char *bytes = json_object_get_string(value);+ if (i == 3) {+ if (decode(bytes, length, &items[i].bytes, &items[i].length)) {+ valid = 0;+ break;+ }+ } else {+ if (length > 2097152) {+ valid = 0;+ break;+ }+ items[i].bytes = malloc(length + 1);+ if (!items[i].bytes) {+ valid = 0;+ break;+ }+ memcpy(items[i].bytes, bytes, length);+ items[i].length = length;+ }+ items[i].mime = mimes[i];+ found++;+ }+ json_object_put(root);+ return valid && found ? 0 : -1;+}+int main(int argc, char **argv) {+ signal(SIGPIPE, SIG_IGN);+ alarm(5);+ char *line = malloc(16000002);+ if (!line)+ return 1;+ int status = 1;+ struct wl_display *display = NULL;+ struct wl_registry *registry = NULL;+ struct zwlr_data_control_device_v1 *device = NULL;+ struct zwlr_data_control_source_v1 *source = NULL;+ if (!fgets(line, 16000002, stdin) || !strchr(line, '\n') || payload(line))+ goto done;+ if (argc == 2 && !strcmp(argv[1], "--check")) {+ status = 0;+ goto done;+ }+ if (argc != 1)+ goto done;+ display = wl_display_connect(NULL);+ if (!display)+ goto done;+ registry = wl_display_get_registry(display);+ wl_registry_add_listener(registry, ®istry_listener, NULL);+ if (wl_display_roundtrip(display) < 0 || !seat || !manager)+ goto done;+ device = zwlr_data_control_manager_v1_get_data_device(manager, seat);+ zwlr_data_control_device_v1_add_listener(device, &device_listener, NULL);+ source = zwlr_data_control_manager_v1_create_data_source(manager);+ zwlr_data_control_source_v1_add_listener(source, &source_listener, NULL);+ for (unsigned i = 0; i < 4; i++)+ if (items[i].mime)+ zwlr_data_control_source_v1_offer(source, items[i].mime);+ zwlr_data_control_device_v1_set_selection(device, source);+ if (wl_display_roundtrip(display) < 0)+ goto done;+ puts("ready");+ fflush(stdout);+ alarm(0);+ while (!cancelled) {+ while (wl_display_prepare_read(display) != 0)+ if (wl_display_dispatch_pending(display) < 0)+ goto done;+ if (wl_display_flush(display) < 0) {+ wl_display_cancel_read(display);+ goto done;+ }+ struct pollfd fds[] = {{wl_display_get_fd(display), POLLIN, 0},+ {STDIN_FILENO, POLLIN, 0}};+ int n = poll(fds, 2, -1);+ if (n < 0 || fds[1].revents) {+ wl_display_cancel_read(display);+ break;+ }+ if (fds[0].revents & POLLIN) {+ if (wl_display_read_events(display) < 0)+ goto done;+ } else {+ wl_display_cancel_read(display);+ if (fds[0].revents)+ break;+ }+ if (wl_display_dispatch_pending(display) < 0)+ goto done;+ }+ status = 0;+done:+ if (source)+ zwlr_data_control_source_v1_destroy(source);+ if (device)+ zwlr_data_control_device_v1_destroy(device);+ if (manager)+ zwlr_data_control_manager_v1_destroy(manager);+ if (seat)+ wl_seat_destroy(seat);+ if (registry)+ wl_registry_destroy(registry);+ if (display)+ wl_display_disconnect(display);+ for (unsigned i = 0; i < 4; i++)+ free(items[i].bytes);+ free(line);+ return status;+}diff --git a/apps/desktop/native/remote-desktop/linux-clipboard/test.mjs b/apps/desktop/native/remote-desktop/linux-clipboard/test.mjsnew file mode 100644index 0000000000..d382fd1723--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-clipboard/test.mjs@@ -0,0 +1,62 @@+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import os from 'node:os';+import assert from 'node:assert/strict';+import { fileURLToPath } from 'node:url';+import test from 'node:test';+test('clipboard parser bounds formats and binary data without a compositor', () => {+ const source = path.dirname(fileURLToPath(import.meta.url));+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-clipboard-test-'));+ const run = (cmd, args) => {+ const result = spawnSync(cmd, args, { encoding: 'utf8', timeout: 60000 });+ assert.equal(result.status, 0, result.stderr || String(result.error));+ return result.stdout.trim();+ };+ try {+ run(process.execPath, [path.join(source, 'build.mjs'), dir]);+ const target = path.join(dir, 'test.c');+ fs.writeFileSync(+ target,+ `+#define main clipboard_main+#include ${JSON.stringify(path.join(source, 'main.c'))}+#undef main+#include <assert.h>+int main(void) {+ unsigned char *bytes=NULL;size_t length=0;+ assert(!decode("YQ==",4,&bytes,&length) && length==1 && bytes[0]=='a');free(bytes);+ assert(decode("Y!==",4,&bytes,&length)==-1);+ assert(decode("A",1,&bytes,&length)==-1);+ assert(decode("====",4,&bytes,&length)==-1);+ assert(payload("{\\\"text\\\":3}")==-1);+ assert(payload("{}")==-1);+ assert(!payload("{\\\"text\\\":\\\"test\\\",\\\"html\\\":\\\"<b>test</b>\\\",\\\"png\\\":\\\"YQ==\\\"}"));+ assert(items[0].length==4 && items[1].length==11 && items[3].length==1);+ for(unsigned i=0;i<4;i++) free(items[i].bytes);+ return 0;+}+`,+ );+ const flags = run('pkg-config', ['--cflags', '--libs', 'wayland-client', 'json-c']).split(+ /\s+/,+ );+ run('cc', [+ '-std=c11',+ '-Wall',+ '-Wextra',+ '-Werror',+ '-fsanitize=address,undefined',+ target,+ path.join(dir, 'wlr-data-control-unstable-v1.c'),+ '-I',+ dir,+ ...flags,+ '-o',+ path.join(dir, 'test'),+ ]);+ run(path.join(dir, 'test'), []);+ } finally {+ fs.rmSync(dir, { recursive: true, force: true });+ }+});diff --git a/apps/desktop/native/remote-desktop/linux-clipboard/wlr-data-control-unstable-v1.xml b/apps/desktop/native/remote-desktop/linux-clipboard/wlr-data-control-unstable-v1.xmlnew file mode 100644index 0000000000..75e8671b0d--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-clipboard/wlr-data-control-unstable-v1.xml@@ -0,0 +1,278 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="wlr_data_control_unstable_v1">+ <copyright>+ Copyright © 2018 Simon Ser+ Copyright © 2019 Ivan Molodetskikh++ Permission to use, copy, modify, distribute, and sell this+ software and its documentation for any purpose is hereby granted+ without fee, provided that the above copyright notice appear in+ all copies and that both that copyright notice and this permission+ notice appear in supporting documentation, and that the name of+ the copyright holders not be used in advertising or publicity+ pertaining to distribution of the software without specific,+ written prior permission. The copyright holders make no+ representations about the suitability of this software for any+ purpose. It is provided "as is" without express or implied+ warranty.++ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF+ THIS SOFTWARE.+ </copyright>++ <description summary="control data devices">+ This protocol allows a privileged client to control data devices. In+ particular, the client will be able to manage the current selection and take+ the role of a clipboard manager.++ Warning! The protocol described in this file is experimental and+ backward incompatible changes may be made. Backward compatible changes+ may be added together with the corresponding interface version bump.+ Backward incompatible changes are done by bumping the version number in+ the protocol and interface names and resetting the interface version.+ Once the protocol is to be declared stable, the 'z' prefix and the+ version number in the protocol and interface names are removed and the+ interface version number is reset.+ </description>++ <interface name="zwlr_data_control_manager_v1" version="2">+ <description summary="manager to control data devices">+ This interface is a manager that allows creating per-seat data device+ controls.+ </description>++ <request name="create_data_source">+ <description summary="create a new data source">+ Create a new data source.+ </description>+ <arg name="id" type="new_id" interface="zwlr_data_control_source_v1"+ summary="data source to create"/>+ </request>++ <request name="get_data_device">+ <description summary="get a data device for a seat">+ Create a data device that can be used to manage a seat's selection.+ </description>+ <arg name="id" type="new_id" interface="zwlr_data_control_device_v1"/>+ <arg name="seat" type="object" interface="wl_seat"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="destroy the manager">+ All objects created by the manager will still remain valid, until their+ appropriate destroy request has been called.+ </description>+ </request>+ </interface>++ <interface name="zwlr_data_control_device_v1" version="2">+ <description summary="manage a data device for a seat">+ This interface allows a client to manage a seat's selection.++ When the seat is destroyed, this object becomes inert.+ </description>++ <request name="set_selection">+ <description summary="copy data to the selection">+ This request asks the compositor to set the selection to the data from+ the source on behalf of the client.++ The given source may not be used in any further set_selection or+ set_primary_selection requests. Attempting to use a previously used+ source is a protocol error.++ To unset the selection, set the source to NULL.+ </description>+ <arg name="source" type="object" interface="zwlr_data_control_source_v1"+ allow-null="true"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="destroy this data device">+ Destroys the data device object.+ </description>+ </request>++ <event name="data_offer">+ <description summary="introduce a new wlr_data_control_offer">+ The data_offer event introduces a new wlr_data_control_offer object,+ which will subsequently be used in either the+ wlr_data_control_device.selection event (for the regular clipboard+ selections) or the wlr_data_control_device.primary_selection event (for+ the primary clipboard selections). Immediately following the+ wlr_data_control_device.data_offer event, the new data_offer object+ will send out wlr_data_control_offer.offer events to describe the MIME+ types it offers.+ </description>+ <arg name="id" type="new_id" interface="zwlr_data_control_offer_v1"/>+ </event>++ <event name="selection">+ <description summary="advertise new selection">+ The selection event is sent out to notify the client of a new+ wlr_data_control_offer for the selection for this device. The+ wlr_data_control_device.data_offer and the wlr_data_control_offer.offer+ events are sent out immediately before this event to introduce the data+ offer object. The selection event is sent to a client when a new+ selection is set. The wlr_data_control_offer is valid until a new+ wlr_data_control_offer or NULL is received. The client must destroy the+ previous selection wlr_data_control_offer, if any, upon receiving this+ event.++ The first selection event is sent upon binding the+ wlr_data_control_device object.+ </description>+ <arg name="id" type="object" interface="zwlr_data_control_offer_v1"+ allow-null="true"/>+ </event>++ <event name="finished">+ <description summary="this data control is no longer valid">+ This data control object is no longer valid and should be destroyed by+ the client.+ </description>+ </event>++ <!-- Version 2 additions -->++ <event name="primary_selection" since="2">+ <description summary="advertise new primary selection">+ The primary_selection event is sent out to notify the client of a new+ wlr_data_control_offer for the primary selection for this device. The+ wlr_data_control_device.data_offer and the wlr_data_control_offer.offer+ events are sent out immediately before this event to introduce the data+ offer object. The primary_selection event is sent to a client when a+ new primary selection is set. The wlr_data_control_offer is valid until+ a new wlr_data_control_offer or NULL is received. The client must+ destroy the previous primary selection wlr_data_control_offer, if any,+ upon receiving this event.++ If the compositor supports primary selection, the first+ primary_selection event is sent upon binding the+ wlr_data_control_device object.+ </description>+ <arg name="id" type="object" interface="zwlr_data_control_offer_v1"+ allow-null="true"/>+ </event>++ <request name="set_primary_selection" since="2">+ <description summary="copy data to the primary selection">+ This request asks the compositor to set the primary selection to the+ data from the source on behalf of the client.++ The given source may not be used in any further set_selection or+ set_primary_selection requests. Attempting to use a previously used+ source is a protocol error.++ To unset the primary selection, set the source to NULL.++ The compositor will ignore this request if it does not support primary+ selection.+ </description>+ <arg name="source" type="object" interface="zwlr_data_control_source_v1"+ allow-null="true"/>+ </request>++ <enum name="error" since="2">+ <entry name="used_source" value="1"+ summary="source given to set_selection or set_primary_selection was already used before"/>+ </enum>+ </interface>++ <interface name="zwlr_data_control_source_v1" version="1">+ <description summary="offer to transfer data">+ The wlr_data_control_source object is the source side of a+ wlr_data_control_offer. It is created by the source client in a data+ transfer and provides a way to describe the offered data and a way to+ respond to requests to transfer the data.+ </description>++ <enum name="error">+ <entry name="invalid_offer" value="1"+ summary="offer sent after wlr_data_control_device.set_selection"/>+ </enum>++ <request name="offer">+ <description summary="add an offered MIME type">+ This request adds a MIME type to the set of MIME types advertised to+ targets. Can be called several times to offer multiple types.++ Calling this after wlr_data_control_device.set_selection is a protocol+ error.+ </description>+ <arg name="mime_type" type="string"+ summary="MIME type offered by the data source"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="destroy this source">+ Destroys the data source object.+ </description>+ </request>++ <event name="send">+ <description summary="send the data">+ Request for data from the client. Send the data as the specified MIME+ type over the passed file descriptor, then close it.+ </description>+ <arg name="mime_type" type="string" summary="MIME type for the data"/>+ <arg name="fd" type="fd" summary="file descriptor for the data"/>+ </event>++ <event name="cancelled">+ <description summary="selection was cancelled">+ This data source is no longer valid. The data source has been replaced+ by another data source.++ The client should clean up and destroy this data source.+ </description>+ </event>+ </interface>++ <interface name="zwlr_data_control_offer_v1" version="1">+ <description summary="offer to transfer data">+ A wlr_data_control_offer represents a piece of data offered for transfer+ by another client (the source client). The offer describes the different+ MIME types that the data can be converted to and provides the mechanism+ for transferring the data directly from the source client.+ </description>++ <request name="receive">+ <description summary="request that the data is transferred">+ To transfer the offered data, the client issues this request and+ indicates the MIME type it wants to receive. The transfer happens+ through the passed file descriptor (typically created with the pipe+ system call). The source client writes the data in the MIME type+ representation requested and then closes the file descriptor.++ The receiving client reads from the read end of the pipe until EOF and+ then closes its end, at which point the transfer is complete.++ This request may happen multiple times for different MIME types.+ </description>+ <arg name="mime_type" type="string"+ summary="MIME type desired by receiver"/>+ <arg name="fd" type="fd" summary="file descriptor for data transfer"/>+ </request>++ <request name="destroy" type="destructor">+ <description summary="destroy this offer">+ Destroys the data offer object.+ </description>+ </request>++ <event name="offer">+ <description summary="advertise offered MIME type">+ Sent immediately after creating the wlr_data_control_offer object.+ One event per offered MIME type.+ </description>+ <arg name="mime_type" type="string" summary="offered MIME type"/>+ </event>+ </interface>+</protocol>diff --git a/apps/desktop/native/remote-desktop/linux-credentials/channel.py b/apps/desktop/native/remote-desktop/linux-credentials/channel.pynew file mode 100644index 0000000000..f3f7abd335--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/channel.py@@ -0,0 +1,197 @@+"""Existing Cindy v1 credential wire protocol; secrets stay in this helper.++JOSE primitives come from JWCrypto, not an application cryptography implementation.+See packages/remote-credentials-native/{NativeChannel,SealedMessage}.swift.+"""+import base64+import hashlib+import json+import time+import uuid++from jwcrypto import jwk, jwe, jws++MAX_PACKET = 8 * 1024 * 1024+TYPE = "cindy-remote-desktop-v1"+OFFER_TYPE = "cindy-remote-desktop-offer-v1"+PURPOSES = {"ready", "authenticate", "authentication-result", "authentication-status",+ "request", "response", "revoke"}+++class Error(Exception):+ def __init__(self, code="INVALID_MESSAGE"):+ super().__init__("CREDENTIAL_" + code)+++def require(condition, code="INVALID_MESSAGE"):+ if not condition:+ raise Error(code)+++def encode(value):+ return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode()+++def decode(value):+ def unique(pairs):+ result = {}+ for key, item in pairs:+ require(key not in result)+ result[key] = item+ return result+ return json.loads(value, object_pairs_hook=unique)+++def b64(data):+ return base64.urlsafe_b64encode(data).decode().rstrip("=")+++def unb64(value):+ require(isinstance(value, str) and 0 < len(value) <= MAX_PACKET)+ data = base64.b64decode(value + "=" * (-len(value) % 4), altchars=b"-_", validate=True)+ require(b64(data) == value)+ return data+++def identity(value):+ return isinstance(value, str) and 0 < len(value.encode()) <= 512+++def public(key):+ return decode(key.export_public())+++def public_key(value, ephemeral=False):+ require(isinstance(value, dict))+ allowed = {"kty", "crv", "x", "y"} | ({"kid"} if ephemeral else set())+ require(set(value) <= allowed and value.get("kty") == "EC" and value.get("crv") == "P-256")+ require(len(unb64(value.get("x"))) == 32 and len(unb64(value.get("y"))) == 32)+ if "kid" in value:+ uuid.UUID(value["kid"])+ result = jwk.JWK(**{k: value[k] for k in ("kty", "crv", "x", "y")})+ result.get_op_key("verify") # validate that the coordinates are on the curve+ return result+++def header(packet, count):+ require(isinstance(packet, str) and len(packet) <= MAX_PACKET and len(packet.split(".")) == count)+ first = packet.split(".", 1)[0]+ require(len(first) <= 4096)+ value = decode(unb64(first))+ require(isinstance(value, dict))+ return value+++def sign(body, key, offer=False):+ fields = {"alg": "ES256", "typ": OFFER_TYPE if offer else TYPE}+ if not offer:+ fields["cty"] = "JWE"+ signed = jws.JWS(body)+ signed.add_signature(key, protected=encode(fields).decode())+ return signed.serialize(compact=True)+++def verify(packet, key, offer=False):+ expected = {"alg": "ES256", "typ": OFFER_TYPE if offer else TYPE}+ if not offer:+ expected["cty"] = "JWE"+ require(header(packet, 3) == expected)+ signed = jws.JWS()+ signed.allowed_algs = ["ES256"]+ signed.deserialize(packet)+ signed.verify(key, alg="ES256")+ return signed.payload+++def seal(body, sender, recipient):+ require(len(body) <= MAX_PACKET // 2)+ encrypted = jwe.JWE(body, protected=encode({"alg": "ECDH-ES", "enc": "A256GCM", "typ": TYPE}).decode(),+ algs=["ECDH-ES", "A256GCM"], recipient=recipient)+ return sign(encrypted.serialize(compact=True).encode(), sender)+++def open_sealed(packet, sender, recipient):+ compact = verify(packet, sender).decode("ascii")+ fields = header(compact, 5)+ require(set(fields) == {"alg", "enc", "typ", "epk"})+ require(fields["alg"] == "ECDH-ES" and fields["enc"] == "A256GCM" and fields["typ"] == TYPE)+ public_key(fields["epk"], ephemeral=True)+ require(compact.split(".")[1] == "")+ encrypted = jwe.JWE(algs=["ECDH-ES", "A256GCM"])+ encrypted.deserialize(compact, key=recipient)+ require(len(encrypted.payload) <= MAX_PACKET // 2)+ return encrypted.payload+++class Channel:+ def __init__(self, local, remote, key):+ require(local["realm"] in ("global", "cn") and local["realm"] == remote["realm"], "INVALID_IDENTITY")+ require(local["membership"] == remote["membership"] and identity(local["membership"]), "INVALID_IDENTITY")+ require(identity(local["device"]) and identity(remote["device"]) and local["device"] != remote["device"], "INVALID_IDENTITY")+ require(public(key) == local["publicKey"], "INVALID_IDENTITY")+ self.local, self.remote, self.key = local, remote, key+ self.remote_key = public_key(remote["publicKey"])+ self.ephemeral = jwk.JWK.generate(kty="EC", crv="P-256")+ self.deadline, self.wall_deadline = time.monotonic() + 1800, time.time() + 1800+ self.local_offer = {"domain": "cindy.remote-desktop.offer.v1", "realm": local["realm"],+ "membership": local["membership"], "from": local["device"], "to": remote["device"],+ "nonce": str(uuid.uuid4()), "ephemeral": public(self.ephemeral),+ "expiresAt": int((time.time() + 60) * 1000)}+ self.remote_offer = None+ self.session = None+ self.confirmed = False+ self.outgoing = self.high = 0+ self.received = set()++ def active(self):+ require(self.key is not None and time.monotonic() < self.deadline and time.time() < self.wall_deadline, "EXPIRED")++ def offer(self):+ self.active()+ return sign(encode(self.local_offer), self.key, offer=True)++ def accept(self, packet):+ self.active()+ require(self.remote_offer is None and len(packet) <= 4096)+ value = decode(verify(packet, self.remote_key, offer=True))+ require(set(value) == set(self.local_offer))+ for field in ("domain", "realm", "membership"):+ require(value[field] == self.local_offer[field], "INVALID_IDENTITY")+ require(value["from"] == self.remote["device"] and value["to"] == self.local["device"], "INVALID_IDENTITY")+ now = time.time() * 1000+ require(type(value["expiresAt"]) is int and now < value["expiresAt"] <= now + 120000+ and self.local_offer["expiresAt"] > now and identity(value["nonce"]), "INVALID_IDENTITY")+ public_key(value["ephemeral"])+ self.session = b64(hashlib.sha256(encode(sorted([self.local_offer, value], key=lambda o: o["from"]))).digest())+ self.remote_offer = value++ def send(self, purpose, body):+ self.active()+ require(self.session is not None and purpose in PURPOSES and (purpose == "ready" or self.confirmed))+ self.outgoing += 1+ require(self.outgoing < 2 ** 64)+ return seal(encode({"domain": "cindy.remote-desktop.packet.v1", "session": self.session,+ "from": self.local["device"], "to": self.remote["device"], "sequence": self.outgoing,+ "purpose": purpose, "body": base64.b64encode(encode(body)).decode()}),+ self.key, public_key(self.remote_offer["ephemeral"]))++ def receive(self, packet):+ self.active()+ require(self.session is not None)+ value = decode(open_sealed(packet, self.remote_key, self.ephemeral))+ require(value["domain"] == "cindy.remote-desktop.packet.v1" and value["session"] == self.session+ and value["from"] == self.remote["device"] and value["to"] == self.local["device"])+ sequence, purpose = value["sequence"], value["purpose"]+ require(type(sequence) is int and 0 < sequence < 2 ** 64 and sequence not in self.received+ and sequence > self.high - 256 and purpose in PURPOSES and (purpose == "ready" or self.confirmed))+ self.high = max(self.high, sequence)+ self.received = {x for x in self.received if self.high - x < 256} | {sequence}+ if purpose == "ready":+ self.confirmed = True+ body = base64.b64decode(value["body"], validate=True)+ return purpose, body++ def close(self):+ self.key = self.ephemeral = self.session = self.remote_offer = None+ self.confirmed = False+ self.received.clear()diff --git a/apps/desktop/native/remote-desktop/linux-credentials/host.py b/apps/desktop/native/remote-desktop/linux-credentials/host.pynew file mode 100644index 0000000000..640154636d--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/host.py@@ -0,0 +1,186 @@+import asyncio+import base64+import hashlib+import time+import uuid++from channel import Channel, Error, decode, encode, identity, public, require+++class Host:+ def __init__(self, directory, load_key, read_account, read_state, unlock):+ self.directory, self.load_key = directory, load_key+ self.read_account, self.read_state, self.unlock = read_account, read_state, unlock+ self.owner = self.key = None+ self.sessions, self.active, self.candidates = {}, {}, {}+ self.attempts = []+ self.verifying = False++ def close_handle(self, handle):+ state = self.sessions.pop(handle, None)+ if not state:+ return+ state["channel"].close()+ job = state.get("job")+ if job and job is not asyncio.current_task():+ job.cancel()+ for mapping in (self.active, self.candidates):+ if mapping.get(state["peer"]) == handle:+ del mapping[state["peer"]]++ def close_all(self):+ for handle in list(self.sessions):+ self.close_handle(handle)++ def current(self, handle, peer):+ state = self.sessions.get(handle)+ require(state is not None and state["peer"] == peer, "CANCELLED")+ state["channel"].active()+ require(self.read_account() == state["account"], "INVALID_IDENTITY")+ require(state["authorization"] is not None or time.monotonic() < state["until"], "EXPIRED")+ return state++ async def status(self):+ result = {}+ state = await self.read_state()+ for handle, item in list(self.sessions.items()):+ try:+ self.current(handle, item["peer"])+ if item["authorization"]:+ require(state == "unlocked", "UNLOCK_UNAVAILABLE")+ if self.active.get(item["peer"]) == handle:+ result[item["peer"]] = item["authorization"]+ except Error:+ self.close_handle(handle)+ return result++ async def call(self, value):+ method = value["method"]+ if method == "configure":+ owner = tuple(value[x] for x in ("realm", "membership", "authDevice"))+ require(owner[0] in ("global", "cn") and identity(owner[1]) and identity(owner[2]), "INVALID_IDENTITY")+ require(await self.read_state() in ("locked", "unlocked"), "UNLOCK_UNAVAILABLE")+ if owner != self.owner:+ self.close_all()+ self.owner = self.key = None+ # No password operation here; Secret Service must already be available.+ key = self.load_key(self.directory, owner[0])+ self.owner, self.key = owner, key+ return encode(self.descriptor()).decode()+ if method == "updateToken":+ require(self.owner is not None and (value["realm"], value["membership"]) == self.owner[:2], "CANCELLED")+ return True+ if method == "status":+ return await self.status()+ if method in ("closeAll", "reset"):+ self.close_all()+ if method == "reset":+ self.owner = self.key = None+ return True+ if method == "close":+ peer = value["peer"]+ for handle in (self.active.get(peer), self.candidates.get(peer)):+ self.close_handle(handle)+ return True+ require(self.owner is not None, "INVALID_IDENTITY")+ if method == "begin":+ await self.status()+ peer = value["peer"]+ require(identity(peer) and len(value["descriptor"]) <= 4096, "INVALID_IDENTITY")+ descriptor = decode(value["descriptor"])+ require(descriptor["version"] == 1 and descriptor["device"] == peer+ and descriptor["realm"] == self.owner[0] and descriptor["membership"] == self.owner[1], "INVALID_IDENTITY")+ old = self.sessions.get(self.candidates.get(peer))+ if old and old["offer"] == value["offer"]:+ return {"handle": self.candidates[peer], "offer": old["channel"].offer()}+ require(len({s["peer"] for s in self.sessions.values()}) < 8 or peer in self.candidates or peer in self.active, "UNAVAILABLE")+ require(await self.read_state() in ("locked", "unlocked"), "UNLOCK_UNAVAILABLE")+ channel = Channel(self.descriptor(), descriptor, self.key)+ channel.accept(value["offer"])+ self.close_handle(self.candidates.get(peer))+ handle = str(uuid.uuid4())+ self.sessions[handle] = {"peer": peer, "offer": value["offer"], "channel": channel,+ "account": self.read_account(), "until": time.monotonic() + 120,+ "authorization": None, "completed": {}, "pending": set()}+ self.candidates[peer] = handle+ return {"handle": handle, "offer": channel.offer()}+ state = self.current(value["handle"], value["peer"])+ channel = state["channel"]+ if method == "response":+ require(state["authorization"] and value["requestId"] in state["pending"], "INVALID_IDENTITY")+ require(await self.read_state() == "unlocked", "UNLOCK_UNAVAILABLE")+ self.current(value["handle"], value["peer"])+ state["pending"].remove(value["requestId"])+ return channel.send("response", {"id": value["requestId"], "payload": base64.b64encode(value["body"].encode()).decode(),+ "success": value["success"] is True})+ require(method == "receive")+ purpose, body = channel.receive(value["ciphertext"])+ if purpose == "revoke":+ self.close_handle(value["handle"])+ return {"kind": "closed"}+ if purpose == "ready":+ return {"kind": "reply", "ciphertext": channel.send("ready", state["account"])}+ if purpose == "authenticate":+ require(len(body) <= 8192)+ attempt = decode(body)+ require(str(uuid.UUID(attempt["id"])) == attempt["id"] and attempt["account"] == state["account"])+ password = base64.b64decode(attempt["password"], validate=True)+ require(0 < len(password) <= 4096 and b"\0" not in password)+ password.decode("utf-8")+ digest = hashlib.sha256(body).digest()+ completed = state["completed"].get(attempt["id"])+ if completed:+ require(completed[0] == digest)+ return {"kind": "reply", "ciphertext": channel.send("authentication-result", completed[1])}+ require(not self.verifying and not state["authorization"] and len(state["completed"]) < 5, "UNAVAILABLE")+ now = time.monotonic()+ self.attempts = [x for x in self.attempts if now - x < 60]+ require(len(self.attempts) < 5, "UNAVAILABLE")+ self.attempts.append(now)+ def current():+ self.current(value["handle"], value["peer"])+ require(self.candidates.get(value["peer"]) == value["handle"], "CANCELLED")+ current()+ result = {"id": attempt["id"], "account": state["account"], "accepted": False}+ self.verifying = True+ state["job"] = asyncio.current_task()+ try:+ await self.unlock(password, current)+ current()+ require(await self.read_state() == "unlocked", "UNLOCK_UNAVAILABLE")+ current()+ result["accepted"] = True+ except Error as error:+ if str(error) != "CREDENTIAL_INVALID_IDENTITY":+ result["failure"] = str(error)+ except Exception:+ result["failure"] = "CREDENTIAL_UNAVAILABLE"+ finally:+ password = body = attempt = None+ self.verifying = False+ state.pop("job", None)+ current()+ state["completed"][result["id"]] = digest, result+ if result["accepted"]:+ self.close_handle(self.active.get(value["peer"]))+ state["authorization"] = str(uuid.uuid4())+ self.active[value["peer"]] = value["handle"]+ del self.candidates[value["peer"]]+ return {"kind": "reply", "ciphertext": channel.send("authentication-result", result)}+ if purpose == "authentication-status":+ require(len(body) <= 256)+ completed = state["completed"].get(decode(body)["id"])+ require(completed is not None)+ return {"kind": "reply", "ciphertext": channel.send("authentication-result", completed[1])}+ require(purpose == "request" and state["authorization"], "INVALID_IDENTITY")+ require(await self.read_state() == "unlocked", "UNLOCK_UNAVAILABLE")+ self.current(value["handle"], value["peer"])+ request = decode(body)+ require(identity(request["id"]) and request["id"] not in state["pending"] and len(state["pending"]) < 64)+ payload = base64.b64decode(request["payload"], validate=True).decode("utf-8")+ state["pending"].add(request["id"])+ return {"kind": "command", "id": request["id"], "body": payload, "authenticationSession": state["authorization"]}++ def descriptor(self):+ return {"version": 1, "realm": self.owner[0], "membership": self.owner[1],+ "device": self.owner[2], "publicKey": public(self.key)}diff --git a/apps/desktop/native/remote-desktop/linux-credentials/main.py b/apps/desktop/native/remote-desktop/linux-credentials/main.pynew file mode 100644index 0000000000..8788b2cf6b--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/main.py@@ -0,0 +1,100 @@+#!/usr/bin/python3+"""Private stdio endpoint. Main sees descriptors, ciphertext and fixed errors only."""+import asyncio+import ctypes+import os+from pathlib import Path+import resource+import signal+import stat+import sys++# -I disables cwd, PYTHONPATH and user-site imports. Only these packaged sibling+# modules are added; the profile directory is never a Python import location.+sys.path.insert(0, str(Path(__file__).resolve().parent))+++def harden():+ resource.setrlimit(resource.RLIMIT_CORE, (0, 0))+ libc = ctypes.CDLL(None)+ if libc.prctl(4, 0, 0, 0, 0) != 0: # PR_SET_DUMPABLE+ raise RuntimeError()+ if libc.prctl(1, signal.SIGTERM, 0, 0, 0) != 0: # PR_SET_PDEATHSIG+ raise RuntimeError()+++async def serve(directory, parent, executable):+ from channel import Error, MAX_PACKET, decode, encode, require+ from host import Host+ from platform_linux import account, lock_state, verify_and_unlock+ from storage import load_identity++ def caller():+ require(os.getppid() == parent and Path(f"/proc/{parent}").stat().st_uid == os.getuid(), "CANCELLED")+ require(Path(f"/proc/{parent}/exe").resolve() == Path(executable).resolve(), "CANCELLED")+ caller()+ require(stat.S_ISFIFO(os.fstat(0).st_mode) or stat.S_ISSOCK(os.fstat(0).st_mode), "UNAVAILABLE")+ require(Path(executable).name.lower() in ("electron", "cindy", "cindydev"), "UNAVAILABLE")+ require(os.getuid() > 0 and os.geteuid() == os.getuid(), "UNAVAILABLE")+ host = Host(directory, load_identity, account, lock_state, verify_and_unlock)+ reader = asyncio.StreamReader(limit=MAX_PACKET)+ transport, _ = await asyncio.get_running_loop().connect_read_pipe(lambda: asyncio.StreamReaderProtocol(reader), sys.stdin.buffer)+ jobs = set()++ async def process(line):+ request_id = ""+ try:+ caller()+ value = decode(line)+ require(isinstance(value, dict) and isinstance(value.get("id"), str) and len(value["id"]) <= 128)+ request_id = value["id"]+ result = await host.call(value)+ caller()+ reply = {"id": request_id, "result": result}+ except asyncio.CancelledError:+ reply = {"id": request_id, "error": "CREDENTIAL_CANCELLED"}+ except Exception as error:+ reply = {"id": request_id, "error": str(error) if isinstance(error, Error) else "CREDENTIAL_UNAVAILABLE"}+ sys.stdout.buffer.write(encode(reply) + b"\n")+ sys.stdout.buffer.flush()++ owner = asyncio.current_task()+ asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, owner.cancel)+ try:+ while line := await reader.readline():+ caller()+ require(len(line) <= MAX_PACKET and len(jobs) < 16, "UNAVAILABLE")+ job = asyncio.create_task(process(line))+ jobs.add(job)+ job.add_done_callback(jobs.discard)+ finally:+ transport.close()+ host.close_all()+ for job in list(jobs):+ job.cancel()+ await asyncio.gather(*jobs, return_exceptions=True)+++if __name__ == "__main__":+ try:+ original_parent = os.getppid()+ harden()+ if os.getppid() != original_parent:+ raise RuntimeError()+ if sys.argv[1:] == ["--lock-state"]:+ from platform_linux import lock_state+ print(asyncio.run(lock_state()))+ elif sys.argv[1:] == ["--pam"]:+ from platform_linux import pam_verify+ pam_verify(sys.stdin.buffer.read(4097))+ elif len(sys.argv) == 5 and sys.argv[1] == "--serve":+ if int(sys.argv[3]) != original_parent:+ raise RuntimeError()+ asyncio.run(serve(sys.argv[2], original_parent, sys.argv[4]))+ else:+ raise RuntimeError()+ except BaseException:+ if sys.argv[1:] == ["--lock-state"]:+ print("unavailable")+ else:+ sys.exit(77)diff --git a/apps/desktop/native/remote-desktop/linux-credentials/platform_linux.py b/apps/desktop/native/remote-desktop/linux-credentials/platform_linux.pynew file mode 100644index 0000000000..414fc6e09e--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/platform_linux.py@@ -0,0 +1,230 @@+"""Hyprlock's documented SIGUSR1 interface, gated by native PAM verification.++No keyboard injection, compositor bypass, root helper or lock-screen configuration+changes. Unknown lockers and ambiguous/inactive sessions are unsupported.+"""+import asyncio+import ctypes+import ctypes.util+import hashlib+import os+from pathlib import Path+import pwd+import re+import signal+import stat+import sys+import time++from channel import Error, decode, require+++async def command(*args):+ proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE,+ stderr=asyncio.subprocess.DEVNULL)+ try:+ data, _ = await asyncio.wait_for(proc.communicate(), 2)+ require(proc.returncode == 0 and len(data) <= 65536, "UNLOCK_UNAVAILABLE")+ return data.decode()+ finally:+ if proc.returncode is None:+ proc.kill()+ await proc.wait()+++def trusted_file(path):+ value = Path(path).stat()+ require(stat.S_ISREG(value.st_mode) and value.st_uid == 0 and not value.st_mode & 0o022,+ "UNLOCK_UNAVAILABLE")+ return value.st_dev, value.st_ino+++def account():+ user = pwd.getpwuid(os.getuid())+ require(os.getuid() > 0 and os.geteuid() == os.getuid(), "UNLOCK_UNAVAILABLE")+ machine = Path("/etc/machine-id").read_text().strip()+ require(re.fullmatch(r"[a-f0-9]{32}", machine), "UNLOCK_UNAVAILABLE")+ record = hashlib.sha256(f"{machine}:{user.pw_uid}:{user.pw_name}".encode()).hexdigest()+ return {"name": user.pw_name, "recordID": record}+++async def session():+ session_id = os.environ.get("XDG_SESSION_ID", "")+ require(re.fullmatch(r"[a-zA-Z0-9_-]{1,64}", session_id), "UNLOCK_UNAVAILABLE")+ raw = await command("/usr/bin/loginctl", "show-session", session_id,+ "-p", "User", "-p", "Active", "-p", "Remote", "-p", "Type", "-p", "LockedHint")+ props = dict(line.split("=", 1) for line in raw.splitlines() if "=" in line)+ require(props.get("User") == str(os.getuid()) and props.get("Active") == "yes"+ and props.get("Remote") == "no" and props.get("Type") == "wayland"+ and props.get("LockedHint") in ("yes", "no"), "UNLOCK_UNAVAILABLE")+ # LockedHint is advisory; some lockers do not publish it. Confirm the actual+ # compositor lock, including a stranded lock whose client has exited.+ trusted_file("/usr/bin/hyprctl")+ monitors = decode(await command("/usr/bin/hyprctl", "-j", "monitors"))+ require(isinstance(monitors, list) and 0 < len(monitors) <= 32, "UNLOCK_UNAVAILABLE")+ blockers = [m.get("solitaryBlockedBy") for m in monitors]+ require(all(isinstance(items, list) and all(isinstance(x, str) for x in items) for items in blockers), "UNLOCK_UNAVAILABLE")+ if any("LOCK" in items for items in blockers):+ return session_id, True+ require(any("WORKSPACE" not in items for items in blockers), "UNLOCK_UNAVAILABLE")+ return session_id, False+++def locker_identity(pid):+ proc = Path("/proc") / str(pid)+ require(proc.stat().st_uid == os.getuid(), "UNLOCK_UNAVAILABLE")+ expected = trusted_file("/usr/bin/hyprlock")+ executable = (proc / "exe").stat()+ require((executable.st_dev, executable.st_ino) == expected, "UNLOCK_UNAVAILABLE")+ env = dict(item.split(b"=", 1) for item in (proc / "environ").read_bytes().split(b"\0") if b"=" in item)+ for key in ("XDG_SESSION_ID", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR"):+ require(os.environ.get(key) and env.get(key.encode()) == os.environ[key].encode(), "UNLOCK_UNAVAILABLE")+ fields = (proc / "stat").read_text().rsplit(")", 1)[1].split()+ require(fields[0] not in ("Z", "X"), "UNLOCK_UNAVAILABLE")+ return pid, fields[19], expected+++def lockers():+ trusted_file("/usr/bin/hyprlock")+ trusted_file("/etc/pam.d/hyprlock")+ require(hasattr(os, "pidfd_open") and hasattr(signal, "pidfd_send_signal"), "UNLOCK_UNAVAILABLE")+ matches = []+ for entry in Path("/proc").iterdir():+ if not entry.name.isdecimal():+ continue+ try:+ if (entry / "comm").read_text().strip() == "hyprlock":+ matches.append(locker_identity(int(entry.name)))+ except (FileNotFoundError, PermissionError, ProcessLookupError):+ continue+ require(len(matches) <= 1, "UNLOCK_UNAVAILABLE")+ return matches+++async def snapshot():+ session_id, locked = await session()+ running = lockers()+ # A PID alone does not prove the compositor granted the lock. Require both.+ require(locked == bool(running), "UNLOCK_UNAVAILABLE")+ return session_id, running[0] if running else None+++async def lock_state():+ try:+ _, locker = await snapshot()+ return "locked" if locker else "unlocked"+ except Exception:+ return "unavailable"+++async def verify_and_unlock(password, current):+ original_account = account()+ original = await snapshot()+ current()+ fd = os.pidfd_open(original[1][0]) if original[1] else None+ proc = None+ try:+ if original[1]:+ require(locker_identity(original[1][0]) == original[1], "UNLOCK_UNAVAILABLE")+ proc = await asyncio.create_subprocess_exec(+ sys.executable, "-I", "-B", str(Path(__file__).with_name("main.py")), "--pam",+ stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL)+ await asyncio.wait_for(proc.communicate(password), 15)+ current()+ require(proc.returncode == 0, "INVALID_IDENTITY")+ require(account() == original_account, "INVALID_IDENTITY")+ require(await snapshot() == original, "UNLOCK_UNAVAILABLE")+ current()+ if fd is None:+ return # Explicit setup on an already unlocked session verifies only.+ require(locker_identity(original[1][0]) == original[1], "UNLOCK_UNAVAILABLE")+ # pidfd cannot accidentally signal a new process after PID reuse.+ signal.pidfd_send_signal(fd, signal.SIGUSR1)+ for _ in range(50):+ await asyncio.sleep(.1)+ current()+ try:+ state = await snapshot()+ except Error:+ # Process exit and compositor release are not simultaneous.+ # Keep waiting for proof; never submit the password or signal again.+ continue+ current()+ require(state[0] == original[0] and account() == original_account, "UNLOCK_UNAVAILABLE")+ if state[1] is None:+ return+ require(state == original, "UNLOCK_UNAVAILABLE")+ raise Error("UNLOCK_UNAVAILABLE")+ finally:+ if fd is not None:+ os.close(fd)+ if proc and proc.returncode is None:+ proc.kill()+ await proc.wait()+++def pam_verify(password):+ """Only the isolated --pam subprocess accepts bytes from its private pipe."""+ require(0 < len(password) <= 4096 and b"\0" not in password)+ password.decode("utf-8")+ user = account()["name"].encode()+ trusted_file("/etc/pam.d/hyprlock")+ lib = ctypes.CDLL("libpam.so.0")+ libc = ctypes.CDLL(None)++ class Message(ctypes.Structure):+ _fields_ = [("style", ctypes.c_int), ("text", ctypes.c_char_p)]++ class Response(ctypes.Structure):+ _fields_ = [("text", ctypes.c_void_p), ("code", ctypes.c_int)]++ callback_type = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int,+ ctypes.POINTER(ctypes.POINTER(Message)),+ ctypes.POINTER(ctypes.POINTER(Response)), ctypes.c_void_p)+ libc.calloc.argtypes = [ctypes.c_size_t, ctypes.c_size_t]+ libc.calloc.restype = ctypes.c_void_p+ libc.strdup.argtypes = [ctypes.c_char_p]+ libc.strdup.restype = ctypes.c_void_p+ libc.free.argtypes = [ctypes.c_void_p]++ @callback_type+ def conversation(count, messages, responses, _data):+ if not 0 < count <= 16:+ return 19 # PAM_CONV_ERR+ allocation = libc.calloc(count, ctypes.sizeof(Response))+ if not allocation:+ return 5+ values = ctypes.cast(allocation, ctypes.POINTER(Response))+ for i in range(count):+ style = messages[i].contents.style+ if style not in (1, 2, 3, 4):+ for j in range(i):+ libc.free(values[j].text)+ libc.free(allocation)+ return 19+ if style in (1, 2):+ values[i].text = libc.strdup(password if style == 1 else user)+ if not values[i].text:+ for j in range(i):+ libc.free(values[j].text)+ libc.free(allocation)+ return 5+ responses[0] = values+ return 0++ class Conversation(ctypes.Structure):+ _fields_ = [("callback", callback_type), ("data", ctypes.c_void_p)]++ conv, handle = Conversation(conversation, None), ctypes.c_void_p()+ lib.pam_start.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.POINTER(Conversation), ctypes.POINTER(ctypes.c_void_p)]+ for name in ("pam_authenticate", "pam_acct_mgmt", "pam_end"):+ getattr(lib, name).argtypes = [ctypes.c_void_p, ctypes.c_int]+ result = lib.pam_start(b"hyprlock", user, ctypes.byref(conv), ctypes.byref(handle))+ require(result == 0, "UNAVAILABLE")+ try:+ result = lib.pam_authenticate(handle, 1) # PAM_DISALLOW_NULL_AUTHTOK+ if result == 0:+ result = lib.pam_acct_mgmt(handle, 0)+ require(result == 0, "INVALID_IDENTITY")+ finally:+ lib.pam_end(handle, result)diff --git a/apps/desktop/native/remote-desktop/linux-credentials/requirements.txt b/apps/desktop/native/remote-desktop/linux-credentials/requirements.txtnew file mode 100644index 0000000000..adf6ee0ff2--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/requirements.txt@@ -0,0 +1,3 @@+# Distribution runtime dependencies: Python >= 3.11, PyGObject + Secret-1,+# libpam, loginctl and Hyprlock. No packages are downloaded at runtime.+jwcrypto>=1.6.1,<2diff --git a/apps/desktop/native/remote-desktop/linux-credentials/storage.py b/apps/desktop/native/remote-desktop/linux-credentials/storage.pynew file mode 100644index 0000000000..b1a83f0efc--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/storage.py@@ -0,0 +1,61 @@+"""Private host identity in the desktop Secret Service; disk holds only a pin.++Never unlock a locked collection, fall back to plaintext, or replace a missing+key behind an existing pin. Linux Secret Service protects storage, not against+other compromised applications running as the same OS user.+"""+import fcntl+import hashlib+import os+from pathlib import Path++from channel import jwk, public, encode, require+++def load_identity(directory, realm):+ import gi+ gi.require_version("Secret", "1")+ from gi.repository import Secret++ directory = Path(directory)+ require(directory.is_absolute() and not directory.is_symlink(), "UNAVAILABLE")+ directory.mkdir(mode=0o700, parents=True, exist_ok=True)+ require(directory.stat().st_uid == os.getuid() and directory.stat().st_mode & 0o077 == 0, "UNAVAILABLE")+ scope = hashlib.sha256(str(directory.resolve()).encode()).hexdigest()+ schema = Secret.Schema.new("org.makecindy.RemoteCredentials", Secret.SchemaFlags.NONE,+ {"profile": Secret.SchemaAttributeType.STRING,+ "realm": Secret.SchemaAttributeType.STRING})+ attrs = {"profile": scope, "realm": realm}+ lock = os.open(directory / "identity.lock", os.O_RDWR | os.O_CREAT | os.O_NOFOLLOW, 0o600)+ try:+ fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)+ service = Secret.Service.get_sync(Secret.ServiceFlags.OPEN_SESSION, None)+ items = service.search_sync(schema, attrs, Secret.SearchFlags.ALL | Secret.SearchFlags.LOAD_SECRETS, None)+ require(len(items) <= 1, "UNAVAILABLE")+ marker = directory / (realm + ".public-sha256")+ require(not marker.is_symlink(), "UNAVAILABLE")+ if items:+ require(not items[0].get_locked(), "UNAVAILABLE")+ secret = items[0].get_secret()+ require(secret is not None, "UNAVAILABLE")+ key = jwk.JWK.from_json(secret.get_text())+ require(key.has_private and key.get("kty") == "EC" and key.get("crv") == "P-256", "UNAVAILABLE")+ else:+ require(not marker.exists(), "INVALID_IDENTITY")+ collection = Secret.Collection.for_alias_sync(service, "default", Secret.CollectionFlags.NONE, None)+ require(collection is not None and not collection.get_locked(), "UNAVAILABLE")+ key = jwk.JWK.generate(kty="EC", crv="P-256")+ require(Secret.password_store_sync(schema, attrs, "default", "Cindy remote desktop identity",+ key.export_private(), None), "UNAVAILABLE")+ fingerprint = hashlib.sha256(encode(public(key))).hexdigest()+ if marker.exists():+ require(marker.read_text() == fingerprint, "INVALID_IDENTITY")+ else:+ fd = os.open(marker, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o600)+ with os.fdopen(fd, "w") as stream:+ stream.write(fingerprint)+ stream.flush()+ os.fsync(stream.fileno())+ return key+ finally:+ os.close(lock)diff --git a/apps/desktop/native/remote-desktop/linux-credentials/test.mjs b/apps/desktop/native/remote-desktop/linux-credentials/test.mjsnew file mode 100644index 0000000000..42e3465ffb--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/test.mjs@@ -0,0 +1,164 @@+// Independent JOSE implementation, generated fake identities, no real OS secrets.+import assert from 'node:assert/strict';+import { spawn, spawnSync } from 'node:child_process';+import { createHash, randomUUID } from 'node:crypto';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { createInterface } from 'node:readline';+import {+ CompactSign,+ compactVerify,+ CompactEncrypt,+ compactDecrypt,+ exportJWK,+ generateKeyPair,+ importJWK,+} from 'jose';++const directory = path.dirname(fileURLToPath(import.meta.url));+const python = process.argv[2] ?? '/usr/bin/python3';+const unit = spawnSync(python, ['-I', '-B', path.join(directory, 'test_credentials.py')], {+ stdio: 'inherit',+});+assert.equal(unit.status, 0);+const child = spawn(python, ['-I', '-B', path.join(directory, 'test_interop.py')], {+ stdio: ['pipe', 'pipe', 'inherit'],+});+const waiting = new Map();+const lines = createInterface({ input: child.stdout });+lines.on('line', (line) => {+ const value = JSON.parse(line),+ pending = waiting.get(value.id);+ assert.ok(pending);+ waiting.delete(value.id);+ value.error ? pending.reject(new Error(value.error)) : pending.resolve(value.result);+});+const exited = new Promise((resolve) => child.once('exit', resolve));+child.on('exit', () => {+ for (const p of waiting.values()) p.reject(new Error('helper exited'));+});+const call = (method, args = {}) =>+ new Promise((resolve, reject) => {+ const id = randomUUID();+ waiting.set(id, { resolve, reject });+ child.stdin.write(JSON.stringify({ id, method, ...args }) + '\n');+ });+function canonical(value) {+ if (Array.isArray(value)) return value.map(canonical);+ if (value && typeof value === 'object')+ return Object.fromEntries(+ Object.keys(value)+ .sort()+ .map((key) => [key, canonical(value[key])]),+ );+ return value;+}+const bytes = (v) => Buffer.from(JSON.stringify(v));+const keys = await generateKeyPair('ES256', { extractable: true });+const ephemeral = await generateKeyPair('ECDH-ES', { crv: 'P-256', extractable: true });+const local = {+ version: 1,+ device: 'phone',+ membership: 'test-account',+ realm: 'global',+ publicKey: await exportJWK(keys.publicKey),+};+const timer = setTimeout(() => child.kill(), 15000);+try {+ const host = JSON.parse(+ await call('configure', { realm: 'global', membership: 'test-account', authDevice: 'host' }),+ );+ const hostKey = await importJWK(host.publicKey, 'ES256');+ const offer = {+ domain: 'cindy.remote-desktop.offer.v1',+ realm: 'global',+ membership: 'test-account',+ from: 'phone',+ to: 'host',+ nonce: randomUUID(),+ ephemeral: await exportJWK(ephemeral.publicKey),+ expiresAt: Date.now() + 60000,+ };+ const signedOffer = await new CompactSign(bytes(offer))+ .setProtectedHeader({ alg: 'ES256', typ: 'cindy-remote-desktop-offer-v1' })+ .sign(keys.privateKey);+ const opened = await call('begin', {+ peer: 'phone',+ offer: signedOffer,+ descriptor: JSON.stringify(local),+ });+ const remote = JSON.parse(Buffer.from((await compactVerify(opened.offer, hostKey)).payload));+ const session = createHash('sha256')+ .update(bytes(canonical([offer, remote].sort((a, b) => a.from.localeCompare(b.from)))))+ .digest('base64url');+ const recipient = await importJWK(remote.ephemeral, 'ECDH-ES');+ let sequence = 0;+ async function packet(purpose, body) {+ const plaintext = bytes({+ domain: 'cindy.remote-desktop.packet.v1',+ session,+ from: 'phone',+ to: 'host',+ sequence: ++sequence,+ purpose,+ body: bytes(body).toString('base64'),+ });+ const ciphertext = await new CompactEncrypt(plaintext)+ .setProtectedHeader({ alg: 'ECDH-ES', enc: 'A256GCM', typ: 'cindy-remote-desktop-v1' })+ .encrypt(recipient);+ return new CompactSign(Buffer.from(ciphertext))+ .setProtectedHeader({ alg: 'ES256', typ: 'cindy-remote-desktop-v1', cty: 'JWE' })+ .sign(keys.privateKey);+ }+ async function receive(ciphertext) {+ const signed = await compactVerify(ciphertext, hostKey, { algorithms: ['ES256'] });+ const encrypted = await compactDecrypt(+ Buffer.from(signed.payload).toString(),+ ephemeral.privateKey,+ { keyManagementAlgorithms: ['ECDH-ES'], contentEncryptionAlgorithms: ['A256GCM'] },+ );+ const value = JSON.parse(Buffer.from(encrypted.plaintext));+ assert.equal(value.session, session);+ assert.equal(value.from, 'host');+ assert.equal(value.to, 'phone');+ return { purpose: value.purpose, body: JSON.parse(Buffer.from(value.body, 'base64')) };+ }+ const exchange = async (ciphertext) =>+ call('receive', { peer: 'phone', handle: opened.handle, ciphertext });+ const readyPacket = await packet('ready', {});+ const ready = await receive((await exchange(readyPacket)).ciphertext);+ assert.equal(ready.purpose, 'ready');+ await assert.rejects(exchange(readyPacket));+ const authentication = await packet('authenticate', {+ id: randomUUID(),+ account: ready.body,+ password: Buffer.from('fake-interop-password').toString('base64'),+ });+ const accepted = await receive((await exchange(authentication)).ciphertext);+ assert.equal(accepted.body.accepted, true);+ const command = await exchange(+ await packet('request', {+ id: 'request-1',+ payload: Buffer.from('{"op":"capabilities"}').toString('base64'),+ }),+ );+ assert.equal(command.kind, 'command');+ const response = await call('response', {+ peer: 'phone',+ handle: opened.handle,+ requestId: 'request-1',+ body: '{"ok":true}',+ success: true,+ });+ const decoded = await receive(response);+ assert.equal(decoded.purpose, 'response');+ assert.equal(Buffer.from(decoded.body.payload, 'base64').toString(), '{"ok":true}');+ console.log(+ 'Independent JOSE handshake, encrypted password, response and replay rejection passed',+ );+} finally {+ clearTimeout(timer);+ lines.close();+ child.stdin.end();+ await exited;+}diff --git a/apps/desktop/native/remote-desktop/linux-credentials/test_credentials.py b/apps/desktop/native/remote-desktop/linux-credentials/test_credentials.pynew file mode 100644index 0000000000..843f48cbc8--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/test_credentials.py@@ -0,0 +1,334 @@+"""In-memory tests only: no personal keyring, real password or screen lock."""+import asyncio+import base64+import json+from pathlib import Path+import sys+import time+import unittest+from unittest.mock import AsyncMock, Mock, patch+import uuid+import tempfile+from types import SimpleNamespace++sys.path.insert(0, str(Path(__file__).resolve().parent))+from channel import Channel, Error, b64, decode, encode, jwk, open_sealed, public, seal, sign+from host import Host+import platform_linux as platform+++def peer(name, key, realm="global"):+ return {"version": 1, "device": name, "membership": "test-account", "realm": realm, "publicKey": public(key)}+++class ChannelTests(unittest.TestCase):+ def setUp(self):+ a, b = jwk.JWK.generate(kty="EC", crv="P-256"), jwk.JWK.generate(kty="EC", crv="P-256")+ self.a = Channel(peer("phone", a), peer("host", b), a)+ self.b = Channel(peer("host", b), peer("phone", a), b)+ self.a.accept(self.b.offer())+ self.b.accept(self.a.offer())++ def test_ready_replay_and_password_roundtrip(self):+ packet = self.a.send("ready", {})+ self.b.receive(packet)+ with self.assertRaises(Error):+ self.b.receive(packet)+ self.a.receive(self.b.send("ready", {}))+ purpose, body = self.b.receive(self.a.send("authenticate", {"password": "fake"}))+ self.assertEqual((purpose, decode(body)), ("authenticate", {"password": "fake"}))++ def test_unconfirmed_cannot_send_password(self):+ with self.assertRaises(Error):+ self.a.send("authenticate", {})++ def test_foreign_signer_rejected(self):+ key = jwk.JWK.generate(kty="EC", crv="P-256")+ with self.assertRaises(Exception):+ self.b.receive(sign(b"fake", key))++ def test_forbidden_header_rejected(self):+ from jwcrypto import jws+ token = jws.JWS(b"fake")+ token.add_signature(self.a.key, protected=json.dumps({"alg": "ES256", "typ": "cindy-remote-desktop-v1", "cty": "JWE", "jku": "https://invalid.test"}))+ with self.assertRaises(Error):+ self.b.receive(token.serialize(compact=True))++ def test_closed_and_expired_channels(self):+ self.a.deadline = time.monotonic() - 1+ with self.assertRaisesRegex(Error, "EXPIRED"):+ self.a.offer()+ self.b.close()+ with self.assertRaisesRegex(Error, "EXPIRED"):+ self.b.offer()++ def test_realm_and_account_binding(self):+ key = jwk.JWK.generate(kty="EC", crv="P-256")+ for field, value in [("realm", "cn"), ("membership", "other"), ("device", "host")]:+ remote = peer("phone", self.a.key)+ remote[field] = value+ with self.subTest(field=field), self.assertRaisesRegex(Error, "INVALID_IDENTITY"):+ Channel(peer("host", key), remote, key)++ def test_tamper_does_not_consume_sequence(self):+ packet = self.a.send("ready", {})+ parts = packet.split(".")+ parts[1] = b64(b"altered")+ with self.assertRaises(Exception):+ self.b.receive(".".join(parts))+ self.assertEqual(self.b.receive(packet)[0], "ready")++ def test_noncanonical_and_duplicate_json(self):+ from channel import unb64+ with self.assertRaises(Exception):+ unb64("YWJj=")+ with self.assertRaises(Error):+ decode('{"alg":"ES256","alg":"none"}')+++class HostTests(unittest.IsolatedAsyncioTestCase):+ async def asyncSetUp(self):+ self.account = {"name": "test-user", "recordID": "test-record"}+ self.key = jwk.JWK.generate(kty="EC", crv="P-256")+ self.state = "locked"+ self.calls = 0+ self.reject = False++ async def unlock(password, current):+ self.calls += 1+ current()+ self.assertEqual(password, b"fake-test-password")+ if self.reject:+ raise Error("INVALID_IDENTITY")+ self.state = "unlocked"++ async def read_state():+ return self.state+ self.host = Host("/unused-test-directory", lambda *_: self.key, lambda: self.account.copy(), read_state, unlock)+ self.descriptor = decode(await self.host.call({"method": "configure", "realm": "global", "membership": "test-account", "authDevice": "host"}))+ await self.connect()++ async def connect(self):+ key = jwk.JWK.generate(kty="EC", crv="P-256")+ descriptor = peer("phone", key)+ self.phone = Channel(descriptor, self.descriptor, key)+ opened = await self.host.call({"method": "begin", "peer": "phone", "offer": self.phone.offer(), "descriptor": encode(descriptor).decode()})+ self.handle = opened["handle"]+ self.phone.accept(opened["offer"])+ self.assertEqual(await self.host.status(), {})+ reply = await self.exchange("ready", {})+ self.phone.receive(reply["ciphertext"])++ async def exchange(self, purpose, body):+ return await self.host.call({"method": "receive", "handle": self.handle, "peer": "phone", "ciphertext": self.phone.send(purpose, body)})++ def attempt(self):+ return {"id": str(uuid.uuid4()), "account": self.account.copy(), "password": base64.b64encode(b"fake-test-password").decode()}++ async def test_success_deduplication_and_authorized_command(self):+ attempt = self.attempt()+ for _ in range(2):+ result = await self.exchange("authenticate", attempt)+ self.assertTrue(decode(self.phone.receive(result["ciphertext"])[1])["accepted"])+ self.assertEqual(self.calls, 1)+ self.assertIn("phone", await self.host.status())+ result = await self.exchange("request", {"id": "test-command", "payload": base64.b64encode(b'{"op":"capabilities"}').decode()})+ self.assertEqual(result["kind"], "command")+ self.assertNotIn("password", json.dumps(result))++ async def test_wrong_password_and_attempt_status(self):+ self.reject = True+ attempt = self.attempt()+ result = await self.exchange("authenticate", attempt)+ self.assertFalse(decode(self.phone.receive(result["ciphertext"])[1])["accepted"])+ result = await self.exchange("authentication-status", {"id": attempt["id"]})+ self.assertFalse(decode(self.phone.receive(result["ciphertext"])[1])["accepted"])+ self.assertEqual(await self.host.status(), {})+ self.assertEqual(self.calls, 1)++ async def test_reconnect_does_not_reset_attempt_budget(self):+ self.reject = True+ for _ in range(5):+ await self.exchange("authenticate", self.attempt())+ await self.connect()+ with self.assertRaisesRegex(Error, "UNAVAILABLE"):+ await self.exchange("authenticate", self.attempt())+ self.assertEqual(self.calls, 5)++ async def test_cancellation_revokes_inflight_password_operation(self):+ started = asyncio.Event()+ async def waiting(password, current):+ started.set()+ await asyncio.Event().wait()+ self.host.unlock = waiting+ job = asyncio.create_task(self.exchange("authenticate", self.attempt()))+ await started.wait()+ await self.host.call({"method": "close", "peer": "phone"})+ with self.assertRaises(asyncio.CancelledError):+ await job+ self.assertFalse(self.host.verifying)+ self.assertEqual(await self.host.status(), {})++ async def test_relock_invalidates_authorization(self):+ await self.exchange("authenticate", self.attempt())+ self.state = "locked"+ self.assertEqual(await self.host.status(), {})+ self.assertNotIn(self.handle, self.host.sessions)++ async def test_unknown_locker_never_loads_key(self):+ self.state = "unavailable"+ self.host.load_key = lambda *_: self.fail("key accessed for unsupported locker")+ with self.assertRaisesRegex(Error, "UNLOCK_UNAVAILABLE"):+ await self.host.call({"method": "configure", "realm": "global", "membership": "new", "authDevice": "host"})++ async def test_forged_account_and_pre_auth_commands(self):+ attempt = self.attempt()+ attempt["account"] = {"recordID": "other", "name": "root"}+ with self.assertRaises(Error):+ await self.exchange("authenticate", attempt)+ with self.assertRaises(Error):+ await self.exchange("request", {"id": "fake", "payload": "e30="})+ self.assertEqual(self.calls, 0)+++class PlatformTests(unittest.IsolatedAsyncioTestCase):+ async def asyncSetUp(self):+ self.target = (123, "456", (1, 2))+ self.original = ("test-session", self.target)+ self.proc = Mock(returncode=0, communicate=AsyncMock(return_value=(b"", b"")), wait=AsyncMock())+ self.patches = [patch.object(platform, "account", return_value={"name": "fake", "recordID": "fake"}),+ patch.object(platform, "snapshot", AsyncMock(side_effect=[self.original, self.original, ("test-session", None)])),+ patch.object(platform, "locker_identity", return_value=self.target),+ patch.object(platform.os, "pidfd_open", return_value=999),+ patch.object(platform.os, "close"),+ patch.object(platform.signal, "pidfd_send_signal"),+ patch.object(platform.asyncio, "create_subprocess_exec", AsyncMock(return_value=self.proc)),+ patch.object(platform.asyncio, "sleep", AsyncMock())]+ for item in self.patches:+ item.start()+ self.addCleanup(item.stop)++ async def test_signal_follows_pam_and_confirmed_same_locker(self):+ await platform.verify_and_unlock(b"fake-password", lambda: None)+ self.proc.communicate.assert_awaited_once_with(b"fake-password")+ self.assertNotIn("fake-password", repr(platform.asyncio.create_subprocess_exec.call_args))+ platform.signal.pidfd_send_signal.assert_called_once_with(999, platform.signal.SIGUSR1)+ platform.os.close.assert_called_once_with(999)++ async def test_rejected_password_never_signals(self):+ self.proc.returncode = 1+ with self.assertRaisesRegex(Error, "INVALID_IDENTITY"):+ await platform.verify_and_unlock(b"fake-password", lambda: None)+ platform.signal.pidfd_send_signal.assert_not_called()++ async def test_replaced_locker_never_signals(self):+ platform.snapshot.side_effect = [self.original, ("test-session", (124, "new", (1, 2)))]+ with self.assertRaisesRegex(Error, "UNLOCK_UNAVAILABLE"):+ await platform.verify_and_unlock(b"fake-password", lambda: None)+ platform.signal.pidfd_send_signal.assert_not_called()++ async def test_revocation_after_pam_never_signals(self):+ current = Mock(side_effect=[None, Error("CANCELLED")])+ with self.assertRaisesRegex(Error, "CANCELLED"):+ await platform.verify_and_unlock(b"fake-password", current)+ platform.signal.pidfd_send_signal.assert_not_called()++ async def test_cancelled_pam_worker_is_killed(self):+ self.proc.returncode = None+ self.proc.communicate.side_effect = asyncio.CancelledError()+ with self.assertRaises(asyncio.CancelledError):+ await platform.verify_and_unlock(b"fake-password", lambda: None)+ self.proc.kill.assert_called_once()+ self.proc.wait.assert_awaited_once()+ platform.signal.pidfd_send_signal.assert_not_called()++ async def test_verified_password_without_unlock_does_not_succeed(self):+ platform.snapshot.side_effect = None+ platform.snapshot.return_value = self.original+ with self.assertRaisesRegex(Error, "UNLOCK_UNAVAILABLE"):+ await platform.verify_and_unlock(b"fake-password", lambda: None)+ platform.signal.pidfd_send_signal.assert_called_once()++ async def test_unlocked_setup_does_not_signal(self):+ platform.snapshot.side_effect = [("test-session", None), ("test-session", None)]+ await platform.verify_and_unlock(b"fake-password", lambda: None)+ platform.signal.pidfd_send_signal.assert_not_called()+ platform.os.pidfd_open.assert_not_called()++ async def test_lock_state_requires_both_logind_and_known_locker(self):+ # Exercise the real composition rather than the unlock operation fixture.+ self.patches[1].stop()+ target = (123, "456", (1, 2))+ for hint, found, expected in [(False, [], "unlocked"), (True, [target], "locked"),+ (True, [], "unavailable"), (False, [target], "unavailable")]:+ with patch.object(platform, "session", AsyncMock(return_value=("test", hint))), patch.object(platform, "lockers", return_value=found):+ self.assertEqual(await platform.lock_state(), expected)++ async def test_unknown_locker_is_unavailable(self):+ with patch.object(platform, "snapshot", AsyncMock(side_effect=Error("UNLOCK_UNAVAILABLE"))):+ self.assertEqual(await platform.lock_state(), "unavailable")+++class StorageTests(unittest.TestCase):+ def setUp(self):+ from storage import load_identity+ self.load = load_identity+ self.temp = tempfile.TemporaryDirectory(prefix="cindy-credential-test-")+ self.addCleanup(self.temp.cleanup)+ self.directory = Path(self.temp.name)+ self.items = []+ self.secret = None+ self.locked = False+ def store(_schema, _attrs, _collection, _label, value, _cancel):+ self.secret = value+ self.items[:] = [SimpleNamespace(get_locked=lambda: self.locked, get_secret=lambda: SimpleNamespace(get_text=lambda: self.secret))]+ return True+ service = SimpleNamespace(search_sync=lambda *_: self.items)+ secret_api = SimpleNamespace(Schema=SimpleNamespace(new=lambda *_: object()), SchemaFlags=SimpleNamespace(NONE=0),+ SchemaAttributeType=SimpleNamespace(STRING=0), ServiceFlags=SimpleNamespace(OPEN_SESSION=1),+ SearchFlags=SimpleNamespace(ALL=1, LOAD_SECRETS=2), CollectionFlags=SimpleNamespace(NONE=0),+ Service=SimpleNamespace(get_sync=lambda *_: service),+ Collection=SimpleNamespace(for_alias_sync=lambda *_: SimpleNamespace(get_locked=lambda: self.locked)),+ password_store_sync=Mock(side_effect=store))+ self.api = secret_api+ modules = {"gi": SimpleNamespace(require_version=lambda *_: None), "gi.repository": SimpleNamespace(Secret=secret_api)}+ context = patch.dict(sys.modules, modules)+ context.start()+ self.addCleanup(context.stop)++ def test_identity_reloads_and_only_public_pin_reaches_disk(self):+ first = self.load(self.directory, "global")+ self.assertEqual(public(self.load(self.directory, "global")), public(first))+ self.api.password_store_sync.assert_called_once()+ for item in self.directory.iterdir():+ self.assertNotIn(first.get("d"), item.read_text())++ def test_locked_key_is_not_replaced(self):+ self.load(self.directory, "global")+ self.locked = True+ with self.assertRaisesRegex(Error, "UNAVAILABLE"):+ self.load(self.directory, "global")+ self.api.password_store_sync.assert_called_once()++ def test_missing_pinned_key_is_not_recreated(self):+ self.load(self.directory, "global")+ self.items.clear()+ with self.assertRaisesRegex(Error, "INVALID_IDENTITY"):+ self.load(self.directory, "global")+ self.api.password_store_sync.assert_called_once()++ def test_locked_collection_cannot_create_first_identity(self):+ self.locked = True+ with self.assertRaisesRegex(Error, "UNAVAILABLE"):+ self.load(self.directory, "global")+ self.api.password_store_sync.assert_not_called()++ def test_changed_identity_is_not_silently_accepted(self):+ self.load(self.directory, "global")+ self.secret = jwk.JWK.generate(kty="EC", crv="P-256").export_private()+ with self.assertRaisesRegex(Error, "INVALID_IDENTITY"):+ self.load(self.directory, "global")+++if __name__ == "__main__":+ unittest.main()diff --git a/apps/desktop/native/remote-desktop/linux-credentials/test_interop.py b/apps/desktop/native/remote-desktop/linux-credentials/test_interop.pynew file mode 100644index 0000000000..ac27e40257--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-credentials/test_interop.py@@ -0,0 +1,30 @@+"""Fake OS backend for the independent Node JOSE interoperability test only."""+import asyncio+from pathlib import Path+import sys+sys.path.insert(0, str(Path(__file__).resolve().parent))+from channel import decode, encode, jwk, require+from host import Host+++async def run():+ key = jwk.JWK.generate(kty="EC", crv="P-256")+ locked = True+ async def state():+ return "locked" if locked else "unlocked"+ async def unlock(password, current):+ nonlocal locked+ current()+ require(password == b"fake-interop-password", "INVALID_IDENTITY")+ locked = False+ host = Host("/unused", lambda *_: key, lambda: {"name": "fake-user", "recordID": "fake-record"}, state, unlock)+ for line in sys.stdin.buffer:+ value = decode(line)+ try:+ result = await host.call(value)+ print(encode({"id": value["id"], "result": result}).decode(), flush=True)+ except Exception:+ print(encode({"id": value["id"], "error": "rejected"}).decode(), flush=True)+++asyncio.run(run())diff --git a/apps/desktop/native/remote-desktop/linux-input/build.mjs b/apps/desktop/native/remote-desktop/linux-input/build.mjsnew file mode 100644index 0000000000..696a618f40--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-input/build.mjs@@ -0,0 +1,51 @@+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+const source = path.dirname(fileURLToPath(import.meta.url));+const [output] = process.argv.slice(2);+if (!output || !path.isAbsolute(output)) throw new Error('Absolute output directory required');+fs.mkdirSync(output, { recursive: true });+function run(command, args) {+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 60000 });+ if (result.error || result.status !== 0)+ throw new Error(`Linux input build failed: ${command}: ${result.stderr || result.error}`);+ return result.stdout.trim();+}+for (const name of ['virtual-keyboard-unstable-v1', 'wlr-virtual-pointer-unstable-v1']) {+ run('wayland-scanner', [+ 'client-header',+ path.join(source, name + '.xml'),+ path.join(output, name + '.h'),+ ]);+ run('wayland-scanner', [+ 'private-code',+ path.join(source, name + '.xml'),+ path.join(output, name + '.c'),+ ]);+}+const flags = run('pkg-config', [+ '--cflags',+ '--libs',+ 'wayland-client',+ 'xkbcommon',+ 'json-c',+]).split(/\s+/);+const binary = path.join(output, 'cindy-linux-desktop-input');+run('cc', [+ '-std=c11',+ '-Wall',+ '-Wextra',+ '-Werror',+ '-O2',+ path.join(source, 'main.c'),+ path.join(output, 'virtual-keyboard-unstable-v1.c'),+ path.join(output, 'wlr-virtual-pointer-unstable-v1.c'),+ '-I',+ output,+ ...flags,+ '-lm',+ '-o',+ binary + '.tmp',+]);+fs.renameSync(binary + '.tmp', binary);diff --git a/apps/desktop/native/remote-desktop/linux-input/main.c b/apps/desktop/native/remote-desktop/linux-input/main.cnew file mode 100644index 0000000000..b2a26953d1--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-input/main.c@@ -0,0 +1,510 @@+#define _GNU_SOURCE+#include "virtual-keyboard-unstable-v1.h"+#include "wlr-virtual-pointer-unstable-v1.h"+#include <errno.h>+#include <json-c/json.h>+#include <linux/input-event-codes.h>+#include <math.h>+#include <poll.h>+#include <signal.h>+#include <stdbool.h>+#include <stdint.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/mman.h>+#include <time.h>+#include <unistd.h>+#include <wayland-client.h>+#include <xkbcommon/xkbcommon.h>++// Private stdin/stdout protocol, identical lifecycle to the other input+// helpers. No sockets beyond the user's compositor, root privileges, or input+// logging.+static struct wl_display *display;+static struct wl_seat *seat;+static struct zwp_virtual_keyboard_manager_v1 *keyboard_manager;+static struct zwlr_virtual_pointer_manager_v1 *pointer_manager;+static struct zwp_virtual_keyboard_v1 *keyboard;+static struct zwlr_virtual_pointer_v1 *pointer;+static struct xkb_keymap *keymap;+static struct xkb_state *state;+static bool keys[256], buttons[3];+static volatile sig_atomic_t stopping;+static const uint32_t button_codes[] = {BTN_LEFT, BTN_MIDDLE, BTN_RIGHT};+static uint32_t now(void) {+ struct timespec t;+ clock_gettime(CLOCK_MONOTONIC, &t);+ return (uint32_t)((uint64_t)t.tv_sec * 1000 + t.tv_nsec / 1000000);+}+static void interrupted(int sig) {+ stopping = 1;+ if (sig == SIGALRM) {+ signal(SIGALRM, SIG_DFL);+ alarm(+ 1); // Bound shutdown if the compositor itself has stopped servicing us.+ }+}+static void global(void *data, struct wl_registry *registry, uint32_t name,+ const char *interface, uint32_t version) {+ (void)data;+ (void)version;+ if (!seat && !strcmp(interface, "wl_seat"))+ seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);+ if (!strcmp(interface, "zwp_virtual_keyboard_manager_v1"))+ keyboard_manager = wl_registry_bind(+ registry, name, &zwp_virtual_keyboard_manager_v1_interface, 1);+ if (!strcmp(interface, "zwlr_virtual_pointer_manager_v1"))+ pointer_manager = wl_registry_bind(+ registry, name, &zwlr_virtual_pointer_manager_v1_interface, 1);+}+static void removed(void *data, struct wl_registry *registry, uint32_t name) {+ (void)data;+ (void)registry;+ (void)name;+}+static const struct wl_registry_listener registry_listener = {global, removed};+static bool set_keymap(struct zwp_virtual_keyboard_v1 *target,+ const char *text) {+ size_t size = strlen(text) + 1;+ int fd = memfd_create("cindy-input-keymap", MFD_CLOEXEC);+ if (fd < 0)+ return false;+ bool ok = ftruncate(fd, (off_t)size) == 0;+ void *memory =+ ok ? mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)+ : MAP_FAILED;+ if (memory == MAP_FAILED) {+ close(fd);+ return false;+ }+ memcpy(memory, text, size);+ zwp_virtual_keyboard_v1_keymap(target, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, fd,+ (uint32_t)size);+ munmap(memory, size);+ close(fd);+ return wl_display_roundtrip(display) >= 0;+}+static void modifiers(void) {+ zwp_virtual_keyboard_v1_modifiers(+ keyboard, xkb_state_serialize_mods(state, XKB_STATE_MODS_DEPRESSED),+ xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED),+ xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED),+ xkb_state_serialize_layout(state, XKB_STATE_LAYOUT_EFFECTIVE));+}+static void key(uint32_t code, bool down) {+ if (keys[code] == down)+ return;+ keys[code] = down;+ zwp_virtual_keyboard_v1_key(keyboard, now(), code, down);+ xkb_state_update_key(state, code + 8, down ? XKB_KEY_DOWN : XKB_KEY_UP);+ modifiers();+}+static void release_all(void) {+ if (keyboard && state)+ for (uint32_t i = 0; i < 256; i++)+ if (keys[i])+ key(i, false);+ if (pointer) {+ for (int i = 0; i < 3; i++)+ if (buttons[i]) {+ zwlr_virtual_pointer_v1_button(pointer, now(), button_codes[i], 0);+ buttons[i] = false;+ }+ zwlr_virtual_pointer_v1_frame(pointer);+ }+}+static int key_code(const char *name) {+ if (strlen(name) == 4 && !strncmp(name, "Key", 3) && name[3] >= 'A' &&+ name[3] <= 'Z') {+ static const int codes[] = {30, 48, 46, 32, 18, 33, 34, 35, 23,+ 36, 37, 38, 50, 49, 24, 25, 16, 19,+ 31, 20, 22, 47, 17, 45, 21, 44};+ return codes[name[3] - 'A'];+ }+ if (strlen(name) == 6 && !strncmp(name, "Digit", 5) && name[5] >= '0' &&+ name[5] <= '9')+ return name[5] == '0' ? KEY_0 : KEY_1 + name[5] - '1';+ const struct {+ const char *name;+ int code;+ } map[] = {+ {"F1", KEY_F1},+ {"F2", KEY_F2},+ {"F3", KEY_F3},+ {"F4", KEY_F4},+ {"F5", KEY_F5},+ {"F6", KEY_F6},+ {"F7", KEY_F7},+ {"F8", KEY_F8},+ {"F9", KEY_F9},+ {"F10", KEY_F10},+ {"F11", KEY_F11},+ {"F12", KEY_F12},+ {"Enter", KEY_ENTER},+ {"Escape", KEY_ESC},+ {"Tab", KEY_TAB},+ {"Space", KEY_SPACE},+ {"Backspace", KEY_BACKSPACE},+ {"Delete", KEY_DELETE},+ {"Insert", KEY_INSERT},+ {"Home", KEY_HOME},+ {"End", KEY_END},+ {"PageUp", KEY_PAGEUP},+ {"PageDown", KEY_PAGEDOWN},+ {"ArrowUp", KEY_UP},+ {"ArrowDown", KEY_DOWN},+ {"ArrowLeft", KEY_LEFT},+ {"ArrowRight", KEY_RIGHT},+ {"ShiftLeft", KEY_LEFTSHIFT},+ {"ControlLeft", KEY_LEFTCTRL},+ {"AltLeft", KEY_LEFTALT},+ {"MetaLeft", KEY_LEFTMETA},+ {"Minus", KEY_MINUS},+ {"Equal", KEY_EQUAL},+ {"BracketLeft", KEY_LEFTBRACE},+ {"BracketRight", KEY_RIGHTBRACE},+ {"Backslash", KEY_BACKSLASH},+ {"Semicolon", KEY_SEMICOLON},+ {"Quote", KEY_APOSTROPHE},+ {"Backquote", KEY_GRAVE},+ {"Comma", KEY_COMMA},+ {"Period", KEY_DOT},+ {"Slash", KEY_SLASH},+ };+ for (size_t i = 0; i < sizeof(map) / sizeof(map[0]); i++)+ if (!strcmp(name, map[i].name))+ return map[i].code;+ return -1;+}+static const char *string(json_object *object, const char *name) {+ json_object *value;+ if (!json_object_object_get_ex(object, name, &value) ||+ !json_object_is_type(value, json_type_string))+ return NULL;+ const char *text = json_object_get_string(value);+ return strlen(text) == (size_t)json_object_get_string_len(value) ? text+ : NULL;+}+static bool number(json_object *object, const char *name, double min,+ double max, double *out) {+ json_object *value;+ if (!json_object_object_get_ex(object, name, &value) ||+ (!json_object_is_type(value, json_type_int) &&+ !json_object_is_type(value, json_type_double)))+ return false;+ *out = json_object_get_double(value);+ return isfinite(*out) && *out >= min && *out <= max;+}+static bool boolean(json_object *object, const char *name, bool *out) {+ json_object *value;+ if (!json_object_object_get_ex(object, name, &value) ||+ !json_object_is_type(value, json_type_boolean))+ return false;+ *out = json_object_get_boolean(value);+ return true;+}+// JSON parser validates UTF-8 before this decoder is used.+static uint32_t codepoint(const unsigned char **cursor) {+ const unsigned char *p = *cursor;+ uint32_t c = *p++;+ int rest = c < 0x80 ? 0 : c < 0xe0 ? 1 : c < 0xf0 ? 2 : 3;+ if (rest)+ c &= (1u << (6 - rest)) - 1;+ while (rest--)+ c = (c << 6) | (*p++ & 63);+ *cursor = p;+ return c;+}+static bool text_input(const char *text) {+ if (!*text)+ return true;+ release_all(); // Text commits are not keyboard shortcuts; never leave+ // modifiers held.+ uint32_t syms[4096];+ size_t count = 0;+ const unsigned char *p = (const unsigned char *)text;+ while (*p && count < 4096) {+ uint32_t c = codepoint(&p);+ syms[count++] = c == '\n' || c == '\r' ? XKB_KEY_Return+ : c == '\t' ? XKB_KEY_Tab+ : xkb_utf32_to_keysym(c);+ }+ if (*p)+ return false;+ bool ok = true;+ // A separate keyboard gives each layout a distinct compositor identity.+ // Replacing a keymap on the active physical-key device can leave clients+ // translating subsequent shortcuts with the previous text-only map.+ // Restrict text to ordinary digit/letter scan codes: clients may dispatch+ // multimedia shortcuts by scan code even when the keysym is printable.+ static const uint32_t text_codes[] = {+ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 22, 23,+ 24, 25, 30, 31, 32, 33, 34, 35, 36, 37, 38, 44, 45, 46, 47, 48, 49, 50};+ const size_t capacity = sizeof(text_codes) / sizeof(text_codes[0]);+ for (size_t offset = 0; offset < count && ok && !stopping;+ offset += capacity) {+ size_t chunk = count - offset < capacity ? count - offset : capacity;+ char *map = NULL;+ size_t length = 0;+ FILE *f = open_memstream(&map, &length);+ if (!f)+ return false;+ fprintf(f, "xkb_keymap { xkb_keycodes { minimum=8; maximum=58;");+ for (size_t i = 0; i < chunk; i++)+ fprintf(f, "<T%03zx>=%u;", i, text_codes[i] + 8);+ fprintf(f, "}; xkb_types { type \"ONE_LEVEL\" { modifiers=None; "+ "map[None]=Level1; }; }; xkb_compatibility {}; xkb_symbols {");+ for (size_t i = 0; i < chunk; i++)+ fprintf(f, "key <T%03zx> { type=\"ONE_LEVEL\", [ 0x%x ] };", i,+ syms[offset + i]);+ fprintf(f, "}; };");+ fclose(f);+ struct zwp_virtual_keyboard_v1 *text_keyboard =+ zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(+ keyboard_manager, seat);+ ok = set_keymap(text_keyboard, map);+ free(map);+ if (ok) {+ zwp_virtual_keyboard_v1_modifiers(text_keyboard, 0, 0, 0, 0);+ for (size_t i = 0; i < chunk && !stopping; i++) {+ zwp_virtual_keyboard_v1_key(text_keyboard, now(), text_codes[i], 1);+ if (wl_display_roundtrip(display) < 0) {+ ok = false;+ break;+ }+ // Give the focused client/IME time to consume each edge (as wtype+ // does); flooding key pairs silently loses text in Chromium.+ struct timespec pace = {.tv_nsec = 2000000};+ nanosleep(&pace, NULL);+ zwp_virtual_keyboard_v1_key(text_keyboard, now(), text_codes[i], 0);+ if (wl_display_roundtrip(display) < 0) {+ ok = false;+ break;+ }+ nanosleep(&pace, NULL);+ }+ ok = wl_display_roundtrip(display) >= 0 && ok;+ }+ zwp_virtual_keyboard_v1_destroy(text_keyboard);+ if (wl_display_roundtrip(display) < 0)+ ok = false;+ }+ modifiers();+ return ok;+}++static bool event(json_object *object, bool apply) {+ if (!json_object_is_type(object, json_type_object))+ return false;+ const char *kind = string(object, "kind");+ if (!kind)+ return false;+ double x = 0, y = 0, button = 0;+ bool down = false;+ if (!strcmp(kind, "release")) {+ if (apply)+ release_all();+ return true;+ }+ if (!strcmp(kind, "move") || !strcmp(kind, "button")) {+ if (!number(object, "x", 0, 1, &x) || !number(object, "y", 0, 1, &y))+ return false;+ bool click = !strcmp(kind, "button");+ if (click && (!number(object, "button", 0, 2, &button) ||+ button != floor(button) || !boolean(object, "down", &down)))+ return false;+ if (apply) {+ zwlr_virtual_pointer_v1_motion_absolute(+ pointer, now(), (uint32_t)llround(x * 1000000),+ (uint32_t)llround(y * 1000000), 1000000, 1000000);+ if (click) {+ // Deliver absolute motion before the button, so a first tap targets+ // its requested surface instead of the previously focused surface.+ zwlr_virtual_pointer_v1_frame(pointer);+ if (wl_display_roundtrip(display) < 0)+ return false;+ buttons[(int)button] = down;+ zwlr_virtual_pointer_v1_button(pointer, now(),+ button_codes[(int)button], down);+ }+ zwlr_virtual_pointer_v1_frame(pointer);+ }+ return true;+ }+ if (!strcmp(kind, "scroll")) {+ if (!number(object, "dx", -2000, 2000, &x) ||+ !number(object, "dy", -2000, 2000, &y))+ return false;+ if (apply) {+ zwlr_virtual_pointer_v1_axis_source(pointer,+ WL_POINTER_AXIS_SOURCE_CONTINUOUS);+ if (x)+ zwlr_virtual_pointer_v1_axis(pointer, now(),+ WL_POINTER_AXIS_HORIZONTAL_SCROLL,+ wl_fixed_from_double(x));+ if (y)+ zwlr_virtual_pointer_v1_axis(pointer, now(),+ WL_POINTER_AXIS_VERTICAL_SCROLL,+ wl_fixed_from_double(y));+ zwlr_virtual_pointer_v1_frame(pointer);+ }+ return true;+ }+ if (!strcmp(kind, "key")) {+ const char *code = string(object, "code");+ int mapped = code ? key_code(code) : -1;+ if (mapped < 0 || !boolean(object, "down", &down))+ return false;+ if (apply)+ key((uint32_t)mapped, down);+ return true;+ }+ if (!strcmp(kind, "text")) {+ const char *text = string(object, "text");+ if (!text || strlen(text) > 16384)+ return false;+ const unsigned char *p = (const unsigned char *)text;+ size_t count = 0;+ while (*p) {+ codepoint(&p);+ if (++count > 4096)+ return false;+ }+ return !apply || text_input(text);+ }+ return false;+}+static bool batch(const char *line, size_t size, bool apply) {+ struct json_tokener *tok = json_tokener_new();+ if (!tok)+ return false;+ json_tokener_set_flags(tok, JSON_TOKENER_STRICT | JSON_TOKENER_VALIDATE_UTF8);+ json_object *array = json_tokener_parse_ex(tok, line, (int)size);+ bool ok = json_tokener_get_error(tok) == json_tokener_success &&+ json_tokener_get_parse_end(tok) == size && array &&+ json_object_is_type(array, json_type_array) &&+ json_object_array_length(array) <= 256;+ json_tokener_free(tok);+ if (ok)+ for (size_t i = 0; i < json_object_array_length(array); i++)+ if (!event(json_object_array_get_idx(array, i), false)) {+ ok = false;+ break;+ }+ if (ok && apply)+ for (size_t i = 0; i < json_object_array_length(array) && !stopping; i++)+ if (!event(json_object_array_get_idx(array, i), true)) {+ ok = false;+ break;+ }+ if (array)+ json_object_put(array);+ return ok;+}+int main(int argc, char **argv) {+ bool check = argc == 2 && !strcmp(argv[1], "--check");+ bool validate = argc == 2 && !strcmp(argv[1], "--validate");+ if (argc > 1 && !check && !validate)+ return 2;+ signal(SIGTERM, interrupted);+ signal(SIGINT, interrupted);+ signal(SIGPIPE, SIG_IGN);+ // Also bound Wayland roundtrips if the compositor or parent stalls.+ signal(SIGALRM, interrupted);+ alarm(6);+ if (!validate) {+ display = wl_display_connect(NULL);+ if (!display)+ return 2;+ struct wl_registry *registry = wl_display_get_registry(display);+ wl_registry_add_listener(registry, ®istry_listener, NULL);+ if (wl_display_roundtrip(display) < 0 || !seat || !keyboard_manager ||+ !pointer_manager)+ return 2;+ if (check) {+ puts("ready");+ wl_display_disconnect(display);+ return 0;+ }+ struct xkb_context *ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);+ struct xkb_rule_names names = {.layout = "us"};+ keymap =+ xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);+ xkb_context_unref(ctx);+ if (!keymap)+ return 2;+ state = xkb_state_new(keymap);+ if (!state)+ return 2;+ keyboard = zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(+ keyboard_manager, seat);+ pointer = zwlr_virtual_pointer_manager_v1_create_virtual_pointer(+ pointer_manager, NULL);+ char *map = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1);+ if (!map || !set_keymap(keyboard, map))+ return 2;+ free(map);+ modifiers();+ if (wl_display_roundtrip(display) < 0)+ return 2;+ }+ puts("ready");+ fflush(stdout);+ char buffer[32769];+ size_t used = 0;+ bool ok = true;+ while (!stopping) {+ struct pollfd fds[2] = {+ {STDIN_FILENO, POLLIN, 0},+ {validate ? -1 : wl_display_get_fd(display), POLLIN, 0}};+ int polled = poll(fds, 2, 6000);+ if (polled <= 0)+ break;+ if (fds[1].revents && wl_display_dispatch(display) < 0)+ break;+ if (!(fds[0].revents & (POLLIN | POLLHUP)))+ continue;+ ssize_t n = read(STDIN_FILENO, buffer + used, 32768 - used);+ if (n <= 0)+ break;+ used += (size_t)n;+ buffer[used] = 0;+ char *newline;+ while ((newline = memchr(buffer, '\n', used))) {+ size_t length = (size_t)(newline - buffer);+ if (!batch(buffer, length, !validate)) {+ ok = false;+ stopping = 1;+ break;+ }+ if (!validate && wl_display_roundtrip(display) < 0) {+ ok = false;+ stopping = 1;+ break;+ }+ puts("ok");+ fflush(stdout);+ alarm(6);+ size_t remaining = used - length - 1;+ memmove(buffer, newline + 1, remaining);+ used = remaining;+ }+ if (used == 32768) {+ ok = false;+ break;+ }+ }+ if (!validate) {+ release_all();+ // Wait for releases to be processed before removing virtual devices.+ wl_display_roundtrip(display);+ zwp_virtual_keyboard_v1_destroy(keyboard);+ zwlr_virtual_pointer_v1_destroy(pointer);+ wl_display_flush(display);+ wl_display_disconnect(display);+ xkb_state_unref(state);+ xkb_keymap_unref(keymap);+ }+ return ok ? 0 : 2;+}diff --git a/apps/desktop/native/remote-desktop/linux-input/test.mjs b/apps/desktop/native/remote-desktop/linux-input/test.mjsnew file mode 100644index 0000000000..c1189210c5--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-input/test.mjs@@ -0,0 +1,102 @@+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import test from 'node:test';++// Explicit native integration check: requires build dependencies, never connects+// to the compositor or injects input. Unit tests cover the main-process adapter.+test('native input rejects invalid batches before applying any event', () => {+ const output = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-input-test-'));+ try {+ const build = spawnSync(+ process.execPath,+ [fileURLToPath(new URL('./build.mjs', import.meta.url)), output],+ { encoding: 'utf8', timeout: 60000 },+ );+ assert.equal(build.status, 0, build.stderr);+ const run = (input) =>+ spawnSync(path.join(output, 'cindy-linux-desktop-input'), ['--validate'], {+ input,+ encoding: 'utf8',+ timeout: 8000,+ });+ const codes = [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']+ .map((c) => 'Key' + c)+ .concat(+ [...'0123456789'].map((c) => 'Digit' + c),+ Array.from({ length: 12 }, (_, i) => 'F' + (i + 1)),+ [+ 'Enter',+ 'Escape',+ 'Tab',+ 'Space',+ 'Backspace',+ 'Delete',+ 'Insert',+ 'Home',+ 'End',+ 'PageUp',+ 'PageDown',+ 'ArrowUp',+ 'ArrowDown',+ 'ArrowLeft',+ 'ArrowRight',+ 'ShiftLeft',+ 'ControlLeft',+ 'AltLeft',+ 'MetaLeft',+ 'Minus',+ 'Equal',+ 'BracketLeft',+ 'BracketRight',+ 'Backslash',+ 'Semicolon',+ 'Quote',+ 'Backquote',+ 'Comma',+ 'Period',+ 'Slash',+ ],+ );+ const accepted = run(+ JSON.stringify([+ ...codes.map((code) => ({ kind: 'key', code, down: true })),+ { kind: 'move', x: 0.25, y: 0.75 },+ { kind: 'button', button: 2, down: true, x: 0, y: 1 },+ { kind: 'scroll', dx: -2000, dy: 2000 },+ { kind: 'text', text: '中文🙂\n' },+ { kind: 'release' },+ ]) + '\n[]\n',+ );+ assert.equal(accepted.status, 0, accepted.stderr);+ assert.equal(accepted.stdout, 'ready\nok\nok\n');+ for (const events of [+ [{ kind: 'move', x: -1, y: 0 }],+ [{ kind: 'key', code: 'Unknown', down: true }],+ [{ kind: 'key', code: 'KeyA', down: 'true' }],+ [{ kind: 'button', button: 1.5, down: true, x: 0, y: 0 }],+ [{ kind: 'scroll', dx: 0, dy: 2001 }],+ [{ kind: 'text', text: 'x'.repeat(4097) }],+ [{ kind: 'text', text: 'embedded\0null' }],+ Array(257).fill({ kind: 'release' }),+ ]) {+ const result = run(JSON.stringify([{ kind: 'release' }, ...events]) + '\n');+ assert.equal(result.status, 2);+ assert.equal(result.stdout, 'ready\n');+ }+ for (const input of [+ '[] trailing\n',+ '[',+ 'x'.repeat(32768),+ Buffer.from([91, 34, 255, 34, 93, 10]),+ ]) {+ const result = run(input);+ assert.notEqual(result.stdout, 'ready\nok\n');+ }+ } finally {+ fs.rmSync(output, { recursive: true, force: true });+ }+});diff --git a/apps/desktop/native/remote-desktop/linux-input/virtual-keyboard-unstable-v1.xml b/apps/desktop/native/remote-desktop/linux-input/virtual-keyboard-unstable-v1.xmlnew file mode 100644index 0000000000..5095c91b81--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-input/virtual-keyboard-unstable-v1.xml@@ -0,0 +1,113 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="virtual_keyboard_unstable_v1">+ <copyright>+ Copyright © 2008-2011 Kristian Høgsberg+ Copyright © 2010-2013 Intel Corporation+ Copyright © 2012-2013 Collabora, Ltd.+ Copyright © 2018 Purism SPC++ Permission is hereby granted, free of charge, to any person obtaining a+ copy of this software and associated documentation files (the "Software"),+ to deal in the Software without restriction, including without limitation+ the rights to use, copy, modify, merge, publish, distribute, sublicense,+ and/or sell copies of the Software, and to permit persons to whom the+ Software is furnished to do so, subject to the following conditions:++ The above copyright notice and this permission notice (including the next+ paragraph) shall be included in all copies or substantial portions of the+ Software.++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+ DEALINGS IN THE SOFTWARE.+ </copyright>++ <interface name="zwp_virtual_keyboard_v1" version="1">+ <description summary="virtual keyboard">+ The virtual keyboard provides an application with requests which emulate+ the behaviour of a physical keyboard.++ This interface can be used by clients on its own to provide raw input+ events, or it can accompany the input method protocol.+ </description>++ <request name="keymap">+ <description summary="keyboard mapping">+ Provide a file descriptor to the compositor which can be+ memory-mapped to provide a keyboard mapping description.++ Format carries a value from the keymap_format enumeration.+ </description>+ <arg name="format" type="uint" summary="keymap format"/>+ <arg name="fd" type="fd" summary="keymap file descriptor"/>+ <arg name="size" type="uint" summary="keymap size, in bytes"/>+ </request>++ <enum name="error">+ <entry name="no_keymap" value="0" summary="No keymap was set"/>+ </enum>++ <request name="key">+ <description summary="key event">+ A key was pressed or released.+ The time argument is a timestamp with millisecond granularity, with an+ undefined base. All requests regarding a single object must share the+ same clock.++ Keymap must be set before issuing this request.++ State carries a value from the key_state enumeration.+ </description>+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>+ <arg name="key" type="uint" summary="key that produced the event"/>+ <arg name="state" type="uint" summary="physical state of the key"/>+ </request>++ <request name="modifiers">+ <description summary="modifier and group state">+ Notifies the compositor that the modifier and/or group state has+ changed, and it should update state.++ The client should use wl_keyboard.modifiers event to synchronize its+ internal state with seat state.++ Keymap must be set before issuing this request.+ </description>+ <arg name="mods_depressed" type="uint" summary="depressed modifiers"/>+ <arg name="mods_latched" type="uint" summary="latched modifiers"/>+ <arg name="mods_locked" type="uint" summary="locked modifiers"/>+ <arg name="group" type="uint" summary="keyboard layout"/>+ </request>++ <request name="destroy" type="destructor" since="1">+ <description summary="destroy the virtual keyboard keyboard object"/>+ </request>+ </interface>++ <interface name="zwp_virtual_keyboard_manager_v1" version="1">+ <description summary="virtual keyboard manager">+ A virtual keyboard manager allows an application to provide keyboard+ input events as if they came from a physical keyboard.+ </description>++ <enum name="error">+ <entry name="unauthorized" value="0" summary="client not authorized to use the interface"/>+ </enum>++ <request name="create_virtual_keyboard">+ <description summary="Create a new virtual keyboard">+ Creates a new virtual keyboard associated to a seat.++ If the compositor enables a keyboard to perform arbitrary actions, it+ should present an error when an untrusted client requests a new+ keyboard.+ </description>+ <arg name="seat" type="object" interface="wl_seat"/>+ <arg name="id" type="new_id" interface="zwp_virtual_keyboard_v1"/>+ </request>+ </interface>+</protocol>diff --git a/apps/desktop/native/remote-desktop/linux-input/wlr-virtual-pointer-unstable-v1.xml b/apps/desktop/native/remote-desktop/linux-input/wlr-virtual-pointer-unstable-v1.xmlnew file mode 100644index 0000000000..ea243e7c80--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-input/wlr-virtual-pointer-unstable-v1.xml@@ -0,0 +1,152 @@+<?xml version="1.0" encoding="UTF-8"?>+<protocol name="wlr_virtual_pointer_unstable_v1">+ <copyright>+ Copyright © 2019 Josef Gajdusek++ Permission is hereby granted, free of charge, to any person obtaining a+ copy of this software and associated documentation files (the "Software"),+ to deal in the Software without restriction, including without limitation+ the rights to use, copy, modify, merge, publish, distribute, sublicense,+ and/or sell copies of the Software, and to permit persons to whom the+ Software is furnished to do so, subject to the following conditions:++ The above copyright notice and this permission notice (including the next+ paragraph) shall be included in all copies or substantial portions of the+ Software.++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+ DEALINGS IN THE SOFTWARE.+ </copyright>++ <interface name="zwlr_virtual_pointer_v1" version="2">+ <description summary="virtual pointer">+ This protocol allows clients to emulate a physical pointer device. The+ requests are mostly mirror opposites of those specified in wl_pointer.+ </description>++ <enum name="error">+ <entry name="invalid_axis" value="0"+ summary="client sent invalid axis enumeration value" />+ <entry name="invalid_axis_source" value="1"+ summary="client sent invalid axis source enumeration value" />+ </enum>++ <request name="motion">+ <description summary="pointer relative motion event">+ The pointer has moved by a relative amount to the previous request.++ Values are in the global compositor space.+ </description>+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>+ <arg name="dx" type="fixed" summary="displacement on the x-axis"/>+ <arg name="dy" type="fixed" summary="displacement on the y-axis"/>+ </request>++ <request name="motion_absolute">+ <description summary="pointer absolute motion event">+ The pointer has moved in an absolute coordinate frame.++ Value of x can range from 0 to x_extent, value of y can range from 0+ to y_extent.+ </description>+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>+ <arg name="x" type="uint" summary="position on the x-axis"/>+ <arg name="y" type="uint" summary="position on the y-axis"/>+ <arg name="x_extent" type="uint" summary="extent of the x-axis"/>+ <arg name="y_extent" type="uint" summary="extent of the y-axis"/>+ </request>++ <request name="button">+ <description summary="button event">+ A button was pressed or released.+ </description>+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>+ <arg name="button" type="uint" summary="button that produced the event"/>+ <arg name="state" type="uint" enum="wl_pointer.button_state" summary="physical state of the button"/>+ </request>++ <request name="axis">+ <description summary="axis event">+ Scroll and other axis requests.+ </description>+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>+ <arg name="axis" type="uint" enum="wl_pointer.axis" summary="axis type"/>+ <arg name="value" type="fixed" summary="length of vector in touchpad coordinates"/>+ </request>++ <request name="frame">+ <description summary="end of a pointer event sequence">+ Indicates the set of events that logically belong together.+ </description>+ </request>++ <request name="axis_source">+ <description summary="axis source event">+ Source information for scroll and other axis.+ </description>+ <arg name="axis_source" type="uint" enum="wl_pointer.axis_source" summary="source of the axis event"/>+ </request>++ <request name="axis_stop">+ <description summary="axis stop event">+ Stop notification for scroll and other axes.+ </description>+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>+ <arg name="axis" type="uint" enum="wl_pointer.axis" summary="the axis stopped with this event"/>+ </request>++ <request name="axis_discrete">+ <description summary="axis click event">+ Discrete step information for scroll and other axes.++ This event allows the client to extend data normally sent using the axis+ event with discrete value.+ </description>+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>+ <arg name="axis" type="uint" enum="wl_pointer.axis" summary="axis type"/>+ <arg name="value" type="fixed" summary="length of vector in touchpad coordinates"/>+ <arg name="discrete" type="int" summary="number of steps"/>+ </request>++ <request name="destroy" type="destructor" since="1">+ <description summary="destroy the virtual pointer object"/>+ </request>+ </interface>++ <interface name="zwlr_virtual_pointer_manager_v1" version="2">+ <description summary="virtual pointer manager">+ This object allows clients to create individual virtual pointer objects.+ </description>++ <request name="create_virtual_pointer">+ <description summary="Create a new virtual pointer">+ Creates a new virtual pointer. The optional seat is a suggestion to the+ compositor.+ </description>+ <arg name="seat" type="object" interface="wl_seat" allow-null="true"/>+ <arg name="id" type="new_id" interface="zwlr_virtual_pointer_v1"/>+ </request>++ <request name="destroy" type="destructor" since="1">+ <description summary="destroy the virtual pointer manager"/>+ </request>++ <!-- Version 2 additions -->+ <request name="create_virtual_pointer_with_output" since="2">+ <description summary="Create a new virtual pointer">+ Creates a new virtual pointer. The seat and the output arguments are+ optional. If the seat argument is set, the compositor should assign the+ input device to the requested seat. If the output argument is set, the+ compositor should map the input device to the requested output.+ </description>+ <arg name="seat" type="object" interface="wl_seat" allow-null="true"/>+ <arg name="output" type="object" interface="wl_output" allow-null="true"/>+ <arg name="id" type="new_id" interface="zwlr_virtual_pointer_v1"/>+ </request>+ </interface>+</protocol>diff --git a/apps/desktop/native/remote-desktop/linux-viewer-display.py b/apps/desktop/native/remote-desktop/linux-viewer-display.pynew file mode 100644index 0000000000..b46b526f61--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-viewer-display.py@@ -0,0 +1,175 @@+#!/usr/bin/python3+"""One lease's temporary Hyprland mirror; restore on EOF, timeout or termination.++No config files, shell evaluation, screenshots, credentials or persisted geometry.+The child outlives a crashing Electron parent long enough to undo its own changes.+"""+import json+import os+import re+import select+import signal+import subprocess+import sys+import time+import uuid+++def command(*args):+ result = subprocess.run(["/usr/bin/hyprctl", *args], capture_output=True,+ timeout=3, check=True, text=True)+ if len(result.stdout) > 128000:+ raise RuntimeError("response too large")+ return result.stdout+++class ViewerDisplay:+ """Own only the generated output and the source's temporary mirror rule."""+ def __init__(self, source, run=command):+ if not re.fullmatch(r"[A-Za-z0-9_.-]{1,80}", source):+ raise ValueError("invalid source")+ self.run = run+ self.source = source+ self.name = "CindyRemote-" + uuid.uuid4().hex[:16]+ self.original = None+ self.created = False+ self.mirrored = False+ try:+ self.lua = self.run("eval", 'assert(type(hl.monitor) == "function")').strip() == "ok"+ except Exception:+ self.lua = False++ def monitors(self):+ return json.loads(self.run("-j", "monitors", "all"))++ def rule(self, monitor, mirror=None):+ value = (f"{monitor['name']},{monitor['width']}x{monitor['height']}@{monitor['refreshRate']},"+ f"{monitor['x']}x{monitor['y']},{monitor['scale']},transform,{monitor['transform']}")+ if mirror:+ value += f",mirror,{mirror}"+ if "vrr" in monitor:+ value += ",vrr," + ("1" if monitor["vrr"] else "0")+ if self.lua:+ # Every string here is an enumerated/validated output or a generated+ # numeric mode. No remote code or arbitrary Lua is accepted.+ fields = {"output": monitor["name"], "mode": f"{monitor['width']}x{monitor['height']}@{monitor['refreshRate']}",+ "position": f"{monitor['x']}x{monitor['y']}", "scale": monitor["scale"],+ "transform": monitor["transform"], "mirror": mirror or ""}+ # hl.monitor merges an existing named rule. Omit unrelated color,+ # HDR and VRR fields so a temporary mirror never replaces them.+ code = "hl.monitor({" + ",".join(k + "=" + json.dumps(v) for k, v in fields.items()) + "})"+ result = self.run("eval", code)+ else:+ result = self.run("keyword", "monitor", value)+ if result.strip() != "ok":+ raise RuntimeError("monitor rejected")++ def move_workspaces(self, source, target):+ workspaces = json.loads(self.run("-j", "workspaces"))+ if len(workspaces) > 128:+ raise RuntimeError("too many workspaces")+ for workspace in workspaces:+ ident = workspace.get("id")+ if workspace.get("monitor") == source and isinstance(ident, int) and ident > 0:+ if self.lua:+ result = self.run("eval", f"hl.dispatch(hl.dsp.workspace.move({{workspace={ident},monitor={json.dumps(target)}}}))")+ else:+ result = self.run("dispatch", "moveworkspacetomonitor", f"{ident} {target}")+ if result.strip() != "ok":+ raise RuntimeError("workspace rejected")++ def resize(self, width, height):+ if (type(width) is not int or type(height) is not int or+ not 320 <= width <= 4096 or not 320 <= height <= 4096 or width * height > 8388608):+ raise ValueError("invalid dimensions")+ if self.original is None:+ self.original = next(m for m in self.monitors() if m["name"] == self.source)+ if self.original.get("mirrorOf", "none") != "none" or self.original.get("specialWorkspace", {}).get("id", 0):+ raise RuntimeError("source unavailable")+ if not self.created:+ # Record intent before invoking the compositor: an interrupted reply+ # must still remove this unique output during cleanup.+ self.created = True+ if self.run("output", "create", "headless", self.name).strip() != "ok":+ raise RuntimeError("output rejected")+ monitors = self.monitors()+ right = max(m["x"] + round((m["height"] if m["transform"] % 2 else m["width"]) / m["scale"])+ for m in monitors if m["name"] != self.name)+ self.rule({"name": self.name, "width": width, "height": height, "refreshRate": 60,+ "x": right, "y": 0, "scale": 1, "transform": 0})+ if not self.mirrored:+ self.move_workspaces(self.source, self.name)+ self.mirrored = True+ self.rule(self.original, self.name)+ for _ in range(40):+ monitor = next((m for m in self.monitors() if m["name"] == self.name), None)+ if monitor and monitor["width"] == width and monitor["height"] == height:+ return {"id": "hyprland:" + self.name, "name": self.name, "width": width, "height": height}+ time.sleep(0.05)+ raise RuntimeError("output did not settle")++ def restore(self):+ if not self.created:+ return+ monitors = self.monitors()+ if any(m["name"] == self.source for m in monitors):+ if self.mirrored:+ self.rule(self.original)+ self.mirrored = False+ self.move_workspaces(self.name, self.source)+ if any(m["name"] == self.name for m in monitors):+ if self.run("output", "remove", self.name).strip() != "ok":+ raise RuntimeError("output removal rejected")+ self.created = False+++def main():+ if len(sys.argv) != 2:+ return 2+ owner = ViewerDisplay(sys.argv[1])+ def terminate(_signum, _frame):+ raise SystemExit(0)+ signal.signal(signal.SIGTERM, terminate)+ signal.signal(signal.SIGINT, terminate)+ buffer = b""+ try:+ while select.select([sys.stdin], [], [], 6)[0]:+ chunk = os.read(sys.stdin.fileno(), 1024)+ if not chunk:+ break+ buffer += chunk+ if len(buffer) > 8192:+ raise ValueError("input too large")+ while b"\n" in buffer:+ line, buffer = buffer.split(b"\n", 1)+ value = json.loads(line)+ if value.get("op") == "ping":+ continue+ result = owner.resize(value.get("width"), value.get("height"))+ print(json.dumps(result), flush=True)+ except Exception:+ # Diagnostics may contain compositor state. Return a fixed error only.+ try:+ print('{"error":"DESKTOP_VIEWER_DISPLAY_UNAVAILABLE"}', flush=True)+ except BrokenPipeError:+ pass+ finally:+ signal.signal(signal.SIGTERM, signal.SIG_IGN)+ # Keep the in-memory snapshot alive through temporary compositor errors.+ # A vanished compositor socket means its temporary outputs vanished too.+ socket = os.path.join(os.environ.get("XDG_RUNTIME_DIR", ""), "hypr",+ os.environ.get("HYPRLAND_INSTANCE_SIGNATURE", ""), ".socket.sock")+ attempt = 0+ while True:+ try:+ owner.restore()+ return 0+ except Exception:+ if not os.path.exists(socket):+ return 0+ attempt += 1+ time.sleep(min(5, 0.2 * attempt))+++if __name__ == "__main__":+ sys.exit(main())diff --git a/apps/desktop/native/remote-desktop/linux-viewer-display.test.py b/apps/desktop/native/remote-desktop/linux-viewer-display.test.pynew file mode 100644index 0000000000..fcd614003a--- /dev/null+++ b/apps/desktop/native/remote-desktop/linux-viewer-display.test.py@@ -0,0 +1,83 @@+"""No compositor connection: exercise ownership, validation and rollback."""+import copy+import importlib.util+import json+import pathlib+import sys+import unittest++sys.dont_write_bytecode = True+spec = importlib.util.spec_from_file_location(+ "viewer_display", pathlib.Path(__file__).with_name("linux-viewer-display.py"))+module = importlib.util.module_from_spec(spec)+spec.loader.exec_module(module)+++class ViewerDisplayTests(unittest.TestCase):+ def fixture(self):+ source = {"name": "eDP-2", "width": 1600, "height": 1000, "refreshRate": 60,+ "x": 0, "y": 0, "scale": 1, "transform": 0, "mirrorOf": "none"}+ monitors = {source["name"]: source}+ calls = []++ def run(*args):+ calls.append(args)+ if args == ("-j", "monitors", "all"):+ return json.dumps(list(monitors.values()))+ if args == ("-j", "workspaces"):+ return "[]"+ if args[:2] == ("output", "create"):+ monitors[args[-1]] = dict(source, name=args[-1])+ if args[:2] == ("output", "remove"):+ monitors.pop(args[-1], None)+ return "ok"++ owner = module.ViewerDisplay(source["name"], run)++ def rule(value, mirror=None):+ monitors[value["name"]] = dict(value, mirrorOf=mirror or "none")++ owner.rule = rule+ return owner, monitors, calls++ def test_rejects_invalid_sizes_before_mutating_any_output(self):+ owner, _, calls = self.fixture()+ for width, height in [(True, 600), (319, 600), (4096, 4096), (800, "600")]:+ with self.assertRaises(ValueError):+ owner.resize(width, height)+ self.assertFalse(any(c[0] == "output" for c in calls))++ def test_restores_exact_source_and_removes_only_owned_output(self):+ owner, monitors, _ = self.fixture()+ before = copy.deepcopy(monitors)+ result = owner.resize(800, 600)+ self.assertEqual(result["width"], 800)+ self.assertEqual(monitors["eDP-2"]["mirrorOf"], owner.name)+ owner.resize(600, 800)+ owner.restore()+ self.assertEqual(monitors, before)+ owner.restore() # Idempotent cleanup.++ def test_cleanup_keeps_snapshot_after_a_temporary_restore_failure(self):+ owner, monitors, _ = self.fixture()+ owner.resize(800, 600)+ rule = owner.rule+ owner.rule = lambda *_: (_ for _ in ()).throw(RuntimeError("temporary"))+ with self.assertRaises(RuntimeError):+ owner.restore()+ self.assertTrue(owner.created)+ self.assertTrue(owner.mirrored)+ owner.rule = rule+ owner.restore()+ self.assertEqual(set(monitors), {"eDP-2"})++ def test_unplugged_source_does_not_block_owned_output_removal(self):+ owner, monitors, _ = self.fixture()+ owner.resize(800, 600)+ del monitors["eDP-2"]+ owner.restore()+ self.assertFalse(monitors)+++if __name__ == "__main__":+ unittest.main()diff --git a/apps/desktop/src/main/__tests__/devStartupStatus.test.ts b/apps/desktop/src/main/__tests__/devStartupStatus.test.tsindex f556abb28c..1dfcdfe253 100644--- a/apps/desktop/src/main/__tests__/devStartupStatus.test.ts+++ b/apps/desktop/src/main/__tests__/devStartupStatus.test.ts@@ -52,26 +52,25 @@ describe('devStartupStatus', () => {startedAtMs: 100,});- markDesktopDevWindowReady();+ markDesktopDevWindowReady(4343);expect(JSON.parse(fs.readFileSync(statusPath, 'utf8'))).toMatchObject({state: 'window-ready',});- expect(JSON.parse(fs.readFileSync(- path.join(tempDir, '.dev-instances', '4242.json'),- 'utf8',- ))).toMatchObject({ state: 'starting' });+ expect(+ JSON.parse(fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8')),+ ).toMatchObject({ state: 'starting' });markDesktopDevReady();const external = JSON.parse(fs.readFileSync(statusPath, 'utf8'));- const persistent = JSON.parse(fs.readFileSync(- path.join(tempDir, '.dev-instances', '4242.json'),- 'utf8',- ));+ const persistent = JSON.parse(+ fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8'),+ );expect(external).toMatchObject({ state: 'ready', instance: { commit: 'abc123' } });expect(persistent).toMatchObject({state: 'ready',+ rendererPid: 4343,rootDir: path.join(tempDir, 'repo'),mode: 'remote',region: 'cn',@@ -83,25 +82,37 @@ describe('devStartupStatus', () => {const identity = { startedAtMs: 50, executablePath: path.join(tempDir, 'Cindy') };readIdentity.mockResolvedValue(identity);cleanup = await beginDesktopDevInstance({- userDataDir: tempDir, dbFilePrefix: 'cindy', rootDir: tempDir,- passive: false, isolated: false, pid: 4242, startedAtMs: 100,+ userDataDir: tempDir,+ dbFilePrefix: 'cindy',+ rootDir: tempDir,+ passive: false,+ isolated: false,+ pid: 4242,+ startedAtMs: 100,});markDesktopDevWindowReady();markDesktopDevReady();- expect(JSON.parse(fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8')))- .toMatchObject({ processIdentity: identity, startedAtMs: 100, state: 'ready' });+ expect(+ JSON.parse(fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8')),+ ).toMatchObject({ processIdentity: identity, startedAtMs: 100, state: 'ready' });});it('does not delay bootstrap for OS identity and preserves readiness on late enrichment', async () => {const identity = { startedAtMs: 50, executablePath: path.join(tempDir, 'Cindy') };let resolveIdentity!: (value: typeof identity) => void;- const pending = new Promise<typeof identity>((resolve) => { resolveIdentity = resolve; });+ const pending = new Promise<typeof identity>((resolve) => {+ resolveIdentity = resolve;+ });readIdentity.mockReturnValue(pending);// Must settle while the OS query is still pending, before bootstrap can// register its pre-ready protocols. Awaiting the probe here would deadlock.cleanup = await beginDesktopDevInstance({- userDataDir: tempDir, dbFilePrefix: 'cindy', rootDir: tempDir,- passive: false, isolated: false, pid: 4242,+ userDataDir: tempDir,+ dbFilePrefix: 'cindy',+ rootDir: tempDir,+ passive: false,+ isolated: false,+ pid: 4242,});const file = path.join(tempDir, '.dev-instances', '4242.json');expect(JSON.parse(fs.readFileSync(file, 'utf8'))).not.toHaveProperty('processIdentity');@@ -109,17 +120,25 @@ describe('devStartupStatus', () => {markDesktopDevReady();resolveIdentity(identity);await pending;- expect(JSON.parse(fs.readFileSync(file, 'utf8')))- .toMatchObject({ state: 'ready', processIdentity: identity });+ expect(JSON.parse(fs.readFileSync(file, 'utf8'))).toMatchObject({+ state: 'ready',+ processIdentity: identity,+ });});it('does not recreate the registration when an identity query completes after exit', async () => {let resolveIdentity!: (value: { startedAtMs: number; executablePath: string }) => void;- const pending = new Promise<{ startedAtMs: number; executablePath: string }>((resolve) => { resolveIdentity = resolve; });+ const pending = new Promise<{ startedAtMs: number; executablePath: string }>((resolve) => {+ resolveIdentity = resolve;+ });readIdentity.mockReturnValue(pending);cleanup = await beginDesktopDevInstance({- userDataDir: tempDir, dbFilePrefix: 'cindy', rootDir: tempDir,- passive: false, isolated: false, pid: 4242,+ userDataDir: tempDir,+ dbFilePrefix: 'cindy',+ rootDir: tempDir,+ passive: false,+ isolated: false,+ pid: 4242,});cleanup();resolveIdentity({ startedAtMs: 50, executablePath: path.join(tempDir, 'Cindy') });@@ -129,30 +148,50 @@ describe('devStartupStatus', () => {it('does not overwrite a replacement instance with a late identity result', async () => {let resolveIdentity!: (value: { startedAtMs: number; executablePath: string }) => void;- const pending = new Promise<{ startedAtMs: number; executablePath: string }>((resolve) => { resolveIdentity = resolve; });+ const pending = new Promise<{ startedAtMs: number; executablePath: string }>((resolve) => {+ resolveIdentity = resolve;+ });readIdentity.mockReturnValueOnce(pending);const oldCleanup = await beginDesktopDevInstance({- userDataDir: tempDir, dbFilePrefix: 'cindy', rootDir: tempDir,- passive: false, isolated: false, pid: 4242, instanceId: 'old',+ userDataDir: tempDir,+ dbFilePrefix: 'cindy',+ rootDir: tempDir,+ passive: false,+ isolated: false,+ pid: 4242,+ instanceId: 'old',});cleanup = await beginDesktopDevInstance({- userDataDir: tempDir, dbFilePrefix: 'cindy', rootDir: tempDir,- passive: false, isolated: false, pid: 4242, instanceId: 'replacement',+ userDataDir: tempDir,+ dbFilePrefix: 'cindy',+ rootDir: tempDir,+ passive: false,+ isolated: false,+ pid: 4242,+ instanceId: 'replacement',});resolveIdentity({ startedAtMs: 50, executablePath: path.join(tempDir, 'old-Cindy') });await pending;oldCleanup();- const record = JSON.parse(fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8'));+ const record = JSON.parse(+ fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8'),+ );expect(record.instanceId).toBe('replacement');expect(record).not.toHaveProperty('processIdentity');});it('still registers when OS identity is unavailable without inventing an identity', async () => {cleanup = await beginDesktopDevInstance({- userDataDir: tempDir, dbFilePrefix: 'cindy', rootDir: tempDir,- passive: false, isolated: false, pid: 4242,+ userDataDir: tempDir,+ dbFilePrefix: 'cindy',+ rootDir: tempDir,+ passive: false,+ isolated: false,+ pid: 4242,});- const record = JSON.parse(fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8'));+ const record = JSON.parse(+ fs.readFileSync(path.join(tempDir, '.dev-instances', '4242.json'), 'utf8'),+ );expect(record.pid).toBe(4242);expect(record).not.toHaveProperty('processIdentity');});@@ -188,14 +227,15 @@ describe('devStartupStatus', () => {markDesktopDevWindowReady();let settleAuth!: (state: { isAuthenticated: boolean; user: unknown | null }) => void;- const pendingAuth = new Promise<{ isAuthenticated: boolean; user: unknown | null }>((resolve) => {- settleAuth = resolve;- });- recordDesktopDevAuthStartupResult(- { isAuthenticated: false, user: null },- pendingAuth,- () => ({ isAuthenticated: false, user: null }),+ const pendingAuth = new Promise<{ isAuthenticated: boolean; user: unknown | null }>(+ (resolve) => {+ settleAuth = resolve;+ },);+ recordDesktopDevAuthStartupResult({ isAuthenticated: false, user: null }, pendingAuth, () => ({+ isAuthenticated: false,+ user: null,+ }));expect(JSON.parse(fs.readFileSync(statusPath, 'utf8'))).toMatchObject({state: 'window-ready',});@@ -221,11 +261,10 @@ describe('devStartupStatus', () => {// The stale background flow resolves as logged out after authStateEpoch changes,// while authManager's live state already contains the manually logged-in user.const pendingAuth = Promise.resolve({ isAuthenticated: false, user: null });- recordDesktopDevAuthStartupResult(- { isAuthenticated: false, user: null },- pendingAuth,- () => ({ isAuthenticated: true, user: { id: 'manual-user' } }),- );+ recordDesktopDevAuthStartupResult({ isAuthenticated: false, user: null }, pendingAuth, () => ({+ isAuthenticated: true,+ user: { id: 'manual-user' },+ }));await pendingAuth;await Promise.resolve();expect(JSON.parse(fs.readFileSync(statusPath, 'utf8'))).toMatchObject({@@ -265,10 +304,9 @@ describe('devStartupStatus', () => {code: 'SINGLE_INSTANCE_OWNED',detail: { userDataDir: '/tmp/Cindy' },});- expect(JSON.parse(fs.readFileSync(- path.join(tempDir, '.dev-instances', '4243.json'),- 'utf8',- ))).toMatchObject({+ expect(+ JSON.parse(fs.readFileSync(path.join(tempDir, '.dev-instances', '4243.json'), 'utf8')),+ ).toMatchObject({state: 'failed',failure: { code: 'SINGLE_INSTANCE_OWNED' },});@@ -318,10 +356,9 @@ describe('devStartupStatus', () => {markDesktopDevStartupFailed('MIGRATE_FAILED', 'late failure');expect(JSON.parse(fs.readFileSync(statusPath, 'utf8'))).toMatchObject({ state: 'ready' });- expect(JSON.parse(fs.readFileSync(- path.join(tempDir, '.dev-instances', '4246.json'),- 'utf8',- ))).toMatchObject({ state: 'ready' });+ expect(+ JSON.parse(fs.readFileSync(path.join(tempDir, '.dev-instances', '4246.json'), 'utf8')),+ ).toMatchObject({ state: 'ready' });});it('cleanup never deletes a record that has been replaced by another owner', async () => {diff --git a/apps/desktop/src/main/__tests__/sessionDragReleaseNativeHost.test.ts b/apps/desktop/src/main/__tests__/sessionDragReleaseNativeHost.test.tsindex 465d9b863d..63750694a2 100644--- a/apps/desktop/src/main/__tests__/sessionDragReleaseNativeHost.test.ts+++ b/apps/desktop/src/main/__tests__/sessionDragReleaseNativeHost.test.ts@@ -149,8 +149,8 @@ describe('SessionDragReleaseNativeHost', () => {expect(forgeSource).toContain("const MACOS_REMOTE_DESKTOP_INPUT_DEPLOYMENT_TARGET = 'macos10.15';",);- expect(forgeSource).toContain(- "MACOS_REMOTE_DESKTOP_INPUT_DEPLOYMENT_TARGET,\n [],\n 'remote desktop input'",+ expect(forgeSource.replace(/\s+/g, ' ')).toContain(+ "MACOS_REMOTE_DESKTOP_INPUT_DEPLOYMENT_TARGET, [], 'remote desktop input'",);expect(forgeSource).not.toContain("dest, arch, '10.15', [], 'remote desktop input'");expect(swiftTargetTriple('arm64', 'macos10.15')).toBe('arm64-apple-macos10.15');diff --git a/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts b/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.tsindex 26a8938196..3358ac6a89 100644--- a/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts+++ b/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts@@ -30,7 +30,7 @@ function handlerBody(source: string, channel: string, nextChannel: string): stridescribe('session runtime control wiring', () => {it('replays Windows attention after the main window is shown independently of inventory loading', () => {- const body = handlerBody(bootstrapSource, "mainWindow.once('ready-to-show'", 'if (!app.isPackaged) markDesktopDevWindowReady();');+ const body = handlerBody(bootstrapSource, "mainWindow.once('ready-to-show'", 'if (!app.isPackaged) markDesktopDevWindowReady(');expect(body.indexOf('refreshWindowsAppBadge();')).toBeGreaterThan(body.indexOf('showMainWindowAndRestoreFullscreen('));});it('advertises host-side model-window protection to remote controllers', () => {diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.tsindex aa295d6687..f46feceb06 100644--- a/apps/desktop/src/main/bootstrap-electron.ts+++ b/apps/desktop/src/main/bootstrap-electron.ts@@ -3972,7 +3972,7 @@ const createWindow = () => {restoreFullscreen: shouldRestoreMacFullscreen,});refreshWindowsAppBadge();- if (!app.isPackaged) markDesktopDevWindowReady();+ if (!app.isPackaged) markDesktopDevWindowReady(mainWindow.webContents.getOSProcessId());void runComputerUseSmokeIfRequested();// 资源用量窗口不应与主窗口首帧争 CPU。主窗口可见后再后台完成 BrowserWindow、// renderer 和首份进程快照预热;回调绑定当代主窗口,重建/退出后不会创建孤儿窗。diff --git a/apps/desktop/src/main/devStartupStatus.ts b/apps/desktop/src/main/devStartupStatus.tsindex 58e69e82ee..783eb01ad8 100644--- a/apps/desktop/src/main/devStartupStatus.ts+++ b/apps/desktop/src/main/devStartupStatus.ts@@ -5,7 +5,10 @@ import type { CindyRegion } from '@cindy/maker-shared/brand-identity';import type { DevProfileKind } from './devCliFlags.js';import { withLocalProfileMigrationStartupBarrier } from './localProfileDataMigration.js';import { atomicWriteFileSync } from './utils/atomicWriteFile.js';-import { readDesktopProcessIdentity, type DesktopProcessIdentity } from './desktopProcessIdentity.js';+import {+ readDesktopProcessIdentity,+ type DesktopProcessIdentity,+} from './desktopProcessIdentity.js';export type DesktopDevMode = 'remote' | 'local' | 'unknown';export type DesktopDevInstanceState = 'starting' | 'ready' | 'failed';@@ -25,6 +28,8 @@ export interface DesktopDevInstanceRecord {worktreeLeaseProtocol?: 1;instanceId: string;pid: number;+ /** Main reports the actual window renderer; Linux zygote children may retain argv. */+ rendererPid?: number;startedAtMs: number;/** Optional for legacy readers/writers; absence never claims that a PID is stale. */processIdentity?: DesktopProcessIdentity;@@ -78,7 +83,7 @@ function atomicWriteJson(filePath: string, value: unknown): void {function readJson(filePath: string): Record<string, unknown> | null {try {const value = JSON.parse(fs.readFileSync(filePath, 'utf8')) as unknown;- return value !== null && typeof value === 'object' ? value as Record<string, unknown> : null;+ return value !== null && typeof value === 'object' ? (value as Record<string, unknown>) : null;} catch {return null;}@@ -93,9 +98,10 @@ function updateExternalStartupStatus(try {const currentState = readJson(statusPath)?.state;- const canTransition = state === 'window-ready'- ? currentState === 'pending'- : currentState === 'pending' || currentState === 'window-ready';+ const canTransition =+ state === 'window-ready'+ ? currentState === 'pending'+ : currentState === 'pending' || currentState === 'window-ready';if (!canTransition) return;atomicWriteJson(statusPath, { state, pid: process.pid, at: Date.now(), ...detail });} catch {@@ -174,16 +180,18 @@ export async function beginDesktopDevInstance(// schemes before Electron's ready event. Never await an OS subprocess here.// Identity is optional evidence: enrich only the instance we still own, using// its latest readiness state, and never resurrect a record removed on exit.- void readDesktopProcessIdentity(pid).then((identity) => {- const current = trackedInstance;- if (!identity || current?.record.instanceId !== record.instanceId) return;- if (readJson(filePath)?.instanceId !== record.instanceId) return;- const updated = { ...current.record, processIdentity: identity };- atomicWriteJson(filePath, updated);- trackedInstance = { filePath, record: updated };- }).catch(() => {- // Failure to enrich must not affect startup or weaken legacy PID checks.- });+ void readDesktopProcessIdentity(pid)+ .then((identity) => {+ const current = trackedInstance;+ if (!identity || current?.record.instanceId !== record.instanceId) return;+ if (readJson(filePath)?.instanceId !== record.instanceId) return;+ const updated = { ...current.record, processIdentity: identity };+ atomicWriteJson(filePath, updated);+ trackedInstance = { filePath, record: updated };+ })+ .catch(() => {+ // Failure to enrich must not affect startup or weaken legacy PID checks.+ });return () => {if (trackedInstance?.record.instanceId === record.instanceId) trackedInstance = null;@@ -207,8 +215,11 @@ function settleDesktopDevReadyIfPossible(): void {}/** Record that the main BrowserWindow can render, without claiming the database is ready. */-export function markDesktopDevWindowReady(): void {+export function markDesktopDevWindowReady(rendererPid?: number): void {if (startupSettled) return;+ if (trackedInstance && Number.isSafeInteger(rendererPid) && rendererPid! > 0) {+ trackedInstance.record = { ...trackedInstance.record, rendererPid };+ }mainWindowReady = true;updateExternalStartupStatus('window-ready', {instance: trackedInstance?.record ?? null,diff --git a/apps/desktop/src/main/maker-host/__tests__/authAdaptersImportPurity.test.ts b/apps/desktop/src/main/maker-host/__tests__/authAdaptersImportPurity.test.tsindex 982d36c7b5..ffeb3544b4 100644--- a/apps/desktop/src/main/maker-host/__tests__/authAdaptersImportPurity.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/authAdaptersImportPurity.test.ts@@ -32,6 +32,8 @@ vi.mock('electron', () => ({vi.mock('@cindy/maker-core', () => ({}));describe('auth-adapters import purity', () => {+ // Keep the side-effect assertions intact while allowing the full auth graph's+ // cold transform on Linux under the eight-worker desktop unit pool.it('importing the module (and its singletons) must not write to the filesystem', async () => {h.userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xdt-auth-import-purity-'));const cwdCodexHome = path.join(process.cwd(), 'codex-home');@@ -59,5 +61,5 @@ describe('auth-adapters import purity', () => {} finally {fs.rmSync(h.userDataDir, { recursive: true, force: true });}- });+ }, 20_000);});diff --git a/apps/desktop/src/main/maker-host/__tests__/codexAuthInvalidation.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexAuthInvalidation.test.tsindex 28aeabcc86..298dfd8d02 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexAuthInvalidation.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexAuthInvalidation.test.ts@@ -103,6 +103,8 @@ function expectPlatformSharedLink(systemAuth: string, localAuth: string): void {});}+// The first dynamic import transforms the complete auth-adapter graph. On Linux+// the cold transform can exceed the 5s default under the full desktop test pool.it('compares Codex hard-link identities without Windows number precision collisions', async () => {const { haveSameStableFileIdentity } = await import('../auth-adapters.js');expect(@@ -113,7 +115,7 @@ it('compares Codex hard-link identities without Windows number precision collisi).toBe(false);expect(haveSameStableFileIdentity({ dev: 0n, ino: 0n }, { dev: 0n, ino: 0n })).toBe(false);expect(haveSameStableFileIdentity({ dev: 7n, ino: 11n }, { dev: 7n, ino: 11n })).toBe(true);-});+}, 20_000);it.each([false, true])('preserves successful shared login and native files when presentation write fails=%s', async (failPresentation) => {const root = fs.mkdtempSync(path.join(os.tmpdir(), 'xdt-codex-shared-mode-'));diff --git a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.tsindex 03ec766a2a..ebb50bf2b3 100644--- a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts+++ b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts@@ -1,7 +1,16 @@import { afterEach, beforeEach, expect, it, vi } from 'vitest';-import { DESKTOP_LOCAL } from '../../../shared/remoteDesktop';+import { DESKTOP_LOCAL, type DesktopHostCommand } from '../../../shared/remoteDesktop';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),@@ -24,10 +33,48 @@ const h = vi.hoisted(() => ({input: vi.fn(),viewHeartbeat: vi.fn(),hostInput: vi.fn(),+ startInput: vi.fn(async () => {}),iceConfig: vi.fn(async (): Promise<any[]> => [{ urls: ['turn:relay.example.test:3478'], username: 'temporary', credential: 'test-only' },]),}));+vi.mock('../waylandCapture', async (original) => ({+ ...(await original<typeof import('../waylandCapture')>()),+ isWaylandDesktop: () => h.wayland,+}));+vi.mock('../linuxInput', () => ({ readLinuxDesktopInputSupport: async () => h.linuxInput }));+vi.mock('../linuxDesktop', () => ({+ supportsLinuxDisplay: () => h.hyprland,+ supportsLinuxLock: () => false,+ waitForLinuxDisplay: vi.fn(),+ linuxMonitors: async () => [+ { name: 'eDP-2', width: 2560, height: 1600, scale: 1.6, transform: 0 },+ ],+ linuxMonitor: vi.fn(),+ linuxDisplay: () => ({ id: 'hyprland:eDP-2', name: 'eDP-2', width: 1600, height: 1000 }),+}));+vi.mock('../linuxCapture', () => ({ readLinuxCursorSupport: async () => false }));+vi.mock('../linuxAudio', () => ({+ supportsLinuxAudio: () => h.linuxAudio,+ LinuxDesktopAudio: class {+ start = h.audioStart;+ stop = h.audioStop;+ read = h.audioRead;+ },+}));+vi.mock('../linuxMute', () => ({+ supportsLinuxMute: () => false,+ LinuxDesktopMute: class {+ async set() {}+ },+}));+vi.mock('../hyprlandCapture', () => ({+ supportsHyprlandCapture: () => h.hyprland,+ HyprlandCapture: class {+ frame = h.hyprlandFrame;+ stop = h.hyprlandStop;+ },+}));vi.mock('../../lifecycle', () => ({onQuit: (name: string, fn: () => unknown, phase = 'sync') => h.quit.set(name, { fn, phase }),}));@@ -137,6 +184,7 @@ vi.mock('../inputHost', () => ({}stop = vi.fn();input = h.hostInput;+ start = h.startInput;},readDesktopDisplayModes: vi.fn(),setDesktopDisplayMode: vi.fn(),@@ -149,6 +197,9 @@ vi.mock('../permissions', () => ({h.permissionDeps = deps;}dismiss() {}+ async read() {+ return {};+ }},}));vi.mock('../windowsHost', () => ({@@ -184,6 +235,15 @@ const offer = () =>h.deps.offer({ lease: h.lease, display: { id: '1' } }, 'sdp', undefined, false, 'attempt');beforeEach(() => {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);@@ -631,3 +691,211 @@ it('does not advertise or select Windows overlays without a ready native serviceh.handlers.get(DESKTOP_LOCAL.REPLY)(event(), command.id, 'answer');await 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();+ 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';+ select([{ id: 'screen:0:0', display_id: '' }]);+ await flush();+ await rejected;+ expect(callback).toHaveBeenCalledExactlyOnceWith({});+ expect(owner.dead).toBe(true);+});++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;+ owner.send.mockImplementation(() => {+ throw new Error('destroyed');+ });+ await vi.advanceTimersByTimeAsync(18_000);+ await rejected;+ expect(owner.dead).toBe(true);+});++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();+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/clipboard.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/clipboard.test.tsindex 64b066142b..7f75c660a9 100644--- a/apps/desktop/src/main/remote-desktop/__tests__/clipboard.test.ts+++ b/apps/desktop/src/main/remote-desktop/__tests__/clipboard.test.ts@@ -1,4 +1,5 @@import { beforeEach, expect, it, vi } from 'vitest';+vi.mock('../linuxClipboardNative', () => ({ supportsLinuxClipboard: () => false }));const mocks = vi.hoisted(() => ({clipboard: {diff --git a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.tsindex 315dfa854d..2f30ae634a 100644--- a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts+++ b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts@@ -39,6 +39,43 @@ function harness() {controller.request('phone', { op: 'start', displayId: '1' }) as Promise<RemoteDesktopLease>,};}+it('finishes native host setup before exposing a lease or allocating temporary displays', async () => {+ const h = harness();+ let done!: () => void;+ h.deps.prepare = vi.fn(+ () =>+ new Promise<void>((resolve) => {+ done = resolve;+ }),+ );+ const starting = h.start();+ await Promise.resolve();+ expect(h.controller.state).toBeNull();+ done();+ const lease = await starting;+ expect(lease.controlling).toBe(false);+ await h.controller.request('phone', { op: 'start', displayId: '1', resume: true });+ // Resume/takeover must not reload a compositor underneath an active capture.+ expect(h.deps.prepare).toHaveBeenCalledOnce();+});+it('does not allocate a lease after host setup was cancelled', async () => {+ const h = harness();+ let done!: () => void;+ let current!: () => boolean;+ h.deps.prepare = (check) => {+ current = check;+ return new Promise<void>((resolve) => {+ done = resolve;+ });+ };+ const starting = h.start();+ await Promise.resolve();+ await h.controller.stop();+ expect(current()).toBe(false);+ done();+ await expect(starting).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(h.controller.state).toBeNull();+});describe('remote desktop authority and lifecycle', () => {it('registers the returned stop promise with the awaited quit phase', () => {const source = readFileSync(new URL('../index.ts', import.meta.url), 'utf8');@@ -52,17 +89,22 @@ describe('remote desktop authority and lifecycle', () => {const stopAndRestore = vi.fn(() => pending);const dismiss = vi.fn();const clear = vi.fn();- new Function('onQuit', 'clearInterval', 'timer', 'permissions', 'remoteDesktop', registration)(- register,- clear,- 1,- { dismiss },- { stop, stopAndRestore },- );+ const clipboardStop = vi.fn();+ new Function(+ 'stopLinuxClipboardWriter',+ 'onQuit',+ 'clearInterval',+ 'timer',+ 'permissions',+ 'remoteDesktop',+ registration,+ )(clipboardStop, register, clear, 1, { dismiss }, { stop, stopAndRestore });expect(register).toHaveBeenCalledWith('remote-desktop-restore', expect.any(Function), 'async');- register.mock.calls[0][1]();+ register.mock.calls.find(([name]) => name === 'remote-desktop-stop')![1]();expect(stop).toHaveBeenCalledOnce();- expect(register.mock.calls[1][1]()).toBe(pending);+ expect(register.mock.calls.find(([name]) => name === 'remote-desktop-restore')![1]()).toBe(+ pending,+ );expect(clear).toHaveBeenCalledWith(1);expect(dismiss).toHaveBeenCalledOnce();});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/hostCommands.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/hostCommands.test.tsindex 4c8cbc7af7..48befdd309 100644--- a/apps/desktop/src/main/remote-desktop/__tests__/hostCommands.test.ts+++ b/apps/desktop/src/main/remote-desktop/__tests__/hostCommands.test.ts@@ -17,6 +17,8 @@ function harness(sourceText = source) {let reply!: (event: object, id: string, value: unknown) => void;const deps = {host,+ wayland: () => false,+ portalWayland: () => false,stopVideo,parseDesktopIceReply,setTimeout,diff --git a/apps/desktop/src/main/remote-desktop/__tests__/hyprlandCapture.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/hyprlandCapture.test.tsnew file mode 100644index 0000000000..91d6e1535c--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/hyprlandCapture.test.ts@@ -0,0 +1,114 @@+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({+ native: vi.fn(),+ stop: vi.fn(),+ exec: vi.fn(),+ access: vi.fn(),+ wayland: true,+}));+vi.mock('node:child_process', () => ({ execFile: h.exec }));+vi.mock('node:fs', () => ({ accessSync: h.access, constants: { X_OK: 1 } }));+vi.mock('../waylandCapture', () => ({+ WAYLAND_DISPLAY_ID: 'wayland-portal',+ isWaylandDesktop: () => h.wayland,+}));+vi.mock('../nativeCapture', () => ({+ NativeDesktopCapture: class {+ frame = h.native;+ stop = h.stop;+ },+}));+import { HyprlandCapture, supportsHyprlandCapture } from '../hyprlandCapture';+beforeEach(() => {+ h.native.mockReset().mockResolvedValue(null);+ h.stop.mockReset();+ h.exec.mockReset();+ h.access.mockReset();+ h.wayland = true;+ vi.stubEnv('HYPRLAND_INSTANCE_SIGNATURE', 'test');+});+afterEach(() => vi.unstubAllEnvs());+const jpeg = Buffer.from([0xff, 0xd8, 0xff, 0xd9]);+it('requires Hyprland, Wayland and an executable system helper', () => {+ expect(supportsHyprlandCapture()).toBe(true);+ h.wayland = false;+ expect(supportsHyprlandCapture()).toBe(false);+ h.wayland = true;+ vi.stubEnv('HYPRLAND_INSTANCE_SIGNATURE', '');+ expect(supportsHyprlandCapture()).toBe(false);+ vi.stubEnv('HYPRLAND_INSTANCE_SIGNATURE', 'test');+ h.access.mockImplementation(() => {+ throw new Error('missing');+ });+ expect(supportsHyprlandCapture()).toBe(false);+});+it('serializes bounded captures and discards late frames after stop', async () => {+ const capture = new HyprlandCapture();+ const first = capture.frame('wayland-portal');+ await vi.waitFor(() => expect(h.exec).toHaveBeenCalledOnce());+ const [executable, args, options, done] = h.exec.mock.calls[0];+ expect(executable).toBe('/usr/bin/grim');+ expect(args.at(-1)).toBe('-');+ expect(options).toMatchObject({+ timeout: 2500,+ maxBuffer: 8 * 1024 * 1024,+ killSignal: 'SIGKILL',+ });+ await expect(capture.frame('wayland-portal')).resolves.toBeNull();+ capture.stop();+ expect(options.signal.aborted).toBe(true);+ const next = capture.frame('wayland-portal');+ done(null, jpeg);+ await expect(first).resolves.toBeNull();+ await expect(capture.frame('wayland-portal')).resolves.toBeNull();+ h.exec.mock.calls[1][3](null, jpeg);+ await expect(next).resolves.toBe(jpeg.toString('base64'));+});+it('rejects foreign displays, failed helpers and malformed images', async () => {+ const capture = new HyprlandCapture();+ await expect(capture.frame('foreign')).resolves.toBeNull();+ expect(h.exec).not.toHaveBeenCalled();+ h.exec.mockImplementation((_file, _args, _options, done) => done(new Error('denied')));+ await expect(capture.frame('wayland-portal')).resolves.toBeNull();+ h.exec.mockImplementation((_file, _args, _options, done) => done(null, Buffer.from('bad')));+ await expect(capture.frame('wayland-portal')).resolves.toBeNull();+});+it('uses persistent capture without grim and retries unavailable helpers only after stop', async () => {+ const capture = new HyprlandCapture();+ h.native.mockResolvedValue(jpeg.toString('base64'));+ await expect(capture.frame('wayland-portal')).resolves.toBe(jpeg.toString('base64'));+ await capture.frame('wayland-portal');+ expect(h.exec).not.toHaveBeenCalled();+ h.native.mockRejectedValue(new Error('unsupported layout'));+ h.exec.mockImplementation((_file, _args, _options, done) => done(null, jpeg));+ await capture.frame('wayland-portal');+ await capture.frame('wayland-portal');+ expect(h.native).toHaveBeenCalledTimes(3);+ expect(h.exec).toHaveBeenCalledTimes(2);+ capture.stop();+ h.native.mockResolvedValue(jpeg.toString('base64'));+ await capture.frame('wayland-portal');+ expect(h.native).toHaveBeenCalledTimes(4);+ expect(h.exec).toHaveBeenCalledTimes(2);+ capture.stop();+});+it('discards a late persistent frame without poisoning the new lease', async () => {+ const capture = new HyprlandCapture();+ let finish!: (value: string | null) => void;+ h.native.mockImplementationOnce(+ () =>+ new Promise((resolve) => {+ finish = resolve;+ }),+ );+ const first = capture.frame('wayland-portal');+ await expect(capture.frame('wayland-portal')).resolves.toBeNull();+ capture.stop();+ h.native.mockResolvedValue(jpeg.toString('base64'));+ const next = capture.frame('wayland-portal');+ finish(null);+ await expect(first).resolves.toBeNull();+ await expect(next).resolves.toBe(jpeg.toString('base64'));+ expect(h.exec).not.toHaveBeenCalled();+ capture.stop();+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.tsindex bc37d82231..cb7c720255 100644--- a/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts+++ b/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts@@ -355,3 +355,61 @@ describe('native input lifecycle', () => {c.exit();});});++it('keeps Linux whole-desktop coordinates normalized and releases input before returning ownership', async () => {+ vi.useFakeTimers();+ const c = childProcess();+ const host = new DesktopInputHost(vi.fn(), {+ platform: 'linux',+ resolveBinary: async () => '/test/linux-helper',+ spawn: () => {+ queueMicrotask(() => c.child.stdout.emit('data', Buffer.from('ready\n')));+ return c.typed;+ },+ });+ try {+ await expect(host.start('1')).rejects.toThrow('DESKTOP_DISPLAY_MISSING');+ await host.start('wayland-portal');+ const events = [+ { kind: 'move' as const, x: 0.25, y: 0.75 },+ { kind: 'button' as const, button: 0 as const, down: true, x: 0.25, y: 0.75 },+ ];+ host.input(events);+ await flush();+ expect(c.child.stdin.write.mock.calls[0][0]).toBe(JSON.stringify(events) + '\n');+ c.child.stdout.emit('data', Buffer.from('ok\n'));+ await flush();+ host.input([+ { kind: 'text', text: '🙂'.repeat(257) },+ { kind: 'key', code: 'KeyA', down: true },+ { kind: 'key', code: 'KeyA', down: false },+ ]);+ await flush();+ expect(JSON.parse(c.child.stdin.write.mock.calls.at(-1)![0])).toEqual([+ { kind: 'text', text: '🙂'.repeat(256) },+ ]);+ c.child.stdout.emit('data', Buffer.from('ok\n'));+ await flush();+ expect(JSON.parse(c.child.stdin.write.mock.calls.at(-1)![0])).toEqual([+ { kind: 'text', text: '🙂' },+ ]);+ c.child.stdout.emit('data', Buffer.from('ok\n'));+ await flush();+ expect(JSON.parse(c.child.stdin.write.mock.calls.at(-1)![0])).toEqual([+ { kind: 'key', code: 'KeyA', down: true },+ { kind: 'key', code: 'KeyA', down: false },+ ]);+ c.child.stdout.emit('data', Buffer.from('ok\n'));+ await flush();+ const released = host.release();+ expect(c.child.stdin.end).toHaveBeenCalledWith('[{"kind":"release"}]\n');+ await expect(withAgentDesktopInput(async () => {})).rejects.toThrow('input is active');+ c.exit();+ await released;+ expect(() => host.input(events)).toThrow('DESKTOP_INPUT_UNAVAILABLE');+ await expect(withAgentDesktopInput(async () => {})).resolves.toBeUndefined();+ } finally {+ host.stop();+ c.exit();+ }+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxAudio.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxAudio.test.tsnew file mode 100644index 0000000000..9eda47899d--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxAudio.test.ts@@ -0,0 +1,71 @@+import { EventEmitter } from 'node:events';+import { PassThrough } from 'node:stream';+import type { ChildProcessWithoutNullStreams } from 'node:child_process';+import { afterEach, expect, it, vi } from 'vitest';+import { LinuxDesktopAudio } from '../linuxAudio';++function fixture() {+ const child = Object.assign(new EventEmitter(), {+ stdin: new PassThrough(),+ stdout: new PassThrough(),+ stderr: new PassThrough(),+ kill: vi.fn(),+ });+ const capture = new LinuxDesktopAudio(() => child as unknown as ChildProcessWithoutNullStreams);+ return { child, capture };+}+afterEach(() => vi.useRealTimers());++it('retains sample alignment across chunks and bounds history to 100 ms', () => {+ const { child, capture } = fixture();+ try {+ capture.start();+ child.stdout.write(Buffer.from([1, 2, 3]));+ expect(capture.read()).toHaveLength(0);+ child.stdout.write(Buffer.from([4, 5, 6, 7, 8, 9]));+ expect([...capture.read()]).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);+ child.stdout.write(Buffer.alloc(80000, 42));+ expect(capture.read()).toHaveLength(38392);+ child.stdout.write(Buffer.alloc(7, 43));+ expect([...capture.read()]).toEqual([42, 43, 43, 43, 43, 43, 43, 43]);+ } finally {+ capture.stop();+ }+});++it('erases buffered sound on stop and ignores late callbacks', () => {+ const { child, capture } = fixture();+ capture.start();+ child.stdout.write(Buffer.alloc(80));+ capture.stop();+ child.stdout.write(Buffer.alloc(80));+ expect(() => capture.read()).toThrow('DESKTOP_AUDIO_UNAVAILABLE');+ expect(child.kill).toHaveBeenCalledWith('SIGKILL');+});++it('stops a producer when its renderer no longer consumes audio', () => {+ vi.useFakeTimers();+ const { child, capture } = fixture();+ capture.start();+ vi.advanceTimersByTime(4000);+ expect(child.kill).toHaveBeenCalledOnce();+ expect(() => capture.read()).toThrow('DESKTOP_AUDIO_UNAVAILABLE');+});++it('surfaces a native capture failure without exposing native diagnostics', () => {+ const { child, capture } = fixture();+ capture.start();+ child.emit('error', new Error('private native details'));+ expect(() => capture.read()).toThrow('DESKTOP_AUDIO_UNAVAILABLE');+});+it('fails a stalled producer even while the renderer keeps polling', () => {+ vi.useFakeTimers();+ const { child, capture } = fixture();+ capture.start();+ for (let i = 0; i < 6; i++) {+ capture.read();+ vi.advanceTimersByTime(1000);+ }+ expect(child.kill).toHaveBeenCalledOnce();+ expect(() => capture.read()).toThrow('DESKTOP_AUDIO_UNAVAILABLE');+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboard.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboard.test.tsnew file mode 100644index 0000000000..a7771ef058--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboard.test.ts@@ -0,0 +1,37 @@+import { beforeEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({ locked: false, text: 'text', supported: true, read: vi.fn() }));+vi.mock('node:child_process', () => ({ execFile: vi.fn() }));+vi.mock('node:util', () => ({+ promisify: () => async () => ({ stdout: h.locked ? 'yes' : 'no' }),+}));+vi.mock('../linuxDesktop', () => ({ supportsLinuxLock: () => h.supported }));+vi.mock('../linuxClipboardNative', () => ({+ readLinuxClipboardSnapshot: async () => {+ h.read();+ if (h.text.length > 512000) throw new Error('CLIPBOARD_TOO_LONG');+ return { formats: ['text/plain'], content: { text: h.text } };+ },+}));+import { linuxClipboardVersion } from '../linuxClipboard';+beforeEach(() => {+ h.locked = false;+ h.supported = true;+ h.text = 'text';+ h.read.mockClear();+});+it('changes the opaque generation when clipboard contents change', async () => {+ const before = await linuxClipboardVersion();+ expect(await linuxClipboardVersion()).toBe(before);+ expect(before).toMatch(/^[a-f0-9]{64}$/);+ h.text = 'different';+ expect(await linuxClipboardVersion()).not.toBe(before);+});+it('does not read clipboard content while the session is locked', async () => {+ h.locked = true;+ await expect(linuxClipboardVersion()).rejects.toThrow('DESKTOP_CLIPBOARD_UNAVAILABLE');+ expect(h.read).not.toHaveBeenCalled();+});+it('bounds content and returns no sampled text in an error', async () => {+ h.text = 'private'.repeat(100000);+ await expect(linuxClipboardVersion()).rejects.toThrow('CLIPBOARD_TOO_LONG');+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboardNative.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboardNative.test.tsnew file mode 100644index 0000000000..f6d9c632db--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboardNative.test.ts@@ -0,0 +1,48 @@+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({ exec: vi.fn() }));+vi.mock('electron', () => ({ app: {} }));+vi.mock('node:child_process', () => ({ execFile: vi.fn(), spawn: vi.fn() }));+vi.mock('node:util', () => ({ promisify: () => h.exec }));+vi.mock('node:fs', () => ({ accessSync: vi.fn(), constants: { X_OK: 1 } }));+import { readLinuxClipboardSnapshot } from '../linuxClipboardNative';+beforeEach(() => {+ h.exec.mockReset();+ vi.stubGlobal('process', { ...process, platform: 'linux' });+ vi.stubEnv('HYPRLAND_INSTANCE_SIGNATURE', 'test');+});+afterEach(() => {+ vi.unstubAllEnvs();+ vi.unstubAllGlobals();+});+it('reads all offered portable text alternatives while Cindy is unfocused', async () => {+ h.exec.mockImplementation(async (_tool, args: string[]) => ({+ stdout: Buffer.from(+ args.includes('--list-types')+ ? 'text/plain;charset=utf-8\ntext/html\ntext/rtf\n'+ : args.at(-1) === 'text/html'+ ? '<b>Hello</b>'+ : args.at(-1) === 'text/rtf'+ ? '{\\rtf1 Hello}'+ : 'Hello',+ ),+ }));+ expect((await readLinuxClipboardSnapshot()).content).toEqual({+ text: 'Hello',+ html: '<b>Hello</b>',+ rtf: '{\\rtf1 Hello}',+ });+});+it('does not read file-manager paths disguised as text or HTML', async () => {+ h.exec.mockResolvedValue({ stdout: Buffer.from('text/uri-list\ntext/plain\ntext/html\n') });+ expect((await readLinuxClipboardSnapshot()).content).toEqual({});+ expect(h.exec).toHaveBeenCalledOnce();+});+it('does not leak native clipboard diagnostics or confuse refusal with empty selection', async () => {+ h.exec.mockRejectedValue({+ stderr: Buffer.from('secret clipboard diagnostics'),+ stdout: Buffer.from('private text'),+ });+ await expect(readLinuxClipboardSnapshot()).rejects.toThrow('DESKTOP_CLIPBOARD_UNAVAILABLE');+ h.exec.mockRejectedValue({ stderr: Buffer.from('Nothing is copied') });+ expect((await readLinuxClipboardSnapshot()).content).toEqual({});+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboardTransfer.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboardTransfer.test.tsnew file mode 100644index 0000000000..00a0aaea9a--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxClipboardTransfer.test.ts@@ -0,0 +1,57 @@+import { beforeEach, expect, it, vi } from 'vitest';+import type { RemoteClipboardContent } from '@cindy/device-link';+const h = vi.hoisted(() => ({+ content: {} as RemoteClipboardContent,+ write: vi.fn(),+ version: vi.fn(),+}));+vi.mock('electron', () => ({+ clipboard: {},+ nativeImage: { createEmpty: () => ({ isEmpty: () => true }) },+}));+vi.mock('../inputHost', () => ({+ readDesktopSelection: async () => '',+ readDesktopClipboardVersion: h.version,+}));+vi.mock('../linuxClipboardNative', () => ({+ supportsLinuxClipboard: () => true,+ readLinuxClipboardSnapshot: async () => ({+ formats: ['text/plain', 'text/html'],+ content: h.content,+ }),+ writeLinuxClipboard: h.write,+}));+import { transferDesktopClipboardContent } from '../clipboard';+beforeEach(() => {+ h.content = { text: 'hello', html: '<b>hello</b>' };+ h.version.mockReset().mockResolvedValue('version');+ h.write.mockReset().mockImplementation(async (value) => {+ h.content = value;+ });+});+it('copies portable alternatives without consulting Electron clipboard', async () => {+ expect(+ await transferDesktopClipboardContent('copy', undefined, () => true, vi.fn(), { sync: true }),+ ).toEqual(h.content);+});+it('writes all formats and returns the verified generation without typing during sync', async () => {+ const input = vi.fn();+ const content = { text: 'updated', html: '<b>updated</b>', rtf: '{\\rtf1 updated}' };+ expect(+ await transferDesktopClipboardContent('paste', content, () => true, input, { sync: true }),+ ).toEqual({ version: 'version' });+ expect(h.write).toHaveBeenCalledWith(content, expect.any(Function));+ expect(input).not.toHaveBeenCalled();+});+it('does not inject paste after revocation while native writing completes', async () => {+ let current = true;+ h.write.mockImplementation(async (value) => {+ h.content = value;+ current = false;+ });+ const input = vi.fn();+ await expect(+ transferDesktopClipboardContent('paste', { text: 'hello' }, () => current, input),+ ).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(input).toHaveBeenCalledExactlyOnceWith([{ kind: 'release' }]);+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxCredentialHost.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxCredentialHost.test.tsnew file mode 100644index 0000000000..ef65b22edd--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxCredentialHost.test.ts@@ -0,0 +1,63 @@+import { EventEmitter } from 'node:events';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({ spawn: vi.fn(), probe: vi.fn(), command: vi.fn() }));+vi.mock('electron', () => ({ app: { isPackaged: true, getPath: () => '/test-profile' } }));+vi.mock('node:child_process', async (original) => ({+ ...(await original<typeof import('node:child_process')>()),+ spawn: h.spawn,+}));+vi.mock('../linuxCredentials', () => ({+ readLinuxUnlockState: h.probe,+ linuxCredentialCommand: h.command,+}));+import { remoteCredentialHost } from '../credentialHost';++beforeEach(() => {+ vi.stubGlobal(+ 'process',+ Object.defineProperty(Object.create(process), 'platform', { value: 'linux' }),+ );+ h.probe.mockResolvedValue('unavailable');+ h.command.mockReturnValue({ file: '/test-python', args: ['--test-helper'] });+});+afterEach(() => {+ remoteCredentialHost.dispose();+ vi.unstubAllGlobals();+ vi.clearAllMocks();+});++it('rejects unsupported Linux lockers before spawning or accessing identity storage', async () => {+ await expect(+ remoteCredentialHost.configure('global', 'account', 'host', 'test-token'),+ ).rejects.toThrow('CREDENTIAL_UNLOCK_UNAVAILABLE');+ expect(h.spawn).not.toHaveBeenCalled();+});+it('routes Linux configuration through the existing private helper lifecycle', async () => {+ h.probe.mockResolvedValue('locked');+ const stdout = Object.assign(new EventEmitter(), { setEncoding: vi.fn() });+ const child = Object.assign(new EventEmitter(), {+ stdout,+ stderr: { resume: vi.fn() },+ kill: vi.fn(),+ stdin: {+ write: vi.fn((line: string) => {+ const request = JSON.parse(line);+ queueMicrotask(() =>+ stdout.emit(+ 'data',+ JSON.stringify({ id: request.id, result: 'test-public-descriptor' }) + '\n',+ ),+ );+ }),+ },+ });+ h.spawn.mockReturnValue(child);+ await expect(+ remoteCredentialHost.configure('global', 'account', 'host', 'test-token'),+ ).resolves.toBe('test-public-descriptor');+ expect(h.spawn).toHaveBeenCalledWith('/test-python', ['--test-helper'], {+ stdio: ['pipe', 'pipe', 'pipe'],+ });+ remoteCredentialHost.dispose();+ expect(child.kill).toHaveBeenCalledOnce();+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxCredentials.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxCredentials.test.tsnew file mode 100644index 0000000000..20a0cb2216--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxCredentials.test.ts@@ -0,0 +1,66 @@+import path from 'node:path';+import { afterEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({ exec: vi.fn(), packaged: false }));+vi.mock('electron', () => ({+ app: {+ get isPackaged() {+ return h.packaged;+ },+ getAppPath: () => '/test-app',+ },+}));+vi.mock('node:child_process', () => ({ execFile: vi.fn() }));+vi.mock('node:util', () => ({ promisify: () => h.exec }));+import { linuxCredentialCommand, readLinuxUnlockState } from '../linuxCredentials';+afterEach(() => {+ vi.unstubAllGlobals();+ h.exec.mockReset();+ h.packaged = false;+});++it('launches the isolated helper with only public parent/profile arguments', () => {+ const command = linuxCredentialCommand('/test-profile');+ expect(command.file).toBe('/usr/bin/python3');+ expect(command.args).toEqual([+ '-I',+ '-B',+ '-u',+ path.join('/test-app', 'native', 'remote-desktop', 'linux-credentials', 'main.py'),+ '--serve',+ '/test-profile',+ String(process.pid),+ process.execPath,+ ]);+});+it('resolves the packaged helper outside asar', () => {+ h.packaged = true;+ vi.stubGlobal(+ 'process',+ Object.assign(Object.create(process), { resourcesPath: '/test-resources' }),+ );+ expect(linuxCredentialCommand().args[3]).toBe(+ path.join('/test-resources', 'tools', 'remote-desktop', 'linux-credentials', 'main.py'),+ );+});+it.each(['locked', 'unlocked', 'unavailable', 'unexpected-private-detail'])(+ 'only returns allowlisted status for %s',+ async (state) => {+ vi.stubGlobal(+ 'process',+ Object.defineProperty(Object.create(process), 'platform', { value: 'linux' }),+ );+ h.exec.mockResolvedValue({ stdout: state + '\n' });+ expect(await readLinuxUnlockState()).toBe(+ ['locked', 'unlocked'].includes(state) ? state : 'unavailable',+ );+ expect(h.exec.mock.calls[0][1].at(-1)).toBe('--lock-state');+ },+);+it('treats missing helper dependencies as unsupported without leaking errors', async () => {+ vi.stubGlobal(+ 'process',+ Object.defineProperty(Object.create(process), 'platform', { value: 'linux' }),+ );+ h.exec.mockRejectedValue(new Error('private diagnostic'));+ expect(await readLinuxUnlockState()).toBe('unavailable');+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxDesktop.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxDesktop.test.tsnew file mode 100644index 0000000000..e8c91f48a5--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxDesktop.test.ts@@ -0,0 +1,121 @@+import { beforeEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({ exec: vi.fn() }));+vi.mock('node:child_process', () => ({ execFile: vi.fn() }));+vi.mock('node:util', () => ({ promisify: () => h.exec }));+import {+ linuxModeEntries,+ linuxInputMapping,+ linuxMonitor,+ linuxMonitors,+ readLinuxDisplayModes,+ setLinuxDisplayMode,+ type LinuxMonitor,+} from '../linuxDesktop';++const monitor: LinuxMonitor = {+ name: 'eDP-2',+ width: 2560,+ height: 1600,+ refreshRate: 60.002,+ x: 0,+ y: 0,+ scale: 1.6,+ transform: 0,+ availableModes: ['[email protected]', '[email protected]'],+};+beforeEach(() => {+ h.exec.mockReset().mockResolvedValue({ stdout: JSON.stringify([monitor]) });+});+it('exposes actual modes with stable numeric IDs and logical input geometry', () => {+ const modes = linuxModeEntries(monitor);+ expect(modes.map((m) => [m.width, m.height, m.current])).toEqual([+ [1600, 1000, false],+ [1600, 1000, true],+ ]);+ expect(modes.every((m) => /^\d{1,10}$/.test(m.id))).toBe(true);+ expect(+ linuxModeEntries({ ...monitor, availableModes: [...monitor.availableModes].reverse() })[0].id,+ ).toBe(modes[1].id);+});+it('selects only an enumerated monitor and refuses forged mode IDs before writes', async () => {+ await expect(linuxMonitor('hyprland:other')).rejects.toThrow('DESKTOP_DISPLAY_MISSING');+ const current = vi.fn();+ await expect(setLinuxDisplayMode('hyprland:eDP-2', '123456', current)).rejects.toThrow(+ 'DESKTOP_DISPLAY_MODE_MISSING',+ );+ expect(current).not.toHaveBeenCalled();+ expect(h.exec.mock.calls.every((c) => c[1][0] === '-j')).toBe(true);+});+it('rechecks the lease after enumeration and before changing the output', async () => {+ const selected = linuxModeEntries(monitor)[0];+ await expect(+ setLinuxDisplayMode('hyprland:eDP-2', selected.id, () => {+ throw new Error('DESKTOP_LEASE_EXPIRED');+ }),+ ).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(h.exec).toHaveBeenCalledTimes(2);+ h.exec+ .mockResolvedValueOnce({ stdout: JSON.stringify([monitor]) })+ .mockRejectedValueOnce(new Error('legacy'))+ .mockResolvedValueOnce({ stdout: 'ok\n' });+ await setLinuxDisplayMode('hyprland:eDP-2', selected.id, () => {});+ expect(h.exec).toHaveBeenLastCalledWith(+ '/usr/bin/hyprctl',+ ['keyword', 'monitor', 'eDP-2,[email protected],0x0,1.6,transform,0'],+ expect.any(Object),+ );+});+it('uses Lua without a failed mutation first and checks revocation after the probe', async () => {+ const mode = linuxModeEntries(monitor)[0];+ h.exec+ .mockResolvedValueOnce({ stdout: JSON.stringify([monitor]) })+ .mockResolvedValueOnce({ stdout: 'ok' })+ .mockResolvedValueOnce({ stdout: 'ok' });+ await setLinuxDisplayMode('hyprland:eDP-2', mode.id, () => {});+ expect(h.exec.mock.calls[2][1]).toEqual([+ 'eval',+ expect.stringContaining('mode="[email protected]"'),+ ]);+ h.exec.mockClear();+ h.exec+ .mockResolvedValueOnce({ stdout: JSON.stringify([monitor]) })+ .mockResolvedValueOnce({ stdout: 'ok' });+ await expect(+ setLinuxDisplayMode('hyprland:eDP-2', mode.id, () => {+ throw new Error('DESKTOP_LEASE_EXPIRED');+ }),+ ).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(h.exec).toHaveBeenCalledTimes(2);+});+it('maps a negative-origin rotated monitor without sending clicks to its neighbour', () => {+ const left = { ...monitor, name: 'DP-1', x: -1000, transform: 1 };+ const point = linuxInputMapping([left, monitor], 'hyprland:DP-1');+ expect(point(0, 0)).toEqual({ x: 0, y: 0 });+ expect(point(1, 1)).toEqual({ x: 999 / 2600, y: 1599 / 1600 });+ const right = linuxInputMapping([left, monitor], 'hyprland:eDP-2');+ expect(right(0, 0).x).toBe(1000 / 2600);+});+it('reads physical modes while phone-fit hides the source from the active layout', async () => {+ const virtual = {+ ...monitor,+ name: 'CindyRemote-1234567812345678',+ width: 800,+ height: 600,+ scale: 1,+ };+ h.exec.mockImplementation(async (_file, args: string[]) => ({+ stdout: JSON.stringify(+ args.includes('all') ? [{ ...monitor, mirrorOf: virtual.name }, virtual] : [virtual],+ ),+ }));+ expect(await readLinuxDisplayModes('hyprland:eDP-2')).toEqual(+ linuxModeEntries(monitor).map(({ id, width, height, current }) => ({+ id,+ width,+ height,+ current,+ })),+ );+ expect((await linuxMonitors()).map((m) => m.name)).toEqual([virtual.name]);+ await expect(linuxMonitor('hyprland:eDP-2')).rejects.toThrow('DESKTOP_DISPLAY_MISSING');+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxLock.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxLock.test.tsnew file mode 100644index 0000000000..123ca8d60c--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxLock.test.ts@@ -0,0 +1,92 @@+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({ exec: vi.fn() }));+vi.mock('node:child_process', () => ({ execFile: vi.fn() }));+vi.mock('node:util', () => ({ promisify: () => h.exec }));+vi.mock('node:fs', async (original) => ({+ ...(await original<typeof import('node:fs')>()),+ accessSync: vi.fn(),+}));+import { lockLinuxDesktop } from '../linuxDesktop';+const platform = Object.getOwnPropertyDescriptor(process, 'platform')!;+const reply = (secure = false, passwordPam = true) => ({+ stdout: JSON.stringify({ secure, passwordPam, locked: true, requested: true }),+});+beforeEach(() => {+ Object.defineProperty(process, 'platform', { value: 'linux' });+ vi.stubEnv('XDG_SESSION_ID', '1');+ vi.stubEnv('HYPRLAND_INSTANCE_SIGNATURE', 'test');+ h.exec.mockReset();+});+afterEach(() => {+ Object.defineProperty(process, 'platform', platform);+ vi.unstubAllEnvs();+ vi.useRealTimers();+});+it('uses Omarchy lock IPC and waits for secure, not merely requested', async () => {+ vi.useFakeTimers();+ h.exec+ .mockResolvedValueOnce(reply())+ .mockResolvedValueOnce({ stdout: 'ok' })+ .mockResolvedValueOnce(reply())+ .mockResolvedValueOnce(reply(true));+ const locking = lockLinuxDesktop(() => true, new AbortController().signal);+ await vi.runAllTimersAsync();+ await locking;+ expect(h.exec.mock.calls.map((c) => [c[0], c[1]])).toEqual([+ ['/usr/bin/omarchy-shell', ['lock', 'status']],+ ['/usr/bin/omarchy-shell', ['lock', 'lock']],+ ['/usr/bin/omarchy-shell', ['lock', 'status']],+ ['/usr/bin/omarchy-shell', ['lock', 'status']],+ ]);+});+it('falls back to logind when the Omarchy interface is unavailable', async () => {+ h.exec+ .mockRejectedValueOnce(new Error('ENOENT'))+ .mockResolvedValueOnce({ stdout: '' })+ .mockResolvedValueOnce({ stdout: 'yes' });+ await lockLinuxDesktop(() => true, new AbortController().signal);+ expect(h.exec.mock.calls[1][1]).toEqual(['lock-session', '1']);+});+it('does not lock after the lease was revoked during the probe', async () => {+ let current = true;+ h.exec.mockImplementationOnce(async () => {+ current = false;+ return reply();+ });+ await expect(lockLinuxDesktop(() => current, new AbortController().signal)).rejects.toThrow(+ 'DESKTOP_LEASE_EXPIRED',+ );+ expect(h.exec).toHaveBeenCalledTimes(1);+});+it('does not claim success after cancellation during acknowledgement', async () => {+ const cancellation = new AbortController();+ h.exec+ .mockResolvedValueOnce(reply())+ .mockResolvedValueOnce({ stdout: 'ok' })+ .mockImplementationOnce(async () => {+ cancellation.abort();+ return reply(true);+ });+ await expect(lockLinuxDesktop(() => true, cancellation.signal)).rejects.toThrow(+ 'DESKTOP_LEASE_EXPIRED',+ );+});+it.each(['missing-pam', 'failed'])('rejects locker refusal: %s', async (stdout) => {+ h.exec.mockResolvedValueOnce(reply()).mockResolvedValueOnce({ stdout });+ await expect(lockLinuxDesktop(() => true, new AbortController().signal)).rejects.toThrow(+ 'DESKTOP_LOCK_FAILED',+ );+ expect(h.exec).toHaveBeenCalledTimes(2);+});+it('does not treat a pending lock as success when acknowledgement times out', async () => {+ vi.useFakeTimers();+ h.exec+ .mockResolvedValue(reply())+ .mockResolvedValueOnce(reply())+ .mockResolvedValueOnce({ stdout: 'ok' });+ const result = expect(lockLinuxDesktop(() => true, new AbortController().signal)).rejects.toThrow(+ 'DESKTOP_LOCK_FAILED',+ );+ await vi.runAllTimersAsync();+ await result;+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxMute.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxMute.test.tsnew file mode 100644index 0000000000..0325f39048--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxMute.test.ts@@ -0,0 +1,58 @@+import { expect, it, vi } from 'vitest';+import { LinuxDesktopMute } from '../linuxMute';+function setup(muted = false) {+ const sink = {+ id: 62,+ info: {+ props: { 'object.serial': 123, 'node.name': 'speakers', 'media.class': 'Audio/Sink' },+ params: { Props: [{ softMute: muted }] },+ },+ };+ let name = 'speakers';+ const run = vi.fn(async (tool: string) => {+ if (tool === 'pactl') return name;+ if (tool === 'pw-dump') return JSON.stringify([sink]);+ return '';+ });+ return {+ sink,+ run,+ mute: new LinuxDesktopMute(run),+ setDefault: (value: string) => {+ name = value;+ },+ };+}+it('restores the original output after default changes and stop races mute', async () => {+ const h = setup();+ await h.mute.set(true);+ h.setDefault('headphones');+ await Promise.all([h.mute.set(true), h.mute.set(false)]);+ expect(h.run).toHaveBeenLastCalledWith('pw-cli', [+ 'set-param',+ '62',+ 'Props',+ '{ softMute: false }',+ ]);+});+it('preserves pre-existing mute and retries failed restoration', async () => {+ const h = setup(true);+ await h.mute.set(true);+ h.run.mockRejectedValueOnce(new Error('private diagnostics'));+ await expect(h.mute.set(false)).rejects.toThrow('DESKTOP_HOST_MUTE_UNAVAILABLE');+ await h.mute.set(false);+ expect(h.run).toHaveBeenLastCalledWith('pw-cli', [+ 'set-param',+ '62',+ 'Props',+ '{ softMute: true }',+ ]);+});+it('does not touch a different output which reused an unplugged output ID', async () => {+ const h = setup();+ await h.mute.set(true);+ h.run.mockClear();+ h.sink.info.props['object.serial'] = 456;+ await h.mute.set(false);+ expect(h.run.mock.calls.some((c) => c[0] === 'pw-cli')).toBe(false);+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxNativeCapture.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxNativeCapture.test.tsnew file mode 100644index 0000000000..eb75128da4--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxNativeCapture.test.ts@@ -0,0 +1,99 @@+import { EventEmitter } from 'node:events';+import { PassThrough } from 'node:stream';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+const h = vi.hoisted(() => ({ spawn: vi.fn(), binary: vi.fn() }));+vi.mock('node:child_process', () => ({ spawn: h.spawn, execFile: vi.fn() }));+vi.mock('../linuxCapture', () => ({ resolveLinuxCaptureBinary: h.binary }));+vi.mock('../windowsHost', () => ({ openWindowsDesktopConnection: vi.fn() }));+import { NativeDesktopCapture } from '../nativeCapture';+const owners: NativeDesktopCapture[] = [];+beforeEach(() => {+ vi.stubGlobal('process', { ...process, platform: 'linux' });+ h.spawn.mockReset();+ h.binary.mockReset().mockResolvedValue('/capture');+});+afterEach(() => {+ owners.splice(0).forEach((o) => o.stop());+ vi.unstubAllGlobals();+ vi.useRealTimers();+});+function setup() {+ const child = Object.assign(new EventEmitter(), {+ stdin: new PassThrough(),+ stdout: new PassThrough(),+ stderr: new PassThrough(),+ kill: vi.fn(),+ });+ h.spawn.mockReturnValue(child);+ const owner = new NativeDesktopCapture();+ owners.push(owner);+ return { child, owner };+}+it('reuses one child for large bounded frames and releases it on cancellation', async () => {+ const { child, owner } = setup();+ const first = owner.frame('wayland-portal');+ await vi.waitFor(() => expect(h.spawn).toHaveBeenCalledOnce());+ expect(h.spawn).toHaveBeenCalledWith('/capture', ['video', '1', '65'], { stdio: 'pipe' });+ await expect(owner.frame('wayland-portal')).resolves.toBeNull();+ const jpeg = 'a'.repeat(400000);+ child.stdout.write(jpeg + '\n');+ await expect(first).resolves.toBe(jpeg);+ const next = owner.frame('wayland-portal');+ child.stdout.write('anBlZw==\n');+ await expect(next).resolves.toBe('anBlZw==');+ expect(h.spawn).toHaveBeenCalledOnce();+ const late = owner.frame('wayland-portal');+ owner.stop();+ child.stdout.write('anBlZw==\n');+ await expect(late).resolves.toBeNull();+ expect(child.kill).toHaveBeenCalledOnce();+ expect(child.stdout.listenerCount('data')).toBe(0);+});+it('does not spawn after a cancelled asynchronous build', async () => {+ const { owner } = setup();+ let finish!: (value: string) => void;+ h.binary.mockImplementation(+ () =>+ new Promise((resolve) => {+ finish = resolve;+ }),+ );+ const pending = owner.frame('wayland-portal');+ owner.stop();+ finish('/capture');+ await expect(pending).resolves.toBeNull();+ expect(h.spawn).not.toHaveBeenCalled();+});+it('stops oversized native replies', async () => {+ const { child, owner } = setup();+ const pending = owner.frame('wayland-portal');+ await vi.waitFor(() => expect(h.spawn).toHaveBeenCalledOnce());+ child.stdout.write('a'.repeat(1500001));+ await expect(pending).resolves.toBeNull();+ expect(child.kill).toHaveBeenCalledOnce();+});+it('times out a stalled child and rejects unsupported display requests', async () => {+ const { child, owner } = setup();+ await expect(owner.frame('42')).resolves.toBeNull();+ expect(h.binary).not.toHaveBeenCalled();+ vi.useFakeTimers();+ const pending = owner.frame('wayland-portal');+ await vi.advanceTimersByTimeAsync(3000);+ await expect(pending).resolves.toBeNull();+ expect(child.kill).toHaveBeenCalledOnce();+});+it('parses a bounded Linux cursor frame and applies requested encoding quality', async () => {+ const { child, owner } = setup();+ const pending = owner.frame('wayland-portal', true, {+ fps: 60,+ bitrate: 20_000_000,+ audio: false,+ });+ await vi.waitFor(() => expect(h.spawn).toHaveBeenCalledOnce());+ expect(h.spawn).toHaveBeenCalledWith('/capture', ['cursor-overlay', '1', '95'], {+ stdio: 'pipe',+ });+ const frame = { jpeg: 'anBlZw==', cursor: null };+ child.stdout.write(JSON.stringify(frame) + '\n');+ await expect(pending).resolves.toEqual(frame);+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxPrivacy.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxPrivacy.test.tsnew file mode 100644index 0000000000..344cb9fba4--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxPrivacy.test.ts@@ -0,0 +1,187 @@+import { afterEach, expect, it, vi } from 'vitest';+vi.mock('../../i18n', () => ({ t: (key: string) => key }));+import { LinuxPrivacyScreen } from '../linuxPrivacy';+const owners: LinuxPrivacyScreen[] = [];+afterEach(() => {+ owners.splice(0).forEach((owner) => owner.stop());+ vi.useRealTimers();+});+function fixture() {+ let state = 'active';+ const resume = vi.fn(async () => {});+ const pause = vi.fn(async () => resume);+ const stop = vi.fn(async () => {});+ const prepare = vi.fn(async () => {});+ const call = vi.fn(async (request: Record<string, unknown>) => {+ if (request.op === 'confirm') return (state = 'confirming');+ if (request.op === 'resume') return (state = 'active');+ if (request.op === 'stop') return 'off';+ return state;+ });+ const owner = new LinuxPrivacyScreen(stop, pause, { prepare, call, labels: () => [] });+ owners.push(owner);+ return {+ owner,+ call,+ prepare,+ pause,+ resume,+ stop,+ state: (next: string) => {+ state = next;+ },+ };+}+it('fences input before confirmation and restores it before native resume', async () => {+ vi.useFakeTimers();+ const h = fixture();+ await h.owner.set(true, () => true);+ h.state('pending');+ await vi.advanceTimersByTimeAsync(250);+ expect(h.pause).toHaveBeenCalledOnce();+ expect(h.call).toHaveBeenLastCalledWith(expect.objectContaining({ op: 'confirm' }));+ h.state('resume');+ await vi.advanceTimersByTimeAsync(250);+ expect(h.resume).toHaveBeenCalledOnce();+ expect(h.call).toHaveBeenLastCalledWith(expect.objectContaining({ op: 'resume' }));+ h.state('disconnect');+ await vi.advanceTimersByTimeAsync(250);+ expect(h.stop).toHaveBeenCalledOnce();+ expect(h.owner.active).toBe(false);+});+it('does not start privacy after preparation loses its lease', async () => {+ const h = fixture();+ let resolve!: () => void;+ h.prepare.mockImplementationOnce(+ () =>+ new Promise<void>((done) => {+ resolve = done;+ }),+ );+ const starting = h.owner.set(true, () => true);+ await Promise.resolve();+ h.owner.stop();+ resolve();+ await expect(starting).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(h.call).not.toHaveBeenCalled();+});+it('ends only this desktop when native privacy disappears', async () => {+ vi.useFakeTimers();+ const h = fixture();+ await h.owner.set(true, () => true);+ h.state('off');+ await vi.advanceTimersByTimeAsync(250);+ expect(h.stop).toHaveBeenCalledOnce();+ expect(h.owner.active).toBe(false);+ expect(vi.getTimerCount()).toBe(0);+});+it('stopping during a local input pause cannot reopen the dialog', async () => {+ vi.useFakeTimers();+ const h = fixture();+ let resolve!: (value: typeof h.resume) => void;+ h.pause.mockImplementationOnce(+ () =>+ new Promise((done) => {+ resolve = done;+ }),+ );+ await h.owner.set(true, () => true);+ h.state('pending');+ await vi.advanceTimersByTimeAsync(250);+ h.owner.stop();+ resolve(h.resume);+ await vi.advanceTimersByTimeAsync(250);+ expect(h.call.mock.calls.some(([r]) => r.op === 'confirm')).toBe(false);+ expect(h.resume).not.toHaveBeenCalled();+});+it('retires a late native start after an earlier stop already returned', async () => {+ const h = fixture();+ let reply!: (state: string) => void;+ h.call.mockImplementationOnce(+ () =>+ new Promise((resolve) => {+ reply = resolve;+ }),+ );+ const starting = h.owner.set(true, () => true);+ await Promise.resolve();+ await Promise.resolve();+ const token = h.call.mock.calls[0][0].token;+ h.owner.stop();+ reply('active');+ await expect(starting).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(h.call.mock.calls.filter(([r]) => r.op === 'stop' && r.token === token)).toHaveLength(2);+});+it('waits for first rendered masks instead of acknowledging the start command', async () => {+ vi.useFakeTimers();+ const h = fixture();+ h.call.mockResolvedValueOnce('starting');+ let ready = false;+ const starting = h.owner+ .set(true, () => true)+ .then(() => {+ ready = true;+ });+ await vi.advanceTimersByTimeAsync(24);+ expect(ready).toBe(false);+ await vi.advanceTimersByTimeAsync(1);+ await starting;+ expect(ready).toBe(true);+});+it('releases masks even when controller teardown fails', async () => {+ vi.useFakeTimers();+ const h = fixture();+ await h.owner.set(true, () => true);+ h.stop.mockRejectedValue(new Error('shutdown'));+ h.state('off');+ await vi.advanceTimersByTimeAsync(250);+ expect(h.owner.active).toBe(false);+ expect(vi.getTimerCount()).toBe(0);+});+it('disabling privacy during a pending local pause restores input for the live lease', async () => {+ vi.useFakeTimers();+ const h = fixture();+ let resolve!: (value: typeof h.resume) => void;+ h.pause.mockImplementationOnce(+ () =>+ new Promise((done) => {+ resolve = done;+ }),+ );+ await h.owner.set(true, () => true);+ h.state('pending');+ await vi.advanceTimersByTimeAsync(250);+ const disabling = h.owner.set(false, () => true);+ resolve(h.resume);+ await disabling;+ expect(h.resume).toHaveBeenCalledOnce();+ expect(h.call.mock.calls.some(([r]) => r.op === 'confirm')).toBe(false);+});+it('a late input resume cannot clear the replacement owner resume callback', async () => {+ vi.useFakeTimers();+ const h = fixture();+ let finish!: () => void;+ h.resume.mockImplementationOnce(+ () =>+ new Promise<void>((done) => {+ finish = done;+ }),+ );+ await h.owner.set(true, () => true);+ h.state('pending');+ await vi.advanceTimersByTimeAsync(250);+ h.state('resume');+ await vi.advanceTimersByTimeAsync(250);+ h.owner.stop();+ h.state('active');+ await h.owner.set(true, () => true);+ const nextResume = vi.fn(async () => {});+ h.pause.mockResolvedValueOnce(nextResume);+ h.state('pending');+ await vi.advanceTimersByTimeAsync(250);+ finish();+ await Promise.resolve();+ h.state('resume');+ await vi.advanceTimersByTimeAsync(250);+ expect(nextResume).toHaveBeenCalledOnce();+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxViewerDisplay.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxViewerDisplay.test.tsnew file mode 100644index 0000000000..882ae56046--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxViewerDisplay.test.ts@@ -0,0 +1,81 @@+import { EventEmitter } from 'node:events';+import { PassThrough } from 'node:stream';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+type TestChild = EventEmitter & {+ stdin: PassThrough;+ stdout: PassThrough;+ stderr: PassThrough;+ kill: ReturnType<typeof vi.fn>;+};+const h = vi.hoisted(() => ({+ child: null as unknown as TestChild,+ monitor: vi.fn(),+ monitors: vi.fn(),+}));+vi.mock('electron', () => ({ app: { isPackaged: false, getAppPath: () => '/test/app' } }));+vi.mock('node:fs', () => ({ accessSync: vi.fn(), constants: { X_OK: 1, R_OK: 4 } }));+vi.mock('node:child_process', () => ({ spawn: () => h.child }));+vi.mock('../linuxDesktop', () => ({+ supportsLinuxDisplay: () => true,+ linuxMonitor: h.monitor,+ linuxMonitors: h.monitors,+ linuxDisplay: (m: { name: string; width: number; height: number }) => ({+ id: `hyprland:${m.name}`,+ name: m.name,+ width: m.width,+ height: m.height,+ }),+}));+import { createLinuxViewerDisplay } from '../linuxViewerDisplay';+const original = { name: 'eDP-2', width: 1600, height: 1000 };+beforeEach(() => {+ vi.useFakeTimers();+ h.child = Object.assign(new EventEmitter(), {+ stdin: new PassThrough(),+ stdout: new PassThrough(),+ stderr: new PassThrough(),+ kill: vi.fn(),+ });+ h.monitor.mockReset().mockResolvedValue(original);+ h.monitors.mockReset().mockResolvedValue([original]);+});+afterEach(() => vi.useRealTimers());+it('restores on EOF, checks actual output geometry and leaves no heartbeat after exit', async () => {+ const owner = await createLinuxViewerDisplay('hyprland:eDP-2', () => true, vi.fn());+ const name = 'CindyRemote-1234567812345678';+ h.monitor.mockResolvedValue({ name, width: 800, height: 600 });+ const resized = owner.resize(800, 600, () => true);+ h.child.stdout.write(+ JSON.stringify({ id: `hyprland:${name}`, name, width: 800, height: 600 }) + '\n',+ );+ expect((await resized).id).toBe(`hyprland:${name}`);+ const restored = owner.restore!(() => true);+ expect(h.child.stdin.writableEnded).toBe(true);+ h.child.emit('exit', 0);+ expect(await restored).toMatchObject({ id: 'hyprland:eDP-2', width: 1600 });+ expect(vi.getTimerCount()).toBe(0);+});+it('disposes instead of accepting a reply from an expired lease', async () => {+ const failed = vi.fn();+ const owner = await createLinuxViewerDisplay('hyprland:eDP-2', () => true, failed);+ let current = true;+ const resized = owner.resize(800, 600, () => current);+ const rejected = expect(resized).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ current = false;+ h.child.stdout.write(+ '{"id":"hyprland:CindyRemote-1234567812345678","name":"test","width":800,"height":600}\n',+ );+ await rejected;+ expect(h.child.stdin.writableEnded).toBe(true);+ h.child.emit('exit', 0);+ await Promise.resolve();+ expect(failed).not.toHaveBeenCalled();+ expect(vi.getTimerCount()).toBe(0);+});+it('finishes restoration if the original output was unplugged', async () => {+ const owner = await createLinuxViewerDisplay('hyprland:eDP-2', () => true, vi.fn());+ h.monitors.mockResolvedValue([]);+ const restored = owner.restore!(() => true);+ h.child.emit('exit', 0);+ expect(await restored).toMatchObject({ id: 'hyprland:eDP-2' });+});diff --git a/apps/desktop/src/main/remote-desktop/__tests__/linuxWindowActions.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/linuxWindowActions.test.tsnew file mode 100644index 0000000000..8ef6a26ac6--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/linuxWindowActions.test.ts@@ -0,0 +1,211 @@+import { expect, it, vi } from 'vitest';+import { LinuxWindowActions } from '../linuxWindowActions';+import { RemoteDesktopController, type DesktopControllerDeps } from '../controller';+import { parseRemoteDesktopRequest, type RemoteDesktopLease } from '@cindy/device-link';++function fixture(lua = false) {+ let workspace = '1';+ const run = vi.fn(async (args: string[]) => {+ if (args[0] === 'eval' && args[1].startsWith('assert(')) return lua ? 'ok' : 'unavailable';+ if (args[0] === 'eval' && args[1].includes('{workspace=')) {+ if (/workspace="[0-9]+"/.test(args[1])) return 'warning: Bad workspace';+ const value = args[1]+ .match(/workspace=(?:"([A-Za-z0-9_.:-]+)"|([0-9]+))/)+ ?.slice(1)+ .find(Boolean);+ if (value) workspace = value.replace(/^name:/, '');+ }+ if (args[1] === 'clients')+ return JSON.stringify([+ { address: '0xabc', mapped: true, hidden: false, title: 'Editor', class: 'code' },+ { address: 'bad; exec', mapped: true, title: 'bad', class: 'bad' },+ ]);+ if (args[1] === 'monitors')+ return JSON.stringify([{ name: 'eDP-2', activeWorkspace: { id: 1, name: workspace } }]);+ if (args[1] === 'workspace') workspace = args[2].replace(/^name:/, '');+ return 'ok';+ });+ const openMenu = vi.fn(async () => {});+ const windows = new LinuxWindowActions(+ run,+ async () => ({+ name: 'eDP-2',+ width: 800,+ height: 600,+ x: 0,+ y: 0,+ scale: 1,+ transform: 0,+ refreshRate: 60,+ availableModes: [],+ }),+ openMenu,+ );+ return {+ windows,+ run,+ openMenu,+ workspace: () => workspace,+ navigate: (next: string) => {+ workspace = next;+ },+ };+}+it('enumerates bounded windows and never dispatches a forged address', async () => {+ const h = fixture();+ expect(await h.windows.request('list', undefined, 'hyprland:eDP-2', () => true)).toEqual([+ { id: '0xabc', title: 'Editor', app: 'code' },+ ]);+ await expect(+ h.windows.request('activate', '0xdef', 'hyprland:eDP-2', () => true),+ ).rejects.toThrow();+ expect(h.run.mock.calls.some(([args]) => args[0] === 'dispatch')).toBe(false);+ await h.windows.request('activate', '0xabc', 'hyprland:eDP-2', () => true);+ expect(h.run).toHaveBeenLastCalledWith(['dispatch', 'focuswindow', 'address:0xabc']);+});+it('toggles an empty workspace and restores it on disconnect', async () => {+ const h = fixture();+ await h.windows.request('desktop', undefined, 'hyprland:eDP-2', () => true);+ expect(h.workspace()).toMatch(/^cindy-desktop-/);+ await h.windows.request('desktop', undefined, 'hyprland:eDP-2', () => true);+ expect(h.workspace()).toBe('1');+ await h.windows.request('desktop', undefined, 'hyprland:eDP-2', () => true);+ await h.windows.stop();+ expect(h.workspace()).toBe('1');+});+it('uses typed Lua dispatchers on current Omarchy without replaying actions', async () => {+ const h = fixture(true);+ await h.windows.request('desktop', undefined, 'hyprland:eDP-2', () => true);+ expect(h.workspace()).toMatch(/^cindy-desktop-/);+ await h.windows.stop();+ expect(h.workspace()).toBe('1');+ await h.windows.request('activate', '0xabc', 'hyprland:eDP-2', () => true);+ expect(h.run).toHaveBeenLastCalledWith([+ 'eval',+ 'hl.dispatch(hl.dsp.focus({window="address:0xabc"}))',+ ]);+ expect(h.run.mock.calls.some(([args]) => args[0] === 'dispatch')).toBe(false);+});+it('does not undo independent local navigation or execute queued work after stop', async () => {+ const h = fixture();+ await h.windows.request('desktop', undefined, 'hyprland:eDP-2', () => true);+ h.navigate('3');+ await h.windows.stop();+ expect(h.workspace()).toBe('3');+ const late = h.windows.request('desktop', undefined, 'hyprland:eDP-2', () => true);+ const stopped = h.windows.stop();+ await expect(late).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ await stopped;+ expect(h.workspace()).toBe('3');+});+it('requires the controlling lease and discards a list that arrives after revocation', async () => {+ const action = vi.fn(async () => []);+ const deps: DesktopControllerDeps = {+ authorized: () => true,+ capabilities: async () => ({+ version: 1,+ enabled: true,+ platform: 'linux',+ canControl: true,+ displays: [{ id: '1', name: 'Main', width: 800, height: 600 }],+ }),+ startInput: async () => {},+ input: () => {},+ stopInput: () => {},+ stopVideo: () => {},+ changed: () => {},+ frame: async () => null,+ offer: async () => 'answer',+ windowAction: action,+ };+ const controller = new RemoteDesktopController(deps);+ const { lease } = (await controller.request('phone', {+ op: 'start',+ displayId: '1',+ })) as RemoteDesktopLease;+ const request = { op: 'windowAction', action: 'list', lease };+ await expect(controller.request('phone', request)).rejects.toThrow('DESKTOP_VIEW_ONLY');+ expect(action).not.toHaveBeenCalled();+ await controller.request('phone', { op: 'control', lease, enabled: true });+ let resolve!: (value: never[]) => void;+ action.mockImplementationOnce(+ () =>+ new Promise((done) => {+ resolve = done;+ }),+ );+ const pending = controller.request('phone', request);+ await controller.stop();+ resolve([]);+ await expect(pending).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+});+it('strictly parses the additive host action without accepting arbitrary commands', () => {+ expect(parseRemoteDesktopRequest({ op: 'windowAction', action: 'desktop', lease: 'a' })).toEqual({+ op: 'windowAction',+ action: 'desktop',+ lease: 'a',+ });+ for (const action of ['exec', 'activate'])+ expect(() =>+ parseRemoteDesktopRequest({ op: 'windowAction', action, lease: 'a', id: ';exec' }),+ ).toThrow();+});++it.each([false, true])(+ 'switches workspaces on the captured monitor without moving windows (Lua=%s)',+ async (lua) => {+ const h = fixture(lua);+ for (const [action, direction] of [+ ['workspaceLeft', 'm-1'],+ ['workspaceRight', 'm+1'],+ ] as const) {+ await h.windows.request(action, undefined, 'hyprland:eDP-2', () => true);+ expect(h.run).toHaveBeenLastCalledWith(+ lua+ ? ['eval', `hl.dispatch(hl.dsp.focus({workspace="${direction}"}))`]+ : ['dispatch', 'workspace', direction],+ );+ expect(h.run).toHaveBeenCalledWith(+ lua+ ? ['eval', 'hl.dispatch(hl.dsp.focus({monitor="eDP-2"}))']+ : ['dispatch', 'focusmonitor', 'eDP-2'],+ );+ }+ const calls = h.run.mock.calls.length;+ await h.windows.stop();+ expect(h.run).toHaveBeenCalledTimes(calls);+ },+);++it('opens the Omarchy menu only after focusing the selected monitor and while authorized', async () => {+ const h = fixture(true);+ await h.windows.request('omarchyMenu', undefined, 'hyprland:eDP-2', () => true);+ expect(h.run).toHaveBeenLastCalledWith(['eval', 'hl.dispatch(hl.dsp.focus({monitor="eDP-2"}))']);+ expect(h.openMenu).toHaveBeenCalledOnce();+ await expect(+ h.windows.request('omarchyMenu', undefined, 'hyprland:eDP-2', () => false),+ ).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(h.openMenu).toHaveBeenCalledOnce();+});++it.each(['workspaceLeft', 'workspaceRight', 'omarchyMenu'] as const)(+ 'validates %s and cancels it when control is revoked during syntax probing',+ async (action) => {+ expect(parseRemoteDesktopRequest({ op: 'windowAction', action, lease: 'test' })).toEqual({+ op: 'windowAction',+ action,+ lease: 'test',+ });+ const h = fixture(true);+ let current = true;+ h.run.mockImplementationOnce(async () => {+ current = false;+ return 'ok';+ });+ await expect(+ h.windows.request(action, undefined, 'hyprland:eDP-2', () => current),+ ).rejects.toThrow('DESKTOP_LEASE_EXPIRED');+ expect(h.run).toHaveBeenCalledTimes(1);+ expect(h.openMenu).not.toHaveBeenCalled();+ },+);diff --git a/apps/desktop/src/main/remote-desktop/__tests__/waylandCapture.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/waylandCapture.test.tsnew file mode 100644index 0000000000..c101839911--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/__tests__/waylandCapture.test.ts@@ -0,0 +1,32 @@+import { expect, it } from 'vitest';+import { isWaylandDesktop, selectPortalSource, waylandDesktopSize } from '../waylandCapture';++it('isolates Wayland and XWayland hosts from X11, macOS and Windows', () => {+ expect(isWaylandDesktop('linux', { XDG_SESSION_TYPE: 'wayland' })).toBe(true);+ expect(isWaylandDesktop('linux', { WAYLAND_DISPLAY: 'wayland-1' })).toBe(true);+ expect(isWaylandDesktop('linux', { XDG_SESSION_TYPE: 'x11' })).toBe(false);+ expect(isWaylandDesktop('darwin', { WAYLAND_DISPLAY: 'wayland-1' })).toBe(false);+ expect(isWaylandDesktop('win32', {})).toBe(false);+});+it('uses only the single screen explicitly selected by the portal, without guessing monitor IDs', () => {+ const selected = { id: 'screen:0:0', display_id: '' };+ expect(selectPortalSource([selected])).toBe(selected);+ expect(selectPortalSource([])).toBeNull();+ expect(selectPortalSource([selected, { id: 'screen:1:0' }])).toBeNull();+ expect(selectPortalSource([{ id: 'window:1:0' }])).toBeNull();+});++it('preserves a 16:10 desktop aspect ratio instead of exposing JPEG edges behind pillarboxed video', () => {+ expect(waylandDesktopSize([{ bounds: { x: 0, y: 0, width: 1600, height: 1000 } }])).toEqual({+ width: 1600,+ height: 1000,+ });+});+it('includes negative output positions and monitor gaps in the whole-desktop geometry', () => {+ expect(+ waylandDesktopSize([+ { bounds: { x: -1200, y: -200, width: 1000, height: 1600 } },+ { bounds: { x: 0, y: 0, width: 1600, height: 1000 } },+ ]),+ ).toEqual({ width: 2800, height: 1600 });+});diff --git a/apps/desktop/src/main/remote-desktop/captureWindow.ts b/apps/desktop/src/main/remote-desktop/captureWindow.tsindex 43c296d773..521d6a4a09 100644--- a/apps/desktop/src/main/remote-desktop/captureWindow.ts+++ b/apps/desktop/src/main/remote-desktop/captureWindow.ts@@ -154,6 +154,7 @@ export class DesktopCaptureWindow {navigateOnDragDrop: false,webviewTag: false,backgroundThrottling: false,+ autoplayPolicy: 'no-user-gesture-required',spellcheck: false,},});diff --git a/apps/desktop/src/main/remote-desktop/clipboard.ts b/apps/desktop/src/main/remote-desktop/clipboard.tsindex 92d7bdd92d..85a934a39f 100644--- a/apps/desktop/src/main/remote-desktop/clipboard.ts+++ b/apps/desktop/src/main/remote-desktop/clipboard.ts@@ -8,6 +8,11 @@ import {CLIPBOARD_MAX_CHARS,} from '@cindy/device-link';import { readDesktopClipboardVersion, readDesktopSelection } from './inputHost';+import {+ readLinuxClipboardSnapshot,+ writeLinuxClipboard,+ supportsLinuxClipboard,+} from './linuxClipboardNative';const IMAGE_BYTES = 8 * 1024 * 1024;const IMAGE_PIXELS = 4_000_000;@@ -64,7 +69,8 @@ export async function transferDesktopClipboard(const selected = await readDesktopSelection();check();if (selected) {- clipboard.writeText(selected);+ if (supportsLinuxClipboard()) await writeLinuxClipboard({ text: selected }, isCurrent);+ else clipboard.writeText(selected);return selected;}// Only a confirmed empty selection opts into the computer clipboard.@@ -72,7 +78,9 @@ export async function transferDesktopClipboard(// remain errors rather than silently returning unrelated clipboard text.const before = await readDesktopClipboardVersion();check();- const existing = clipboard.readText();+ const existing = supportsLinuxClipboard()+ ? (await readLinuxClipboardSnapshot()).content.text+ : clipboard.readText();if (!existing || existing.length > REMOTE_DESKTOP_MAX_CLIPBOARD_CHARS)throw new Error('DESKTOP_CLIPBOARD_INVALID');const after = await readDesktopClipboardVersion();@@ -84,8 +92,13 @@ export async function transferDesktopClipboard(check();if (!text || text.length > REMOTE_DESKTOP_MAX_CLIPBOARD_CHARS)throw new Error('DESKTOP_CLIPBOARD_INVALID');- clipboard.writeText(text);- if (clipboard.readText() !== text) throw new Error('DESKTOP_CLIPBOARD_WRITE_FAILED');+ if (supportsLinuxClipboard()) await writeLinuxClipboard({ text }, isCurrent);+ else clipboard.writeText(text);+ const writtenText = supportsLinuxClipboard()+ ? (await readLinuxClipboardSnapshot()).content.text+ : clipboard.readText();+ check();+ if (writtenText !== text) throw new Error('DESKTOP_CLIPBOARD_WRITE_FAILED');const modifier = process.platform === 'darwin' ? 'MetaLeft' : 'ControlLeft';input([{ kind: 'release' },@@ -117,19 +130,22 @@ export async function transferDesktopClipboardContent(check();if (options?.version && before !== options.version)throw new Error('DESKTOP_CLIPBOARD_CHANGED');- const formats = clipboard.availableFormats();+ const linux = supportsLinuxClipboard() ? await readLinuxClipboardSnapshot() : null;+ check();+ const formats = linux?.formats ?? clipboard.availableFormats();// A file-backed image may also expose a portable bitmap. Never read the// file flavor or dereference its path; a file alone remains unsupported.const fileBacked = formats.some((format) =>/file-url|filenames|hdrop|filecontents|filegroupdescriptor|uri-list/i.test(format),);- const image = clipboard.readImage();- if (fileBacked && image.isEmpty()) throw new Error('CLIPBOARD_UNSUPPORTED');- const snapshot: RemoteClipboardContent = {};+ const image = linux ? nativeImage.createEmpty() : clipboard.readImage();+ if (fileBacked && image.isEmpty() && !linux?.content.png)+ throw new Error('CLIPBOARD_UNSUPPORTED');+ const snapshot: RemoteClipboardContent = { ...linux?.content };// File-manager text/HTML can be a local path rather than image content.- const text = fileBacked ? '' : clipboard.readText();- const html = fileBacked ? '' : clipboard.readHTML();- const rtf = fileBacked ? '' : clipboard.readRTF();+ const text = fileBacked ? '' : linux ? linux.content.text : clipboard.readText();+ const html = fileBacked ? '' : linux ? linux.content.html : clipboard.readHTML();+ const rtf = fileBacked ? '' : linux ? linux.content.rtf : clipboard.readRTF();if (text) snapshot.text = text;if (html) snapshot.html = html;if (rtf) snapshot.rtf = rtf;@@ -156,36 +172,57 @@ export async function transferDesktopClipboardContent(const version = await readDesktopClipboardVersion();check();if (options?.version && version !== options.version) throw new Error('DESKTOP_CLIPBOARD_CHANGED');- clipboard.write({- ...(value.text || value.url ? { text: value.text || value.url } : {}),- ...(value.html ? { html: value.html } : {}),- ...(value.rtf ? { rtf: value.rtf } : {}),- ...(image ? { image } : {}),- });- if (- (image && clipboard.readImage().isEmpty()) ||- (value.text && clipboard.readText() !== value.text)- )- throw new Error('DESKTOP_CLIPBOARD_WRITE_FAILED');- check();- if (options?.sync) {- const fingerprint = () =>- createHash('sha256')- .update(- JSON.stringify([- clipboard.availableFormats(),- clipboard.readText(),- clipboard.readHTML(),- clipboard.readRTF(),- ]),- )- .update(clipboardPng(clipboard.readImage()))- .digest('hex');- const written = fingerprint();- const version = await readDesktopClipboardVersion(true);+ if (supportsLinuxClipboard()) {+ await writeLinuxClipboard(value, isCurrent);+ const actual = (await readLinuxClipboardSnapshot()).content;+ check();+ if (+ (value.text || value.url || undefined) !== actual.text ||+ value.html !== actual.html ||+ value.rtf !== actual.rtf ||+ value.png !== actual.png+ )+ throw new Error('DESKTOP_CLIPBOARD_WRITE_FAILED');+ if (options?.sync) {+ const version = await readDesktopClipboardVersion(true);+ const after = (await readLinuxClipboardSnapshot()).content;+ check();+ if (JSON.stringify(after) !== JSON.stringify(actual))+ throw new Error('DESKTOP_CLIPBOARD_CHANGED');+ return { version };+ }+ } else {+ clipboard.write({+ ...(value.text || value.url ? { text: value.text || value.url } : {}),+ ...(value.html ? { html: value.html } : {}),+ ...(value.rtf ? { rtf: value.rtf } : {}),+ ...(image ? { image } : {}),+ });+ if (+ (image && clipboard.readImage().isEmpty()) ||+ (value.text && clipboard.readText() !== value.text)+ )+ throw new Error('DESKTOP_CLIPBOARD_WRITE_FAILED');check();- if (fingerprint() !== written) throw new Error('DESKTOP_CLIPBOARD_CHANGED');- return { version };+ if (options?.sync) {+ const fingerprint = () =>+ createHash('sha256')+ .update(+ JSON.stringify([+ clipboard.availableFormats(),+ clipboard.readText(),+ clipboard.readHTML(),+ clipboard.readRTF(),+ ]),+ )+ .update(clipboardPng(clipboard.readImage()))+ .digest('hex');+ const written = fingerprint();+ const version = await readDesktopClipboardVersion(true);+ check();+ if (fingerprint() !== written) throw new Error('DESKTOP_CLIPBOARD_CHANGED');+ return { version };+ }}const modifier = process.platform === 'darwin' ? 'MetaLeft' : 'ControlLeft';input([diff --git a/apps/desktop/src/main/remote-desktop/controller.ts b/apps/desktop/src/main/remote-desktop/controller.tsindex 89411ef368..ad34ab4ca5 100644--- a/apps/desktop/src/main/remote-desktop/controller.ts+++ b/apps/desktop/src/main/remote-desktop/controller.ts@@ -7,6 +7,7 @@ import {REMOTE_DESKTOP_LEASE_MS,REMOTE_DESKTOP_MAX_FRAME_BYTES,type DesktopInput,+ type RemoteDesktopWindow,type RemoteDesktopCursorFrame,type RemoteClipboardContent,type RemoteDesktopVideoSettings,@@ -22,6 +23,15 @@ import {const log = createLogger('remote-desktop:controller');export interface DesktopControllerDeps {+ /** Optional host setup before allocating the first lease or temporary output. */+ prepare?(current: () => boolean): Promise<void>;+ windowAction?(+ action: 'list' | 'activate' | 'desktop' | 'workspaceLeft' | 'workspaceRight' | 'omarchyMenu',+ id: string | undefined,+ displayId: string,+ current: () => boolean,+ ): Promise<RemoteDesktopWindow[] | null>;+ stopWindowActions?(): Promise<void>;authorized(peer: string): boolean;/*** Trusted host authentication provider, never a controller-supplied flag.@@ -36,6 +46,7 @@ export interface DesktopControllerDeps {frame(displayId: string,cursorOverlay?: boolean,+ lease?: string,): Promise<string | RemoteDesktopCursorFrame | null>;startInput(displayId: string): Promise<void>;input(events: DesktopInput[]): void;@@ -53,7 +64,7 @@ export interface DesktopControllerDeps {ice?(request: RemoteDesktopIceRequest): Promise<RemoteDesktopIceReply>;displayModes?(displayId: string): Promise<RemoteDesktopDisplayMode[]>;/** Local hardware presence; must not hide displays when remote access is revoked. */- displayPresent?(displayId: string): boolean;+ displayPresent?(displayId: string): boolean | Promise<boolean>;resolution?(displayId: string,modeId: string,@@ -135,7 +146,7 @@ export class RemoteDesktopController {try {this.deps.stopPrivacyScreen?.();} finally {- await this.deps.stopHostMute?.();+ await Promise.all([this.deps.stopHostMute?.(), this.deps.stopWindowActions?.()]);}}/** Revoke input synchronously; optional OS restoration must never retain it@@ -319,7 +330,7 @@ export class RemoteDesktopController {if (this.viewerDisplay === handle) this.viewerDisplay = null;const original = this.originalResolution;if (original) {- if (this.deps.displayPresent?.(original.displayId) !== false)+ if ((await this.deps.displayPresent?.(original.displayId)) !== false)await (this.deps.restoreResolution ?? this.deps.resolution)!(original.displayId,original.modeId,@@ -470,6 +481,16 @@ export class RemoteDesktopController {try {if (!this.active && (this.viewerDisplay || this.originalResolution))await this.restoreStoppedDisplay();+ if (!this.active && this.deps.prepare) {+ const current = () =>+ this.startingPeer === peer &&+ generation === this.controlGeneration &&+ this.deps.authorized(peer) &&+ this.authenticationCurrent(peer, authenticationSession);+ if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ await this.deps.prepare(current);+ if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ }const caps = await this.deps.capabilities();if (!this.authenticationCurrent(peer, authenticationSession))throw new Error('DESKTOP_AUTHENTICATION_REQUIRED');@@ -523,6 +544,25 @@ export class RemoteDesktopController {if (this.displayChanging && !['stop', 'heartbeat', 'frame', 'input'].includes(request.op))throw new Error('DESKTOP_DISPLAY_BUSY');switch (request.op) {+ case 'windowAction': {+ if (!active.controlling) throw new Error('DESKTOP_VIEW_ONLY');+ if (!this.deps.windowAction) throw new Error('DESKTOP_INPUT_UNSUPPORTED');+ const generation = this.controlGeneration;+ const current = () => {+ this.tick();+ return (+ this.active === active && active.controlling && this.controlGeneration === generation+ );+ };+ const result = await this.deps.windowAction(+ request.action,+ request.action === 'activate' ? request.id : undefined,+ active.display.id,+ current,+ );+ if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ return result;+ }case 'privacyScreen': {if (!active.controlling) throw new Error('DESKTOP_VIEW_ONLY');if (!this.deps.privacyScreen) throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');@@ -788,7 +828,11 @@ export class RemoteDesktopController {this.framePending = true;this.lastFrame = this.now();try {- const jpeg = await this.deps.frame(active.display.id, request.cursorOverlay);+ const jpeg = await this.deps.frame(+ active.display.id,+ request.cursorOverlay,+ active.lease,+ );this.require(peer, request.lease); // revoke during capture must not leak the resultif (this.displayChanging || active.display !== display) return { jpeg: null };const frame = typeof jpeg === 'object' && jpeg !== null ? jpeg : { jpeg };diff --git a/apps/desktop/src/main/remote-desktop/credentialHost.ts b/apps/desktop/src/main/remote-desktop/credentialHost.tsindex 54530d1c95..3f253d3e2f 100644--- a/apps/desktop/src/main/remote-desktop/credentialHost.ts+++ b/apps/desktop/src/main/remote-desktop/credentialHost.ts@@ -11,12 +11,13 @@ import {credentialVerificationArguments,} from './credentialSigning';import { createLogger } from '../logger';+import { linuxCredentialCommand, readLinuxUnlockState } from './linuxCredentials';const exec = promisify(execFile);const diagnostic = createLogger('remote-credentials');const binaryName = 'cindy-macos-remote-credentials';let build: Promise<string> | undefined;-async function resolveBinary(realm: 'global' | 'cn'): Promise<string> {+async function resolveBinary(): Promise<string> {if (app.isPackaged) return path.join(process.resourcesPath, 'tools/remote-desktop', binaryName);if (build) return build;build = (async () => {@@ -286,13 +287,15 @@ class RemoteCredentialHost {this.starting = (async () => {const realm = this.configuredRealm;if (!realm) throw new Error('CREDENTIAL_INVALID_IDENTITY');- const binary = await resolveBinary(realm);+ const directory = path.join(app.getPath('userData'), 'remote-desktop/credential-identity');+ if (process.platform === 'linux' && (await readLinuxUnlockState()) === 'unavailable')+ throw new Error('CREDENTIAL_UNLOCK_UNAVAILABLE');+ const command =+ process.platform === 'linux'+ ? linuxCredentialCommand(directory)+ : { file: await resolveBinary(), args: [directory] };if (this.epoch !== epoch) throw new Error('CREDENTIAL_CANCELLED');- const child = spawn(- binary,- [path.join(app.getPath('userData'), 'remote-desktop/credential-identity')],- { stdio: ['pipe', 'pipe', 'pipe'] },- );+ const child = spawn(command.file, command.args, { stdio: ['pipe', 'pipe', 'pipe'] });this.child = child;let buffer = '';child.stdout.setEncoding('utf8');@@ -357,7 +360,8 @@ class RemoteCredentialHost {args: Record<string, unknown> = {},timeout = 35_000,): Promise<unknown> {- if (process.platform !== 'darwin') throw new Error('CREDENTIAL_UNAVAILABLE');+ if (process.platform !== 'darwin' && process.platform !== 'linux')+ throw new Error('CREDENTIAL_UNAVAILABLE');if (timeout <= 0) throw new Error('CREDENTIAL_EXPIRED');const id = randomUUID();let timer: ReturnType<typeof setTimeout>;diff --git a/apps/desktop/src/main/remote-desktop/hyprlandCapture.ts b/apps/desktop/src/main/remote-desktop/hyprlandCapture.tsnew file mode 100644index 0000000000..a4b8aa1e28--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/hyprlandCapture.ts@@ -0,0 +1,103 @@+import { NativeDesktopCapture } from './nativeCapture';+import { execFile } from 'node:child_process';+import { accessSync, constants } from 'node:fs';+import { WAYLAND_DISPLAY_ID, isWaylandDesktop } from './waylandCapture';+import type { RemoteDesktopCursorFrame, RemoteDesktopVideoSettings } from '@cindy/device-link';+import { linuxMonitor } from './linuxDesktop';++// Use the distribution's helper, never a command supplied by a remote peer or PATH.+const executable = '/usr/bin/grim';+export function supportsHyprlandCapture(): boolean {+ if (!isWaylandDesktop(process.platform, process.env) || !process.env.HYPRLAND_INSTANCE_SIGNATURE)+ return false;+ try {+ accessSync(executable, constants.X_OK);+ return true;+ } catch {+ return false;+ }+}++/** Hyprland's native screencopy respects compositor permissions without a portal+ * picker. Called only inside the authorized desktop lease. No files or retained+ * frames; stopping aborts the process and discards a late result.+ * A persistent screencopy child serves supported layouts. grim composes the+ * whole desktop when the persistent helper is unavailable.+ */+export class HyprlandCapture {+ private active: AbortController | null = null;+ private native = new NativeDesktopCapture();+ private fallback = false;++ async frame(+ display: string,+ overlay = false,+ settings?: RemoteDesktopVideoSettings,+ ): Promise<string | RemoteDesktopCursorFrame | null> {+ if (+ (display !== WAYLAND_DISPLAY_ID && !/^hyprland:[A-Za-z0-9_.-]{1,80}$/.test(display)) ||+ !supportsHyprlandCapture() ||+ this.active+ )+ return null;+ const active = new AbortController();+ this.active = active;+ try {+ if (!this.fallback) {+ const frame = await this.native.frame(display, overlay, settings).catch(() => null);+ if (active.signal.aborted || this.active !== active) return null;+ if (frame) return frame;+ this.native.stop();+ this.fallback = true;+ }+ const output = display === WAYLAND_DISPLAY_ID ? null : await linuxMonitor(display);+ if (active.signal.aborted) return null;+ const jpeg = await new Promise<Buffer>((resolve, reject) => {+ execFile(+ executable,+ [+ '-t',+ 'jpeg',+ '-q',+ settings?.bitrate === 20_000_000 ? '95' : settings?.bitrate === 8_000_000 ? '80' : '65',+ '-s',+ '1',+ ...(output ? ['-o', output.name] : []),+ '-',+ ],+ {+ encoding: 'buffer',+ timeout: 2500,+ maxBuffer: 8 * 1024 * 1024,+ signal: active.signal,+ killSignal: 'SIGKILL',+ },+ (error, stdout) => (error ? reject(error) : resolve(stdout)),+ );+ });+ if (+ active.signal.aborted ||+ this.active !== active ||+ jpeg.length < 4 ||+ jpeg[0] !== 0xff ||+ jpeg[1] !== 0xd8 ||+ jpeg[jpeg.length - 2] !== 0xff ||+ jpeg[jpeg.length - 1] !== 0xd9+ )+ return null;+ return jpeg.toString('base64');+ } catch {+ return null;+ } finally {+ if (this.active === active) this.active = null;+ }+ }++ stop(): void {+ const active = this.active;+ this.active = null;+ active?.abort();+ this.native.stop();+ this.fallback = false;+ }+}diff --git a/apps/desktop/src/main/remote-desktop/index.ts b/apps/desktop/src/main/remote-desktop/index.tsindex 45aca3ba99..62da8a9555 100644--- a/apps/desktop/src/main/remote-desktop/index.ts+++ b/apps/desktop/src/main/remote-desktop/index.ts@@ -18,6 +18,7 @@ import { remoteCredentialHost } from './credentialHost';import {isDesktopPermission,REMOTE_DESKTOP_OFFER_BUDGET,+ REMOTE_DESKTOP_MAX_FRAME_BYTES,parseDesktopIceReply,type RemoteDesktopIceRequest,type RemoteDesktopIceReply,@@ -42,10 +43,32 @@ import {waitForDisplayRestore,} from './viewerDisplay';import { desktopCaptureSource, enumerateDesktopSources } from './captureSource';+import {+ isWaylandDesktop,+ WAYLAND_DISPLAY_ID,+ selectPortalSource,+ waylandDesktopSize,+} from './waylandCapture';import { encodeDesktopFrame, encodeNativeRelayFrame } from './frame';import { transferDesktopClipboard, transferDesktopClipboardContent } from './clipboard';import { NativeDesktopCapture } from './nativeCapture';+import { HyprlandCapture, supportsHyprlandCapture } from './hyprlandCapture';+import { readLinuxDesktopInputSupport } from './linuxInput';+import { LinuxDesktopAudio, supportsLinuxAudio } from './linuxAudio';+import { supportsLinuxClipboard, stopLinuxClipboardWriter } from './linuxClipboardNative';+import {+ supportsLinuxDisplay,+ supportsLinuxLock,+ waitForLinuxDisplay,+ linuxMonitors,+ linuxDisplay,+ linuxMonitor,+} from './linuxDesktop';+import { readLinuxCursorSupport } from './linuxCapture';+import { LinuxDesktopMute, supportsLinuxMute } from './linuxMute';import { PrivacyScreen } from './privacyScreen';+import { LinuxPrivacyScreen, supportsLinuxPrivacy, prepareLinuxPrivacy } from './linuxPrivacy';+import { LinuxWindowActions, supportsOmarchyMenu } from './linuxWindowActions';import { systemAudioMuteGuard } from '../voice-input/SystemAudioMuteGuard.js';import { readWindowsDesktopSupport, configureWindowsDesktopSupport } from './windowsHost';import {@@ -101,8 +124,42 @@ const permissions = new RemoteDesktopPermissionsService({});let host: WebContents | null = null;+const wayland = () => isWaylandDesktop(process.platform, process.env);+let portalReady: Promise<void> | null = null;+let portalGrant = false;+// Electron cannot cancel getSources. Keep a pending picker exclusive even when+// its lease is revoked; its eventual selection must never grant a replacement.+let portalSelecting = false;+async function ensurePortalCapture(lease: string): Promise<void> {+ if (!remoteDesktop.hasLease(lease)) throw new Error('DESKTOP_LEASE_EXPIRED');+ if (videoLease === lease && portalReady) return portalReady;+ stopVideo();+ setVideoLease(lease);+ const ready = captureWindow.start();+ host = captureWindow.contents;+ const owner = host;+ const generation = offerGeneration;+ portalGrant = true;+ portalReady = ready.then(() => {+ if (generation !== offerGeneration || host !== owner || !remoteDesktop.hasLease(lease))+ throw new Error('DESKTOP_LEASE_EXPIRED');+ owner!.send(DESKTOP_LOCAL.COMMAND, {+ id: randomUUID(),+ op: 'prepare',+ lease,+ portalCapture: true,+ } satisfies DesktopHostCommand);+ });+ return portalReady;+}const captureWindow = new DesktopCaptureWindow(() => remoteDesktop.stop());const nativeCapture = new NativeDesktopCapture();+const hyprlandCapture = new HyprlandCapture();+const linuxAudio = new LinuxDesktopAudio();+const linuxMute = new LinuxDesktopMute();+const linuxWindows = new LinuxWindowActions();+const nativeWayland = () => wayland() && supportsHyprlandCapture();+const portalWayland = () => wayland() && !nativeWayland();const privacyScreen = new PrivacyScreen((ids) => nativeCapture.setExcludedWindows(ids),() => {@@ -112,6 +169,10 @@ const privacyScreen = new PrivacyScreen(},() => input.pauseForPrivacy(),);+const linuxPrivacy = new LinuxPrivacyScreen(+ () => remoteDesktop.stopPrivacyByUser(),+ () => input.pauseForPrivacy(),+);const supportsPrivacyScreen =(process.platform === 'darwin' &&typeof process.getSystemVersion === 'function' &&@@ -121,7 +182,8 @@ let displayAwake: number | null = null;let nativeDisplay: string | null = null;let windowsAvailable = false;let captureGrant: { source: DesktopCapturerSource; lease: string; audio: boolean } | null = null;-const supportsSystemAudio =+const supportsSystemAudio = () =>+ (nativeWayland() && supportsLinuxAudio()) ||process.platform === 'win32' ||(process.platform === 'darwin' &&typeof process.getSystemVersion === 'function' &&@@ -140,7 +202,7 @@ let preparingOffer = false;let videoAttempt: string | undefined;let pending: {id: string;- op: 'offer' | 'ice';+ op: 'offer' | 'ice' | 'frame';resolve(result: DesktopHostReply): void;reject(error: Error): void;timer: ReturnType<typeof setTimeout>;@@ -150,10 +212,14 @@ let pending: {const input = new DesktopInputHost(() => remoteDesktop.releaseControl());function stopVideo(): void {offerGeneration++;+ portalReady = null;+ portalGrant = false;videoAttempt = undefined;nativeOverlay = false;nativeSettings = undefined;nativeCapture.stop();+ hyprlandCapture.stop();+ linuxAudio.stop();nativeDisplay = null;captureGrant = null;setVideoLease(null);@@ -190,6 +256,37 @@ async function offer(attemptId?: string,): Promise<string> {if (pending || preparingOffer) throw new Error('DESKTOP_VIDEO_BUSY');+ if (portalWayland()) {+ if (lease.display.id !== WAYLAND_DISPLAY_ID) throw new Error('DESKTOP_DISPLAY_MISSING');+ await ensurePortalCapture(lease.lease);+ // ICE retries replace the peer, not the user-authorized capture stream.+ if (pending || preparingOffer) throw new Error('DESKTOP_VIDEO_BUSY');+ preparingOffer = true;+ const generation = offerGeneration;+ try {+ const iceServers = await loadDesktopIceServers();+ if (generation !== offerGeneration || !remoteDesktop.hasLease(lease.lease))+ throw new Error('DESKTOP_LEASE_EXPIRED');+ videoAttempt = attemptId;+ const result = await requestHost(+ {+ id: randomUUID(),+ op: 'offer',+ lease: lease.lease,+ portalCapture: true,+ sdp,+ settings,+ attemptId,+ iceServers,+ },+ REMOTE_DESKTOP_OFFER_BUDGET.hostMs,+ );+ if (typeof result !== 'string') throw new Error('DESKTOP_VIDEO_UNAVAILABLE');+ return result;+ } finally {+ if (generation === offerGeneration) preparingOffer = false;+ }+ }stopVideo();preparingOffer = true;const generation = offerGeneration;@@ -202,8 +299,10 @@ async function offer(if (!current() || host !== currentHost || !currentHost || currentHost.isDestroyed())throw new Error('DESKTOP_LEASE_EXPIRED');let source: DesktopCapturerSource | null = null;- let nativeAvailable = process.platform === 'darwin';- {+ const hyprland = nativeWayland();+ if (hyprland && lease.display.id !== WAYLAND_DISPLAY_ID) await linuxMonitor(lease.display.id);+ let nativeAvailable = process.platform === 'darwin' || hyprland;+ if (!hyprland) {nativeAvailable ||=process.platform === 'win32' && (await readWindowsDesktopSupport()) === 'ready';try {@@ -231,12 +330,19 @@ async function offer(currentHost.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;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({@@ -244,6 +350,8 @@ async function offer(op: 'offer',sourceId: source?.id,nativeCapture: nativeAvailable,+ continuousNativeCapture: hyprland,+ nativeAudio: hyprland && settings?.audio === true,cursorOverlay: nativeOverlay,lease: lease.lease,sdp,@@ -265,7 +373,7 @@ async function offer(/** One bounded command to the existing capture owner; never reset the shared device link. */function requestHost(- command: DesktopHostCommand & { op: 'offer' | 'ice' },+ command: DesktopHostCommand & { op: 'offer' | 'ice' | 'frame' },timeoutMs: number,): Promise<DesktopHostReply> {const currentHost = host;@@ -277,7 +385,15 @@ function requestHost(const timer = setTimeout(() => {if (pending?.id === id) {pending = null;- if (command.op === 'offer') stopVideo();+ if (command.op === 'offer') {+ if (portalWayland()) {+ try {+ currentHost.send(DESKTOP_LOCAL.COMMAND, { id: randomUUID(), op: 'stop' });+ } catch {+ stopVideo();+ }+ } else stopVideo();+ }reject(new Error('DESKTOP_VIDEO_TIMEOUT'));}}, timeoutMs);@@ -317,7 +433,7 @@ export async function requestRemoteDesktop(peer: string, value: unknown): Promis)throw new Error('DESKTOP_UNAVAILABLE');if (- process.platform === 'darwin' &&+ (process.platform === 'darwin' || process.platform === 'linux') &&value !== null &&typeof value === 'object' &&'op' in value &&@@ -339,7 +455,7 @@ export async function requestRemoteDesktop(peer: string, value: unknown): Promisreturn { version: 1, ready: true, descriptor };}}- return process.platform === 'darwin' &&+ return (process.platform === 'darwin' || process.platform === 'linux') &&value !== null &&typeof value === 'object' &&'op' in value &&@@ -348,7 +464,13 @@ export async function requestRemoteDesktop(peer: string, value: unknown): Promis: remoteDesktop.request(peer, value);}-export const remoteDesktop = new RemoteDesktopController({+export const remoteDesktop: RemoteDesktopController = new RemoteDesktopController({+ prepare: async (current) => {+ if (nativeWayland() && (await supportsLinuxPrivacy())) {+ // Optional privacy support cannot make ordinary viewing unavailable.+ await prepareLinuxPrivacy(current, true).catch(() => {});+ }+ },authorized: (peer) => {const settings = readDeviceLinkSettings();return (@@ -362,35 +484,76 @@ export const remoteDesktop = new RemoteDesktopController({const settings = readDeviceLinkSettings();const enabled = settings.remoteDesktopEnabled && settings.remoteControlEnabled;const viewerDisplay = enabled && (await viewerDisplaySupported());+ const linuxDisplays =+ enabled && nativeWayland() && supportsLinuxDisplay()+ ? (await linuxMonitors()).map(linuxDisplay)+ : null;return {version: 1,- cursorOverlay: process.platform === 'darwin' || (process.platform === 'win32' && windowsAvailable),- lockOnExit: process.platform === 'darwin',- clipboardContent: process.platform === 'darwin' || process.platform === 'win32',- clipboardSync: process.platform === 'darwin' || process.platform === 'win32',- clipboardInline: process.platform === 'darwin' || process.platform === 'win32',- privacyScreen: supportsPrivacyScreen,- hostMute: process.platform === 'darwin' || process.platform === 'win32',- clipboardText: process.platform === 'darwin' || process.platform === 'win32',+ windowActions: Boolean(linuxDisplays),+ workspaceNavigation: Boolean(linuxDisplays),+ omarchyMenu: Boolean(linuxDisplays) && supportsOmarchyMenu(),+ cursorOverlay:+ process.platform === 'darwin' ||+ (process.platform === 'win32' && windowsAvailable) ||+ Boolean(enabled && nativeWayland() && (await readLinuxCursorSupport())),+ lockOnExit: process.platform === 'darwin' || supportsLinuxLock(),+ clipboardContent:+ process.platform === 'darwin' ||+ process.platform === 'win32' ||+ (supportsLinuxLock() && supportsLinuxClipboard()),+ clipboardSync:+ process.platform === 'darwin' ||+ process.platform === 'win32' ||+ (supportsLinuxLock() && supportsLinuxClipboard()),+ clipboardInline:+ process.platform === 'darwin' ||+ process.platform === 'win32' ||+ (supportsLinuxLock() && supportsLinuxClipboard()),+ privacyScreen:+ supportsPrivacyScreen || (enabled && nativeWayland() && (await supportsLinuxPrivacy())),+ hostMute:+ process.platform === 'darwin' || process.platform === 'win32' || supportsLinuxMute(),+ clipboardText:+ process.platform === 'darwin' ||+ process.platform === 'win32' ||+ (supportsLinuxLock() && supportsLinuxClipboard()),videoSettings: true,trickleIce: true,backgroundViewing: true,- systemAudio: supportsSystemAudio,+ systemAudio: supportsSystemAudio(),viewerDisplay,viewerDisplayRestore: viewerDisplay,- displayModes: process.platform === 'darwin',+ displayModes: process.platform === 'darwin' || Boolean(linuxDisplays?.length),enabled,- canControl: process.platform === 'darwin' || process.platform === 'win32',+ canControl:+ process.platform === 'darwin' ||+ process.platform === 'win32' ||+ (enabled && nativeWayland() && (await readLinuxDesktopInputSupport())),platform: process.platform,...(enabled ? { permissions: await permissions.read() } : {}),- displays: enabled- ? screen.getAllDisplays().map((d, i) => ({- id: String(d.id),- name: d.label || `Display ${i + 1}`,- width: d.size.width,- height: d.size.height,- }))- : [],+ displays:+ linuxDisplays ??+ (enabled && wayland()+ ? // PipeWire exposes the user's selection, not a mapping to Electron's+ // physical display IDs. Never label an arbitrary selected screen as monitor 1.+ [+ {+ id: WAYLAND_DISPLAY_ID,+ name: '',+ ...(nativeWayland()+ ? waylandDesktopSize(screen.getAllDisplays())+ : { width: 1280, height: 720 }),+ },+ ]+ : enabled+ ? screen.getAllDisplays().map((d, i) => ({+ id: String(d.id),+ name: d.label || `Display ${i + 1}`,+ width: d.size.width,+ height: d.size.height,+ }))+ : []),};},permissions: async (action) => {@@ -398,18 +561,29 @@ export const remoteDesktop = new RemoteDesktopController({if (action === 'guide') permissions.show();return permissions.read();},- frame: async (displayId, cursorOverlay) => {+ frame: async (displayId, cursorOverlay, lease) => {+ if (nativeWayland()) {+ if (!lease || !remoteDesktop.hasLease(lease)) throw new Error('DESKTOP_LEASE_EXPIRED');+ if (preparingOffer) return null;+ const frame = await hyprlandCapture.frame(displayId, cursorOverlay);+ if (!remoteDesktop.hasLease(lease)) return null;+ return encodeNativeRelayFrame(frame, (jpeg) => nativeImage.createFromBuffer(jpeg));+ }+ if (portalWayland()) {+ if (displayId !== WAYLAND_DISPLAY_ID || !lease) throw new Error('DESKTOP_DISPLAY_MISSING');+ if (pending || preparingOffer) return null;+ await ensurePortalCapture(lease);+ if (pending || preparingOffer) return null;+ const result = await requestHost({ id: randomUUID(), op: 'frame', lease }, 2000);+ return typeof result === 'string' ? result : null;+ }// offer() cancels the previous read before acquiring the capture owner.// Leave its required first frame uncontested; relay polling resumes afterwards.if (preparingOffer) return null;// Compatibility viewers must also wake/capture without waiting for// Chromium's thumbnail enumeration, which may hang on a sleeping display.if (process.platform === 'darwin' || windowsAvailable) {- const frame = await nativeCapture.frame(- displayId,- cursorOverlay === true,- nativeSettings,- );+ const frame = await nativeCapture.frame(displayId, cursorOverlay === true, nativeSettings);return encodeNativeRelayFrame(frame, (jpeg) => nativeImage.createFromBuffer(jpeg));}const available = await sources(true).catch((error) => {@@ -432,6 +606,7 @@ export const remoteDesktop = new RemoteDesktopController({// Poll counters even for nonportable items; the content read owns format validation.clipboardVersion: () => readDesktopClipboardVersion(),privacyScreen: async (enabled, current) => {+ if (process.platform === 'linux') return linuxPrivacy.set(enabled, current);if (!supportsPrivacyScreen) throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');if (enabled && process.platform === 'darwin' && videoLease && nativeDisplay) {nativeOverlay = true;@@ -458,18 +633,38 @@ export const remoteDesktop = new RemoteDesktopController({throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');}},- stopPrivacyScreen: () => privacyScreen.stop(),+ stopPrivacyScreen: () => {+ privacyScreen.stop();+ linuxPrivacy.stop();+ },+ windowAction: (action, id, display, current) => {+ if (!nativeWayland()) throw new Error('DESKTOP_INPUT_UNSUPPORTED');+ return linuxWindows.request(action, id, display, current);+ },+ stopWindowActions: () => linuxWindows.stop(),hostMute: async (enabled) => {+ if (process.platform === 'linux') return linuxMute.set(enabled);if (enabled) await systemAudioMuteGuard.mute('remote-desktop');else await systemAudioMuteGuard.restore('remote-desktop');},- stopHostMute: () => systemAudioMuteGuard.restore('remote-desktop'),+ stopHostMute: () =>+ process.platform === 'linux'+ ? linuxMute.set(false)+ : systemAudioMuteGuard.restore('remote-desktop'),displayModes: readDesktopDisplayModes,- displayPresent: (displayId) =>- screen.getAllDisplays().some((display) => String(display.id) === displayId),+ displayPresent: async (displayId) => {+ if (nativeWayland()) {+ const monitors = await linuxMonitors();+ return displayId === WAYLAND_DISPLAY_ID+ ? monitors.length === 1+ : monitors.some((m) => linuxDisplay(m).id === displayId);+ }+ return screen.getAllDisplays().some((display) => String(display.id) === displayId);+ },resolution: async (displayId, modeId, beforeChange, expected) => {await setDesktopDisplayMode(displayId, modeId, beforeChange);- if (expected)+ if (nativeWayland()) await waitForLinuxDisplay(displayId, expected, beforeChange);+ else if (expected)await waitForDisplayRestore(displayId, expected, beforeChange, (displays) =>// Restoration may retire an unplugged monitor; selection must not// publish usable geometry for a monitor that no longer exists.@@ -478,10 +673,20 @@ export const remoteDesktop = new RemoteDesktopController({},restoreResolution: async (displayId, modeId, beforeChange, expected) => {await setDesktopDisplayMode(displayId, modeId, beforeChange, true);- await waitForDisplayRestore(displayId, expected, beforeChange);+ if (nativeWayland()) await waitForLinuxDisplay(displayId, expected, beforeChange);+ else await waitForDisplayRestore(displayId, expected, beforeChange);},createViewerDisplay,- startInput: (displayId) => input.start(displayId),+ startInput: async (displayId) => {+ // A portal-selected window is not the whole compositor coordinate space.+ // Never allow a forged control request to drive that view-only fallback.+ if (+ process.platform === 'linux' &&+ (!nativeWayland() || !(await readLinuxDesktopInputSupport()))+ )+ throw new Error('DESKTOP_INPUT_UNSUPPORTED');+ await input.start(displayId);+ },input: (events) => {try {input.input(events);@@ -496,7 +701,7 @@ export const remoteDesktop = new RemoteDesktopController({},stopInput: () => input.stop(),releaseInput: () => input.release(),- ...(process.platform === 'darwin'+ ...(process.platform === 'darwin' || supportsLinuxLock()? {lockScreen: async (isCurrent: () => boolean, signal: AbortSignal) => {await input.release();@@ -525,22 +730,49 @@ export function registerRemoteDesktopIpc(denyAppDesktopCapture(session.defaultSession, isVoiceInputOwner);const timer = setInterval(() => remoteDesktop.tick(), 1000);timer.unref();+ onQuit('remote-desktop-clipboard', stopLinuxClipboardWriter);onQuit('remote-desktop-stop', () => {clearInterval(timer);permissions.dismiss();remoteDesktop.stop();});onQuit('remote-desktop-restore', () => remoteDesktop.stopAndRestore(), 'async');+ const linuxLayoutChanged = () => {+ if (!nativeWayland() || remoteDesktop.changingDisplay || !remoteDesktop.displayId) return;+ const generation = offerGeneration,+ id = remoteDesktop.displayId;+ // The virtual pointer covers the entire layout: even another output moving+ // invalidates its mapping. Release input immediately while checking geometry.+ remoteDesktop.releaseControl();+ void linuxMonitor(id)+ .then((monitor) => {+ if (generation !== offerGeneration || remoteDesktop.changingDisplay) return;+ const display = linuxDisplay(monitor);+ if (!remoteDesktop.displayGeometryMatches(id, display.width, display.height))+ remoteDesktop.stop();+ })+ .catch(() => {+ if (generation === offerGeneration && !remoteDesktop.changingDisplay) remoteDesktop.stop();+ });+ };screen.on('display-removed', (_event, display) => {+ linuxLayoutChanged();if (remoteDesktop.changingDisplay) return;if (String(display.id) === remoteDesktop.displayId) remoteDesktop.stop();});screen.on('display-added', () => {+ linuxLayoutChanged();// A new screen invalidates mask coverage, not the selected capture geometry.// Include masks still being prepared, before the controller reports enabled.if (privacyScreen.active && !remoteDesktop.changingDisplay) remoteDesktop.stop();});screen.on('display-metrics-changed', (_event, display, metrics) => {+ if (+ metrics.some(+ (metric) => metric === 'bounds' || metric === 'scaleFactor' || metric === 'rotation',+ )+ )+ linuxLayoutChanged();if (remoteDesktop.changingDisplay) return;// Managed resolution changes can deliver scaleFactor after preparation// finishes. Matching logical geometry keeps input coordinates valid;@@ -565,6 +797,7 @@ export function registerRemoteDesktopIpc(});const sessionChanged = () => {nativeCapture.stop(); // do not retain pixels from the previous OS session state+ hyprlandCapture.stop();if (remoteDesktop.state?.controlling) {try {input.input([{ kind: 'release' }]);@@ -592,12 +825,31 @@ export function registerRemoteDesktopIpc()throwIpcError('PERMISSION_DENIED', 'Invalid desktop capture lease');const generation = offerGeneration;- const jpeg = await nativeCapture- .frame(nativeDisplay, nativeOverlay, nativeSettings)- .catch(() => null);+ const jpeg = await (+ nativeWayland()+ ? hyprlandCapture.frame(nativeDisplay, nativeOverlay, nativeSettings)+ : nativeCapture.frame(nativeDisplay, nativeOverlay, nativeSettings)+ ).catch(() => null);if (generation !== offerGeneration || !remoteDesktop.hasLease(lease)) return null;return jpeg;});+ ipcMain.handle(DESKTOP_LOCAL.NATIVE_AUDIO, (event, lease: unknown) => {+ captureWindow.assertSender(event);+ if (+ event.sender !== host ||+ typeof lease !== 'string' ||+ lease !== videoLease ||+ !remoteDesktop.hasLease(lease) ||+ !nativeSettings?.audio ||+ !nativeWayland()+ )+ throwIpcError('PERMISSION_DENIED', 'Invalid desktop audio lease');+ try {+ return linuxAudio.read();+ } catch {+ throwIpcError('PERMISSION_DENIED', 'Desktop audio unavailable');+ }+ });ipcMain.handle(DESKTOP_LOCAL.VIEW_HEARTBEAT, (event, lease: unknown) => {captureWindow.assertSender(event);if (event.sender !== host || typeof lease !== 'string' || lease !== videoLease)@@ -668,6 +920,55 @@ export function registerRemoteDesktopIpc(captureWindow.registered(event);const owner = event.sender;owner.session.setDisplayMediaRequestHandler((request, callback) => {+ if (portalWayland()) {+ const lease = videoLease;+ if (+ !portalGrant ||+ portalSelecting ||+ host !== owner ||+ request.frame !== owner.mainFrame ||+ !request.videoRequested ||+ request.audioRequested ||+ !lease ||+ !remoteDesktop.hasLease(lease)+ ) {+ callback({});+ return;+ }+ portalGrant = false;+ portalSelecting = true;+ const generation = offerGeneration;+ void desktopCapturer+ .getSources({+ types: ['screen'],+ thumbnailSize: { width: 0, height: 0 },+ fetchWindowIcons: false,+ })+ .then((available) => {+ const source = selectPortalSource(available);+ if (+ source &&+ generation === offerGeneration &&+ host === owner &&+ !owner.isDestroyed() &&+ remoteDesktop.hasLease(lease)+ )+ callback({ video: source });+ else callback({});+ })+ .catch(() => {+ // The callback can itself throw if Chromium disposed the request.+ try {+ callback({});+ } catch {+ /* old capture process is already gone */+ }+ })+ .finally(() => {+ portalSelecting = false;+ });+ return;+ }const grant = captureGrant;if (!grant ||@@ -714,13 +1015,22 @@ export function registerRemoteDesktopIpc(throw new Error(String(sdp.error));if (request.op === 'offer' && typeof sdp === 'string' && sdp.length <= 64_000)request.resolve(sdp);+ else if (+ request.op === 'frame' &&+ wayland() &&+ (sdp === null ||+ (typeof sdp === 'string' &&+ sdp.length <= Math.ceil(REMOTE_DESKTOP_MAX_FRAME_BYTES / 3) * 4 &&+ /^[A-Za-z0-9+/]+={0,2}$/.test(sdp)))+ )+ request.resolve(sdp);else if (request.op === 'ice') {const result = parseDesktopIceReply(sdp);if (result.attemptId !== videoAttempt) throw new Error('DESKTOP_VIDEO_STOPPED');request.resolve(result);} else throw new Error('DESKTOP_VIDEO_UNAVAILABLE');} catch (error) {- if (request.op === 'offer') stopVideo();+ if (request.op === 'offer' && !portalWayland()) stopVideo();request.reject(error instanceof Error ? error : new Error('DESKTOP_VIDEO_UNAVAILABLE'));}});diff --git a/apps/desktop/src/main/remote-desktop/inputHost.ts b/apps/desktop/src/main/remote-desktop/inputHost.tsindex 1df71ac8cf..8d3c9dcdc8 100644--- a/apps/desktop/src/main/remote-desktop/inputHost.ts+++ b/apps/desktop/src/main/remote-desktop/inputHost.ts@@ -10,6 +10,17 @@ import type {RemoteDesktopDisplayMode,} from '@cindy/device-link';import { HumanDesktopInput } from './inputOwnership';+import { resolveLinuxInputBinary } from './linuxInput';+import { readLinuxUnlockState } from './linuxCredentials';+import { WAYLAND_DISPLAY_ID } from './waylandCapture';+import {+ readLinuxDisplayModes,+ setLinuxDisplayMode,+ lockLinuxDesktop,+ linuxMonitors,+ linuxInputMapping,+} from './linuxDesktop';+import { linuxClipboardVersion, linuxSelection } from './linuxClipboard';import {openWindowsDesktopConnection,readWindowsDesktopSupport,@@ -21,6 +32,7 @@ const binaryName =process.platform === 'darwin' ? 'cindy-macos-desktop-input' : 'cindy-windows-desktop-input.exe';let build: Promise<string> | null = null;async function resolveBinary(): Promise<string> {+ if (process.platform === 'linux') return resolveLinuxInputBinary();if (app.isPackaged)return path.join(process.resourcesPath, 'tools', 'remote-desktop', binaryName);if (build) return build;@@ -113,6 +125,9 @@ export { resolveBinary as resolveDesktopInputBinary };/** Probe the actual input process, never CuaDriver's or Electron's AX grant. */export async function readDesktopLockState(): Promise<'locked' | 'unlocked' | 'unavailable'> {+ if (process.platform === 'linux') {+ return readLinuxUnlockState();+ }if (process.platform !== 'darwin') return 'unavailable';try {const { stdout } = await exec(await resolveBinary(), ['--lock-state'], {@@ -160,6 +175,7 @@ export async function lockDesktopScreen(isCurrent: () => boolean,signal: AbortSignal,): Promise<void> {+ if (process.platform === 'linux') return lockLinuxDesktop(isCurrent, signal);if (process.platform !== 'darwin') throw new Error('DESKTOP_LOCK_UNAVAILABLE');const binary = await resolveBinary();if (signal.aborted || !isCurrent()) throw new Error('DESKTOP_LEASE_EXPIRED');@@ -197,6 +213,7 @@ export class DesktopInputHost {private heartbeat: ReturnType<typeof setInterval> | null = null;private stopping: Promise<void> = Promise.resolve();private privacyPaused = false;+ private linuxPoint: ((x: number, y: number) => { x: number; y: number }) | null = null;constructor(private readonly onFailure: () => void,private readonly runtime: {@@ -211,7 +228,14 @@ export class DesktopInputHost {async start(displayId: string): Promise<void> {this.stop();const platform = this.runtime.platform ?? process.platform;- if (platform !== 'darwin' && platform !== 'win32') throw new Error('DESKTOP_INPUT_UNSUPPORTED');+ if (platform !== 'darwin' && platform !== 'win32' && platform !== 'linux')+ throw new Error('DESKTOP_INPUT_UNSUPPORTED');+ if (+ platform === 'linux' &&+ displayId !== WAYLAND_DISPLAY_ID &&+ !/^hyprland:[A-Za-z0-9_.-]{1,80}$/.test(displayId)+ )+ throw new Error('DESKTOP_DISPLAY_MISSING');// A replacement helper is not usable until its ready handshake completes.// In particular, canceling a privacy confirmation must keep dropping input// throughout teardown, binary preparation and startup, without losing control.@@ -221,6 +245,10 @@ export class DesktopInputHost {if (generation !== this.generation) throw new Error('DESKTOP_LEASE_EXPIRED');this.activity = new HumanDesktopInput();try {+ if (platform === 'linux' && displayId !== WAYLAND_DISPLAY_ID) {+ this.linuxPoint = linuxInputMapping(await linuxMonitors(), displayId);+ if (generation !== this.generation) throw new Error('DESKTOP_LEASE_EXPIRED');+ } else this.linuxPoint = null;if (platform === 'win32' &&!this.runtime.platform &&@@ -256,7 +284,8 @@ export class DesktopInputHost {const finish = (error?: Error) => {clearTimeout(timer);child.stdout.off('data', receive);- error ? reject(error) : resolve();+ if (error) reject(error);+ else resolve();};const receive = (data: Buffer) => {text += data.toString();@@ -295,6 +324,34 @@ export class DesktopInputHost {}input(events: DesktopInput[]): void {if (this.privacyPaused) return;+ if ((this.runtime.platform ?? process.platform) === 'linux') {+ if (!this.child) throw new Error('DESKTOP_INPUT_UNAVAILABLE');+ // Native text is paced for Wayland clients/IMEs. Bound each acknowledged+ // command so long phone pastes cannot exceed the helper heartbeat timeout.+ let pending: DesktopInput[] = [];+ const flush = () => {+ if (pending.length && this.child) this.write(pending, this.activity!.begin(pending));+ pending = [];+ };+ for (const event of events) {+ if (event.kind !== 'text') {+ pending.push(+ (event.kind === 'move' || event.kind === 'button') && this.linuxPoint+ ? { ...event, ...this.linuxPoint(event.x, event.y) }+ : event,+ );+ continue;+ }+ flush();+ const chars = Array.from(event.text);+ for (let i = 0; i < chars.length; i += 256) {+ pending = [{ kind: 'text', text: chars.slice(i, i + 256).join('') }];+ flush();+ }+ }+ flush();+ return; // Wayland's virtual pointer maps normalized coordinates to the output layout.+ }const display = screen.getAllDisplays().find((item) => String(item.id) === this.displayId);if (!display || (!this.child && !this.windows)) throw new Error('DESKTOP_INPUT_UNAVAILABLE');if (events.length === 0) return;@@ -338,7 +395,8 @@ export class DesktopInputHost {const finish = (error?: Error) => {clearTimeout(timer);if (this.acknowledge === finish) this.acknowledge = null;- error ? reject(error) : resolve();+ if (error) reject(error);+ else resolve();};this.acknowledge = finish;child!.stdin.write(line, (error) => {@@ -444,6 +502,7 @@ export class DesktopInputHost {export async function readDesktopDisplayModes(displayId: string,): Promise<RemoteDesktopDisplayMode[]> {+ if (process.platform === 'linux') return readLinuxDisplayModes(displayId);if (process.platform !== 'darwin' || !/^[0-9]{1,10}$/.test(displayId))throw new Error('DESKTOP_DISPLAY_MODES_UNAVAILABLE');const { stdout } = await exec(await resolveBinary(), ['--display-modes', displayId], {@@ -479,6 +538,8 @@ export async function setDesktopDisplayMode(if (changingResolution) throw new Error('DESKTOP_DISPLAY_BUSY');changingResolution = true;try {+ if (process.platform === 'linux')+ return await setLinuxDisplayMode(displayId, modeId, beforeChange);if (process.platform !== 'darwin' ||!/^[0-9]{1,10}$/.test(displayId) ||@@ -503,6 +564,7 @@ export async function setDesktopDisplayMode(/** Counter only: clipboard text never crosses a helper's stdout/log boundary. */export async function readDesktopClipboardVersion(portable = false): Promise<string> {+ if (process.platform === 'linux') return linuxClipboardVersion();if (process.platform !== 'darwin' && process.platform !== 'win32')throw new Error('DESKTOP_CLIPBOARD_UNAVAILABLE');try {@@ -537,6 +599,7 @@ export async function readDesktopClipboardVersion(portable = false): Promise<str}export async function readDesktopSelection(portable = false): Promise<string> {+ if (process.platform === 'linux') return linuxSelection();try {const { stdout } = await exec(await resolveBinary(),diff --git a/apps/desktop/src/main/remote-desktop/linuxAudio.ts b/apps/desktop/src/main/remote-desktop/linuxAudio.tsnew file mode 100644index 0000000000..240c48ace4--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxAudio.ts@@ -0,0 +1,103 @@+import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process';+import { accessSync, constants } from 'node:fs';++const executable = '/usr/bin/pw-record';+const bytesPerFrame = 8; // Stereo float32, 48 kHz.+const maxBytes = 4800 * bytesPerFrame; // Never retain more than 100 ms.++export function supportsLinuxAudio(): boolean {+ if (process.platform !== 'linux') return false;+ try {+ accessSync(executable, constants.X_OK);+ return true;+ } catch {+ return false;+ }+}++/** Ephemeral output-monitor capture owned by the authorized video lease.+ * PipeWire's sink capture policy follows the default output, never the microphone.+ * Bytes remain in memory and stale samples are dropped instead of building latency.+ */+export class LinuxDesktopAudio {+ private child: ChildProcessWithoutNullStreams | null = null;+ private samples: Buffer = Buffer.alloc(0);+ private failed = false;+ private lastRead = 0;+ private lastData = 0;+ private watchdog: ReturnType<typeof setInterval> | undefined;+ constructor(+ private readonly launch = () =>+ spawn(+ executable,+ [+ '--raw',+ '--format',+ 'f32',+ '--rate',+ '48000',+ '--channels',+ '2',+ '--latency',+ '20ms',+ '--properties',+ '{ stream.capture.sink=true node.name=cindy-desktop-audio media.role=Screen }',+ '-',+ ],+ { stdio: 'pipe' },+ ),+ ) {}++ start(): void {+ this.stop();+ this.failed = false;+ const child = this.launch();+ this.child = child;+ this.lastRead = Date.now();+ this.lastData = this.lastRead;+ child.stderr.resume(); // Never expose native diagnostics or sampled content.+ child.stdin.on('error', () => {});+ child.stdout.on('data', (chunk: Buffer) => {+ if (this.child !== child) return;+ if (chunk.length) this.lastData = Date.now();+ const joined = Buffer.concat([this.samples, chunk]);+ const discard = Math.max(+ 0,+ Math.ceil((joined.length - maxBytes) / bytesPerFrame) * bytesPerFrame,+ );+ this.samples = Buffer.from(joined.subarray(discard));+ });+ const failed = () => {+ if (this.child !== child) return;+ this.stop();+ this.failed = true;+ };+ child.once('error', failed);+ child.once('exit', failed);+ this.watchdog = setInterval(() => {+ if (Date.now() - this.lastRead > 3000 || Date.now() - this.lastData > 5000) failed();+ }, 1000);+ this.watchdog.unref();+ }++ read(): Uint8Array {+ if (!this.child || this.failed) throw new Error('DESKTOP_AUDIO_UNAVAILABLE');+ this.lastRead = Date.now();+ const size = this.samples.length - (this.samples.length % bytesPerFrame);+ const result = Uint8Array.from(this.samples.subarray(0, size));+ this.samples = Buffer.from(this.samples.subarray(size));+ return result;+ }++ stop(): void {+ const child = this.child;+ this.child = null;+ this.samples = Buffer.alloc(0);+ clearInterval(this.watchdog);+ this.watchdog = undefined;+ if (child) {+ child.stdin.destroy();+ child.kill('SIGKILL');+ }+ }+}diff --git a/apps/desktop/src/main/remote-desktop/linuxCapture.ts b/apps/desktop/src/main/remote-desktop/linuxCapture.tsnew file mode 100644index 0000000000..5e8776a613--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxCapture.ts@@ -0,0 +1,62 @@+import { app } from 'electron';+import { execFile } from 'node:child_process';+import { createHash } from 'node:crypto';+import fs from 'node:fs/promises';+import path from 'node:path';+import { promisify } from 'node:util';++const exec = promisify(execFile);+const binaryName = 'cindy-linux-desktop-capture';+let building: Promise<string> | null = null;+export async function readLinuxCursorSupport(): Promise<boolean> {+ if (process.platform !== 'linux') return false;+ try {+ const { stdout } = await exec(await resolveLinuxCaptureBinary(), ['--cursor-check'], {+ timeout: 3000,+ maxBuffer: 1024,+ });+ return stdout.trim() === 'ready';+ } catch {+ return false;+ }+}+export function resolveLinuxCaptureBinary(): Promise<string> {+ if (app.isPackaged)+ return Promise.resolve(path.join(process.resourcesPath, 'tools', 'remote-desktop', binaryName));+ if (building) return building;+ building = (async () => {+ const root = path.join(app.getAppPath(), 'native', 'remote-desktop', 'linux-capture');+ const hash = createHash('sha256').update(process.arch);+ for (const name of [+ 'main.c',+ 'cursor.h',+ 'build.mjs',+ 'wlr-screencopy-unstable-v1.xml',+ 'ext-image-copy-capture-v1.xml',+ 'ext-image-capture-source-v1.xml',+ 'ext-foreign-toplevel-list-v1.xml',+ ])+ hash.update(await fs.readFile(path.join(root, name)));+ const output = path.join(+ app.getPath('userData'),+ 'remote-desktop',+ 'native',+ hash.digest('hex'),+ );+ const binary = path.join(output, binaryName);+ try {+ await fs.access(binary, fs.constants.X_OK);+ return binary;+ } catch {+ /* build this source */+ }+ await exec('node', [path.join(root, 'build.mjs'), output], {+ timeout: 60000,+ maxBuffer: 64000,+ });+ return binary;+ })().finally(() => {+ building = null;+ });+ return building;+}diff --git a/apps/desktop/src/main/remote-desktop/linuxClipboard.ts b/apps/desktop/src/main/remote-desktop/linuxClipboard.tsnew file mode 100644index 0000000000..7729193981--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxClipboard.ts@@ -0,0 +1,36 @@+import { createHash } from 'node:crypto';+import { execFile } from 'node:child_process';+import { promisify } from 'node:util';+import { supportsLinuxLock } from './linuxDesktop';+import { readLinuxClipboardSnapshot } from './linuxClipboardNative';++const exec = promisify(execFile);+/** Linux has no portable clipboard generation counter. Fingerprint only the+ * portable formats that our existing transfer path can expose, never file URLs.+ * This is called within the controlling lease, never as an application watcher. */+async function unlocked(): Promise<void> {+ if (!supportsLinuxLock()) throw new Error('DESKTOP_CLIPBOARD_UNAVAILABLE');+ try {+ const { stdout } = await exec(+ '/usr/bin/loginctl',+ ['show-session', process.env.XDG_SESSION_ID!, '-p', 'LockedHint', '--value'],+ { timeout: 1000, maxBuffer: 128 },+ );+ if (stdout.trim() !== 'no') throw new Error('DESKTOP_CLIPBOARD_UNAVAILABLE');+ } catch {+ throw new Error('DESKTOP_CLIPBOARD_UNAVAILABLE');+ }+}+export async function linuxClipboardVersion(): Promise<string> {+ await unlocked();+ const snapshot = await readLinuxClipboardSnapshot();+ await unlocked();+ return createHash('sha256').update(JSON.stringify(snapshot)).digest('hex');+}+export async function linuxSelection(): Promise<string> {+ await unlocked();+ const text = (await readLinuxClipboardSnapshot(true)).content.text ?? '';+ await unlocked();+ if (text.length > 16384) throw new Error('DESKTOP_CLIPBOARD_COPY_FAILED');+ return text;+}diff --git a/apps/desktop/src/main/remote-desktop/linuxClipboardNative.ts b/apps/desktop/src/main/remote-desktop/linuxClipboardNative.tsnew file mode 100644index 0000000000..6b60469e34--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxClipboardNative.ts@@ -0,0 +1,181 @@+import { app } from 'electron';+import { spawn, execFile, type ChildProcessWithoutNullStreams } from 'node:child_process';+import { promisify } from 'node:util';+import { createHash } from 'node:crypto';+import fs from 'node:fs/promises';+import { accessSync, constants } from 'node:fs';+import path from 'node:path';+import type { RemoteClipboardContent } from '@cindy/device-link';++const exec = promisify(execFile);+export function supportsLinuxClipboard(): boolean {+ if (process.platform !== 'linux' || !process.env.HYPRLAND_INSTANCE_SIGNATURE) return false;+ try {+ accessSync('/usr/bin/wl-paste', constants.X_OK);+ return true;+ } catch {+ return false;+ }+}+async function read(args: string[], maxBuffer: number): Promise<Buffer> {+ try {+ const result = await exec('/usr/bin/wl-paste', args, {+ timeout: 2000,+ maxBuffer,+ encoding: 'buffer',+ });+ return result.stdout;+ } catch (error) {+ // Empty selection is distinct from failed compositor access. Never propagate+ // subprocess exceptions: they can include clipboard contents in stdout.+ if (+ error &&+ typeof error === 'object' &&+ 'stderr' in error &&+ Buffer.isBuffer(error.stderr) &&+ /^Nothing is copied|^No selection/.test(error.stderr.toString())+ )+ return Buffer.alloc(0);+ throw new Error('DESKTOP_CLIPBOARD_UNAVAILABLE');+ }+}+export async function readLinuxClipboardSnapshot(+ primary = false,+): Promise<{ formats: string[]; content: RemoteClipboardContent }> {+ if (!supportsLinuxClipboard()) throw new Error('DESKTOP_CLIPBOARD_UNAVAILABLE');+ const selection = primary ? ['--primary'] : [];+ const formats = (await read([...selection, '--list-types'], 16384))+ .toString()+ .trim()+ .split('\n')+ .filter(Boolean);+ if (formats.length > 64 || formats.some((f) => f.length > 256))+ throw new Error('CLIPBOARD_UNSUPPORTED');+ const fileBacked = formats.some((f) =>+ /file-url|filenames|hdrop|filecontents|filegroupdescriptor|uri-list/i.test(f),+ );+ const content: RemoteClipboardContent = {};+ const textTypes = [+ ['text', ['text/plain;charset=utf-8', 'text/plain', 'UTF8_STRING']],+ ['html', ['text/html']],+ ['rtf', ['text/rtf', 'application/rtf']],+ ] as const;+ if (!fileBacked) {+ for (const [key, types] of textTypes) {+ if (primary && key !== 'text') continue;+ const mime = types.find((type) => formats.includes(type));+ if (mime) {+ const value = (+ await read([...selection, '--no-newline', '--type', mime], 2 * 1024 * 1024)+ ).toString();+ if (value.length > 512000) throw new Error('CLIPBOARD_TOO_LONG');+ if (value) content[key] = value;+ }+ }+ }+ if (!primary && formats.includes('image/png')) {+ const png = await read(['--no-newline', '--type', 'image/png'], 8 * 1024 * 1024);+ if (+ png.length < 33 ||+ !png.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))+ )+ throw new Error('CLIPBOARD_UNSUPPORTED');+ const width = png.readUInt32BE(16),+ height = png.readUInt32BE(20);+ if (!width || !height || width * height > 4000000) throw new Error('CLIPBOARD_TOO_LONG');+ content.png = png.toString('base64');+ }+ return { formats, content };+}+let building: Promise<string> | undefined;+async function binary(): Promise<string> {+ const name = 'cindy-linux-desktop-clipboard';+ if (app.isPackaged) return path.join(process.resourcesPath, 'tools', 'remote-desktop', name);+ if (building) return building;+ building = (async () => {+ const source = path.join(app.getAppPath(), 'native', 'remote-desktop', 'linux-clipboard');+ const hash = createHash('sha256').update(process.arch);+ for (const name of ['main.c', 'build.mjs', 'wlr-data-control-unstable-v1.xml'])+ hash.update(await fs.readFile(path.join(source, name)));+ const directory = path.join(+ app.getPath('userData'),+ 'remote-desktop',+ 'native',+ hash.digest('hex'),+ );+ const target = path.join(directory, name);+ try {+ await fs.access(target, constants.X_OK);+ return target;+ } catch {+ /* Build this source. */+ }+ await exec('node', [path.join(source, 'build.mjs'), directory], {+ timeout: 60000,+ maxBuffer: 64000,+ });+ return target;+ })()+ .catch(() => {+ throw new Error('DESKTOP_CLIPBOARD_UNAVAILABLE');+ })+ .finally(() => {+ building = undefined;+ });+ return building;+}+let writer: ChildProcessWithoutNullStreams | null = null;+/** Like Electron's clipboard owner, an explicitly copied value survives the+ * remote lease until replacement or app exit. It never observes later copies. */+export function stopLinuxClipboardWriter(): void {+ writer?.kill();+ writer = null;+}+export async function writeLinuxClipboard(+ content: RemoteClipboardContent,+ current: () => boolean,+): Promise<void> {+ const executable = await binary();+ if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ const child = spawn(executable, [], { stdio: 'pipe' });+ child.stderr.resume();+ child.stdin.on('error', () => {});+ try {+ await new Promise<void>((resolve, reject) => {+ let response = '';+ const finish = (ready: boolean) => {+ clearTimeout(timer);+ child.stdout.off('data', data);+ child.off('error', failed);+ child.off('exit', failed);+ if (ready) resolve();+ else reject(new Error('DESKTOP_CLIPBOARD_WRITE_FAILED'));+ };+ const failed = () => finish(false);+ const data = (chunk: Buffer) => {+ response += chunk.toString();+ if (response.length > 32) failed();+ else if (response.includes('\n')) finish(response === 'ready\n');+ };+ const timer = setTimeout(failed, 5000);+ child.once('error', failed);+ child.once('exit', failed);+ child.stdout.on('data', data);+ child.stdin.write(+ JSON.stringify({+ ...content,+ ...(content.url && !content.text ? { text: content.url } : {}),+ }) + '\n',+ );+ });+ if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ writer?.kill();+ writer = child;+ child.once('exit', () => {+ if (writer === child) writer = null;+ });+ } catch (error) {+ child.kill();+ throw error;+ }+}diff --git a/apps/desktop/src/main/remote-desktop/linuxCredentials.ts b/apps/desktop/src/main/remote-desktop/linuxCredentials.tsnew file mode 100644index 0000000000..55c60e3168--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxCredentials.ts@@ -0,0 +1,36 @@+import { app } from 'electron';+import { execFile } from 'node:child_process';+import path from 'node:path';+import { promisify } from 'node:util';++const exec = promisify(execFile);+export function linuxCredentialCommand(directory?: string): { file: string; args: string[] } {+ const script = app.isPackaged+ ? path.join(process.resourcesPath, 'tools', 'remote-desktop', 'linux-credentials', 'main.py')+ : path.join(app.getAppPath(), 'native', 'remote-desktop', 'linux-credentials', 'main.py');+ return {+ file: '/usr/bin/python3',+ args: [+ '-I',+ '-B',+ '-u',+ script,+ ...(directory+ ? ['--serve', directory, String(process.pid), process.execPath]+ : ['--lock-state']),+ ],+ };+}++/** Read-only probe: no keyring access, password prompt or lock-screen mutation. */+export async function readLinuxUnlockState(): Promise<'locked' | 'unlocked' | 'unavailable'> {+ if (process.platform !== 'linux') return 'unavailable';+ try {+ const command = linuxCredentialCommand();+ const { stdout } = await exec(command.file, command.args, { timeout: 6000, maxBuffer: 1024 });+ const state = stdout.trim();+ return state === 'locked' || state === 'unlocked' ? state : 'unavailable';+ } catch {+ return 'unavailable';+ }+}diff --git a/apps/desktop/src/main/remote-desktop/linuxDesktop.ts b/apps/desktop/src/main/remote-desktop/linuxDesktop.tsnew file mode 100644index 0000000000..dcea951f98--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxDesktop.ts@@ -0,0 +1,260 @@+import { execFile } from 'node:child_process';+import { promisify } from 'node:util';+import { accessSync, constants } from 'node:fs';+import { createHash } from 'node:crypto';+import type { RemoteDesktopDisplayMode } from '@cindy/device-link';+import { WAYLAND_DISPLAY_ID } from './waylandCapture';++const exec = promisify(execFile);+const executable = '/usr/bin/hyprctl';+/** Only compositor-enumerated identifiers ever reach a subprocess argument. */+export interface LinuxMonitor {+ name: string;+ width: number;+ height: number;+ refreshRate: number;+ x: number;+ y: number;+ scale: number;+ transform: number;+ availableModes: string[];+}+export function supportsLinuxDisplay(): boolean {+ if (process.platform !== 'linux' || !process.env.HYPRLAND_INSTANCE_SIGNATURE) return false;+ try {+ accessSync(executable, constants.X_OK);+ return true;+ } catch {+ return false;+ }+}+export async function linuxMonitors(includeMirrored = false): Promise<LinuxMonitor[]> {+ const { stdout } = await exec(+ executable,+ ['-j', 'monitors', ...(includeMirrored ? ['all'] : [])],+ {+ timeout: 2000,+ maxBuffer: 128000,+ },+ );+ const value: unknown = JSON.parse(stdout);+ if (!Array.isArray(value) || value.length > 32) throw new Error('DESKTOP_DISPLAY_MISSING');+ return value.filter(+ (m): m is LinuxMonitor =>+ m &&+ typeof m.name === 'string' &&+ /^[A-Za-z0-9_.-]{1,80}$/.test(m.name) &&+ [m.width, m.height, m.x, m.y, m.transform].every(Number.isSafeInteger) &&+ m.width > 0 &&+ m.height > 0 &&+ m.width <= 16384 &&+ m.height <= 16384 &&+ Number.isFinite(m.scale) &&+ m.scale >= 0.25 &&+ m.scale <= 8 &&+ Number.isFinite(m.refreshRate) &&+ m.refreshRate > 0 &&+ m.refreshRate <= 1000 &&+ m.transform >= 0 &&+ m.transform <= 7 &&+ Array.isArray(m.availableModes) &&+ m.availableModes.length <= 256 &&+ m.availableModes.every(+ (mode: unknown) =>+ typeof mode === 'string' && /^\d{1,5}x\d{1,5}@\d{1,4}(\.\d{1,5})?Hz$/.test(mode),+ ),+ );+}+export async function linuxMonitor(+ displayId: string,+ includeMirrored = false,+): Promise<LinuxMonitor> {+ const monitors = await linuxMonitors(includeMirrored);+ const monitor =+ displayId === WAYLAND_DISPLAY_ID && monitors.length === 1+ ? monitors[0]+ : monitors.find((m) => `hyprland:${m.name}` === displayId);+ if (!monitor) throw new Error('DESKTOP_DISPLAY_MISSING');+ return monitor;+}+export function linuxDisplay(m: LinuxMonitor) {+ return {+ id: `hyprland:${m.name}`,+ name: m.name,+ width: Math.round((m.transform % 2 ? m.height : m.width) / m.scale),+ height: Math.round((m.transform % 2 ? m.width : m.height) / m.scale),+ };+}+/** Map a selected output into Hyprland's full logical layout, including negative origins. */+export function linuxInputMapping(monitors: LinuxMonitor[], displayId: string) {+ const selected = monitors.find((m) => linuxDisplay(m).id === displayId);+ if (!selected) throw new Error('DESKTOP_DISPLAY_MISSING');+ const left = Math.min(...monitors.map((m) => m.x)),+ top = Math.min(...monitors.map((m) => m.y));+ const width = Math.max(...monitors.map((m) => m.x + linuxDisplay(m).width)) - left;+ const height = Math.max(...monitors.map((m) => m.y + linuxDisplay(m).height)) - top;+ const size = linuxDisplay(selected);+ return (x: number, y: number) => ({+ x: (selected.x - left + x * (size.width - 1)) / width,+ y: (selected.y - top + y * (size.height - 1)) / height,+ });+}+export function linuxModeEntries(m: LinuxMonitor): (RemoteDesktopDisplayMode & { mode: string })[] {+ const rotated = m.transform % 2 === 1;+ return m.availableModes.map((mode) => {+ const [width, height, hz] = mode.replace('Hz', '').split(/[x@]/).map(Number);+ return {+ id: String(createHash('sha256').update(`${m.name}:${mode}`).digest().readUInt32BE(0)),+ width: Math.round((rotated ? height : width) / m.scale),+ height: Math.round((rotated ? width : height) / m.scale),+ current: width === m.width && height === m.height && Math.abs(hz - m.refreshRate) < 0.02,+ mode: mode.replace('Hz', ''),+ };+ });+}+export async function readLinuxDisplayModes(+ displayId: string,+): Promise<RemoteDesktopDisplayMode[]> {+ // Phone-fit mirrors the source onto a temporary output. Hyprland omits that+ // physical source from the active layout, but its native modes still exist.+ // Include it only for mode reads; capture and input must use the active layout.+ return linuxModeEntries(await linuxMonitor(displayId, true)).map(+ ({ id, width, height, current }) => ({ id, width, height, current }),+ );+}+export async function waitForLinuxDisplay(+ displayId: string,+ expected: { width: number; height: number } | undefined,+ current: () => void,+): Promise<void> {+ for (let attempt = 0; attempt < 40; attempt++) {+ current();+ const monitor = await linuxMonitor(displayId);+ current();+ const rotated = monitor.transform % 2 === 1;+ if (+ !expected ||+ (Math.round((rotated ? monitor.height : monitor.width) / monitor.scale) === expected.width &&+ Math.round((rotated ? monitor.width : monitor.height) / monitor.scale) === expected.height)+ )+ return;+ await new Promise((resolve) => setTimeout(resolve, 50));+ }+ throw new Error('DESKTOP_DISPLAY_MODE_MISSING');+}+export async function setLinuxDisplayMode(+ displayId: string,+ modeId: string,+ beforeChange: () => void,+): Promise<void> {+ const monitor = await linuxMonitor(displayId);+ const selected = linuxModeEntries(monitor).find((m) => m.id === modeId);+ if (!selected) throw new Error('DESKTOP_DISPLAY_MODE_MISSING');+ let lua = false;+ try {+ const probe = await exec(executable, ['eval', 'assert(type(hl.monitor) == "function")'], {+ timeout: 2000,+ maxBuffer: 1024,+ });+ lua = probe.stdout.trim() === 'ok';+ } catch {+ /* Older Hyprland uses the keyword interface. */+ }+ beforeChange();+ // Probe before the lease guard, then perform exactly one authorized write.+ const code = `hl.monitor({output=${JSON.stringify(monitor.name)},mode=${JSON.stringify(selected.mode)},position="${monitor.x}x${monitor.y}",scale=${monitor.scale},transform=${monitor.transform}})`;+ const args = lua+ ? ['eval', code]+ : [+ 'keyword',+ 'monitor',+ `${monitor.name},${selected.mode},${monitor.x}x${monitor.y},${monitor.scale},transform,${monitor.transform}`,+ ];+ const { stdout } = await exec(executable, args, { timeout: 3000, maxBuffer: 1024 });+ if (stdout.trim() !== 'ok') throw new Error('DESKTOP_DISPLAY_MODE_MISSING');+}++export function supportsLinuxLock(): boolean {+ if (+ process.platform !== 'linux' ||+ !/^[a-zA-Z0-9_-]{1,64}$/.test(process.env.XDG_SESSION_ID ?? '')+ )+ return false;+ try {+ accessSync('/usr/bin/loginctl', constants.X_OK);+ return true;+ } catch {+ return false;+ }+}+export async function lockLinuxDesktop(current: () => boolean, signal: AbortSignal): Promise<void> {+ if (!supportsLinuxLock()) throw new Error('DESKTOP_LOCK_UNAVAILABLE');+ const check = () => {+ if (!current() || signal.aborted) throw new Error('DESKTOP_LEASE_EXPIRED');+ };+ check();+ const session = process.env.XDG_SESSION_ID!;+ const shell = '/usr/bin/omarchy-shell';+ const status = async (): Promise<{ secure: boolean; passwordPam: boolean }> => {+ check();+ const { stdout } = await exec(shell, ['lock', 'status'], {+ timeout: 1000,+ signal,+ maxBuffer: 4096,+ });+ check();+ const value = JSON.parse(stdout);+ if (typeof value?.secure !== 'boolean' || typeof value?.passwordPam !== 'boolean')+ throw new Error('DESKTOP_LOCK_UNAVAILABLE');+ return value;+ };+ // Quickshell owns Omarchy's session lock. A logind request alone does not+ // invoke it, and LockedHint is not its compositor-lock acknowledgement.+ let omarchy: Awaited<ReturnType<typeof status>> | undefined;+ if (process.env.HYPRLAND_INSTANCE_SIGNATURE) {+ try {+ omarchy = await status();+ } catch {+ check();+ // Other Linux desktops continue using their logind listener.+ }+ }+ check();+ if (omarchy) {+ if (omarchy.secure) return;+ if (!omarchy.passwordPam) throw new Error('DESKTOP_LOCK_UNAVAILABLE');+ const { stdout } = await exec(shell, ['lock', 'lock'], {+ timeout: 1000,+ signal,+ maxBuffer: 128,+ });+ check();+ if (stdout.trim() !== 'ok') throw new Error('DESKTOP_LOCK_FAILED');+ const deadline = Date.now() + 2000;+ do {+ // "requested" / "locked" can precede the compositor acknowledgement.+ if ((await status()).secure) return;+ await new Promise((resolve) => setTimeout(resolve, 100));+ } while (Date.now() < deadline);+ check();+ throw new Error('DESKTOP_LOCK_FAILED');+ }+ await exec('/usr/bin/loginctl', ['lock-session', session], {+ timeout: 3000,+ signal,+ maxBuffer: 1024,+ });+ // logind only delivers a request; do not claim success unless the locker acts.+ for (let attempt = 0; attempt < 10; attempt++) {+ check();+ const { stdout } = await exec(+ '/usr/bin/loginctl',+ ['show-session', session, '-p', 'LockedHint', '--value'],+ { timeout: 1000, signal, maxBuffer: 128 },+ );+ check();+ if (stdout.trim() === 'yes') return;+ await new Promise((resolve) => setTimeout(resolve, 100));+ }+ throw new Error('DESKTOP_LOCK_FAILED');+}diff --git a/apps/desktop/src/main/remote-desktop/linuxInput.ts b/apps/desktop/src/main/remote-desktop/linuxInput.tsnew file mode 100644index 0000000000..ea9055561b--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxInput.ts@@ -0,0 +1,63 @@+import { app } from 'electron';+import { execFile } from 'node:child_process';+import { createHash } from 'node:crypto';+import fs from 'node:fs/promises';+import path from 'node:path';+import { promisify } from 'node:util';+import { isWaylandDesktop } from './waylandCapture';++const exec = promisify(execFile);+const binaryName = 'cindy-linux-desktop-input';+let building: Promise<string> | null = null;+export function resolveLinuxInputBinary(): Promise<string> {+ if (app.isPackaged)+ return Promise.resolve(path.join(process.resourcesPath, 'tools', 'remote-desktop', binaryName));+ if (building) return building;+ building = (async () => {+ const root = path.join(app.getAppPath(), 'native', 'remote-desktop', 'linux-input');+ const hash = createHash('sha256').update(process.arch);+ for (const name of [+ 'main.c',+ 'build.mjs',+ 'virtual-keyboard-unstable-v1.xml',+ 'wlr-virtual-pointer-unstable-v1.xml',+ ])+ hash.update(await fs.readFile(path.join(root, name)));+ const output = path.join(+ app.getPath('userData'),+ 'remote-desktop',+ 'native',+ hash.digest('hex'),+ );+ const binary = path.join(output, binaryName);+ try {+ await fs.access(binary, fs.constants.X_OK);+ return binary;+ } catch {+ /* build this source */+ }+ await exec('node', [path.join(root, 'build.mjs'), output], {+ timeout: 60000,+ maxBuffer: 64000,+ });+ return binary;+ })().finally(() => {+ building = null;+ });+ return building;+}++/** Probe registry support without creating devices or injecting input. */+export async function readLinuxDesktopInputSupport(): Promise<boolean> {+ if (!isWaylandDesktop(process.platform, process.env) || !process.env.HYPRLAND_INSTANCE_SIGNATURE)+ return false;+ try {+ const { stdout } = await exec(await resolveLinuxInputBinary(), ['--check'], {+ timeout: 3000,+ maxBuffer: 1024,+ });+ return stdout.trim() === 'ready';+ } catch {+ return false;+ }+}diff --git a/apps/desktop/src/main/remote-desktop/linuxMute.ts b/apps/desktop/src/main/remote-desktop/linuxMute.tsnew file mode 100644index 0000000000..7a5e4e5b32--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxMute.ts@@ -0,0 +1,89 @@+import { execFile } from 'node:child_process';+import { accessSync, constants } from 'node:fs';+import { promisify } from 'node:util';++const exec = promisify(execFile);+export function supportsLinuxMute(): boolean {+ if (process.platform !== 'linux') return false;+ try {+ for (const tool of ['pactl', 'pw-dump', 'pw-cli'])+ accessSync(`/usr/bin/${tool}`, constants.X_OK);+ return true;+ } catch {+ return false;+ }+}+interface Sink {+ id: number;+ serial: number;+ name: string;+ muted: boolean;+}+/** Mute playback only, leaving the monitor branch audible remotely. Object+ * serial protects against numeric ID reuse after unplug. Writes are serialized. */+export class LinuxDesktopMute {+ private original: Sink | null = null;+ private tail: Promise<void> = Promise.resolve();+ constructor(+ private readonly run = async (tool: string, args: string[]) => {+ const { stdout } = await exec(`/usr/bin/${tool}`, args, {+ timeout: 2000,+ maxBuffer: 4 * 1024 * 1024,+ });+ return stdout;+ },+ ) {}+ private async sinks(): Promise<Sink[]> {+ const nodes: unknown = JSON.parse(await this.run('pw-dump', []));+ if (!Array.isArray(nodes) || nodes.length > 10000)+ throw new Error('DESKTOP_HOST_MUTE_UNAVAILABLE');+ return nodes.flatMap((node) => {+ const props = node?.info?.props;+ const params = node?.info?.params?.Props;+ const mute = Array.isArray(params)+ ? params.find((p) => typeof p?.softMute === 'boolean')+ : undefined;+ const serial = Number(props?.['object.serial']);+ return Number.isSafeInteger(node?.id) &&+ node.id > 0 &&+ Number.isSafeInteger(serial) &&+ serial > 0 &&+ props?.['media.class'] === 'Audio/Sink' &&+ typeof props['node.name'] === 'string' &&+ mute+ ? [{ id: node.id, serial, name: props['node.name'], muted: mute.softMute }]+ : [];+ });+ }+ set(enabled: boolean): Promise<void> {+ const result = this.tail+ .then(async () => {+ if (!enabled && !this.original) return;+ const sinks = await this.sinks();+ if (!this.original) {+ const name = (await this.run('pactl', ['get-default-sink'])).trim();+ const sink = sinks.find((s) => s.name === name);+ if (!sink) throw new Error('DESKTOP_HOST_MUTE_UNAVAILABLE');+ this.original = sink;+ }+ const original = this.original;+ if (!sinks.some((s) => s.id === original.id && s.serial === original.serial)) {+ this.original = null;+ if (enabled) throw new Error('DESKTOP_HOST_MUTE_UNAVAILABLE');+ return;+ }+ await this.run('pw-cli', [+ 'set-param',+ String(original.id),+ 'Props',+ `{ softMute: ${enabled || original.muted ? 'true' : 'false'} }`,+ ]);+ if (!enabled) this.original = null;+ })+ .catch(() => {+ throw new Error('DESKTOP_HOST_MUTE_UNAVAILABLE');+ });+ this.tail = result.catch(() => {});+ return result;+ }+}diff --git a/apps/desktop/src/main/remote-desktop/linuxPrivacy.ts b/apps/desktop/src/main/remote-desktop/linuxPrivacy.tsnew file mode 100644index 0000000000..9c5618b461--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxPrivacy.ts@@ -0,0 +1,236 @@+import { app, nativeTheme } from 'electron';+import { execFile } from 'node:child_process';+import { createHash, randomBytes } from 'node:crypto';+import fs from 'node:fs/promises';+import path from 'node:path';+import { promisify } from 'node:util';+import { t } from '../i18n';++const exec = promisify(execFile);+async function run(args: string[]): Promise<string> {+ const { stdout } = await exec('/usr/bin/hyprctl', args, { timeout: 3000, maxBuffer: 16384 });+ return stdout.trim();+}+async function version() {+ const value = JSON.parse(await run(['-j', 'version']));+ if (value.version !== '0.56.2' || !/^[a-f0-9]{40}$/.test(value.commit) || value.dirty)+ throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ return value;+}+export async function supportsLinuxPrivacy(): Promise<boolean> {+ if (process.platform !== 'linux' || !process.env.HYPRLAND_INSTANCE_SIGNATURE) return false;+ try {+ const current = await version();+ if (app.isPackaged) {+ const meta = JSON.parse(+ await fs.readFile(+ path.join(+ process.resourcesPath,+ 'tools',+ 'remote-desktop',+ 'cindy-hyprland-privacy.json',+ ),+ 'utf8',+ ),+ );+ return meta.hash === current.commit;+ }+ const header = await fs.readFile('/usr/include/hyprland/src/version.h', 'utf8');+ return header.includes(`"${current.commit}"`);+ } catch {+ return false;+ }+}+export async function prepareLinuxPrivacy(+ currentOwner: () => boolean,+ allowLoad = false,+): Promise<void> {+ const current = await version();+ const source = path.join(app.getAppPath(), 'native', 'remote-desktop', 'hyprland-privacy');+ let directory = path.join(process.resourcesPath, 'tools', 'remote-desktop');+ if (!app.isPackaged) {+ const hash = createHash('sha256').update(current.abiHash).update(process.arch);+ for (const file of ['main.cpp', 'gate.hpp', 'build.mjs'])+ hash.update(await fs.readFile(path.join(source, file)));+ for (const file of ['illustration.webp', 'wordmark.png', 'wordmark-light.png'])+ hash.update(+ await fs.readFile(path.join(source, '../../../src/renderer/assets/splash', file)),+ );+ directory = path.join(app.getPath('userData'), 'remote-desktop', 'native', hash.digest('hex'));+ try {+ await fs.access(path.join(directory, 'cindy-hyprland-privacy.json'));+ } catch {+ await exec('node', [path.join(source, 'build.mjs'), directory], {+ timeout: 120000,+ maxBuffer: 64000,+ });+ }+ }+ const meta = JSON.parse(+ await fs.readFile(path.join(directory, 'cindy-hyprland-privacy.json'), 'utf8'),+ );+ if (meta.hash !== current.commit) throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ // Hyprland reloads configuration after plugin load/unload. Install only+ // before a lease exists, never while a temporary viewer layout is active.+ const identity = `ready:${meta.source}`;+ const existing = await run(['cindy-privacy', '{"op":"probe"}']).catch(() => '');+ if (!currentOwner()) throw new Error('DESKTOP_LEASE_EXPIRED');+ if (existing !== identity && !allowLoad) throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ if (existing.startsWith('ready:') && existing !== identity) {+ // The old plugin atomically refuses retirement while owned and refuses new+ // owners after retirement. Never unload another connection's active mask.+ const retired = await run(['cindy-privacy', '{"op":"retire"}']);+ if (!path.isAbsolute(retired) || !retired.endsWith('/cindy-hyprland-privacy.so'))+ throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ await run(['plugin', 'unload', retired]);+ }+ if (existing !== identity) {+ if (!currentOwner()) throw new Error('DESKTOP_LEASE_EXPIRED');+ await run(['plugin', 'load', path.join(directory, 'cindy-hyprland-privacy.so')]);+ }+ const deadline = Date.now() + 3000;+ let state = await run(['cindy-privacy', '{"op":"probe"}']);+ while (state === `loading:${meta.source}` && Date.now() < deadline && currentOwner()) {+ await new Promise((resolve) => setTimeout(resolve, 25));+ state = await run(['cindy-privacy', '{"op":"probe"}']);+ }+ if (state !== identity || !currentOwner()) throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+}+interface Runtime {+ prepare(): Promise<void>;+ call(request: Record<string, unknown>): Promise<string>;+ labels(): string[];+}+const runtime: Runtime = {+ prepare: () => prepareLinuxPrivacy(() => true),+ call: (request) => run(['cindy-privacy', JSON.stringify(request)]),+ labels: () =>+ ['status', 'hint', 'title', 'detail', 'cancel', 'disconnect'].map((key) =>+ t(`privacyExit.${key}`),+ ),+};++/** The compositor owns masking/input exclusion and a six-second owner watchdog.+ * This adapter reuses the controller's lease and input-pause lifecycle. It never+ * creates a second viewer, changes system config or handles passwords. */+export class LinuxPrivacyScreen {+ private generation = 0;+ private token: string | null = null;+ private timer?: ReturnType<typeof setTimeout>;+ private resume?: () => Promise<void>;+ private pausing?: Promise<() => Promise<void>>;+ private cleanup: Promise<unknown> = Promise.resolve();+ get active(): boolean {+ return this.token !== null;+ }+ constructor(+ private readonly stopped: () => void | Promise<void>,+ private readonly suspendInput: () => Promise<() => Promise<void>>,+ private readonly native: Runtime = runtime,+ ) {}+ async set(enabled: boolean, current: () => boolean): Promise<void> {+ if (!enabled) {+ const resuming = this.pausing ?? Promise.resolve(this.resume);+ this.stop();+ await this.cleanup;+ const resume = await resuming;+ if (current()) await resume?.();+ return;+ }+ if (this.token && current()) return;+ const generation = ++this.generation;+ const valid = () => generation === this.generation && current();+ await this.cleanup;+ await this.native.prepare();+ if (!valid()) throw new Error('DESKTOP_LEASE_EXPIRED');+ const token = randomBytes(16).toString('hex');+ this.token = token;+ try {+ let state = await this.native.call({+ op: 'start',+ token,+ labels: this.native.labels(),+ dark: nativeTheme.shouldUseDarkColors,+ });+ // Do not acknowledge privacy until each powered display has rendered its+ // first mask. A disconnected/stalled output fails the toggle closed.+ const deadline = Date.now() + 2000;+ while (state === 'starting' && valid() && Date.now() < deadline) {+ await new Promise((resolve) => setTimeout(resolve, 25));+ state = await this.native.call({ op: 'ping', token });+ }+ if (!valid()) throw new Error('DESKTOP_LEASE_EXPIRED');+ if (state !== 'active') throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ this.schedule(generation, current);+ } catch (error) {+ if (this.token === token) this.stop();+ else {+ // A stop may have reached the compositor before this late start. Retire+ // the old owner again after its reply, without touching a replacement.+ this.cleanup = this.native.call({ op: 'stop', token }).catch(() => {});+ await this.cleanup;+ }+ throw error;+ }+ }+ private schedule(generation: number, current: () => boolean): void {+ this.timer = setTimeout(() => {+ void this.poll(generation, current);+ }, 250);+ this.timer.unref();+ }+ private async poll(generation: number, current: () => boolean): Promise<void> {+ const token = this.token;+ const valid = () =>+ !!token && this.token === token && generation === this.generation && current();+ if (!valid()) {+ if (generation === this.generation) this.stop();+ return;+ }+ try {+ const state = await this.native.call({ op: 'ping', token });+ if (!valid()) return;+ if (state === 'pending') {+ const pausing = this.suspendInput();+ this.pausing = pausing;+ const resume = await pausing;+ if (this.pausing === pausing) this.pausing = undefined;+ if (!valid()) return;+ this.resume = resume;+ if ((await this.native.call({ op: 'confirm', token })) !== 'confirming')+ throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ } else if (state === 'resume') {+ await this.resume?.();+ if (!valid()) return;+ this.resume = undefined;+ if ((await this.native.call({ op: 'resume', token })) !== 'active')+ throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ } else if (state === 'disconnect') {+ await this.finish(generation);+ return;+ } else if (state !== 'active' && state !== 'confirming')+ throw new Error('DESKTOP_PRIVACY_UNAVAILABLE');+ if (valid()) this.schedule(generation, current);+ } catch {+ if (valid()) await this.finish(generation);+ }+ }+ private async finish(generation: number): Promise<void> {+ try {+ await this.stopped();+ } catch {+ /* Native watchdog also releases the mask. */+ } finally {+ if (generation === this.generation) this.stop();+ }+ }+ stop(): void {+ this.generation++;+ clearTimeout(this.timer);+ this.resume = undefined;+ this.pausing = undefined;+ const token = this.token;+ this.token = null;+ if (token) this.cleanup = this.native.call({ op: 'stop', token }).catch(() => {});+ }+}diff --git a/apps/desktop/src/main/remote-desktop/linuxViewerDisplay.ts b/apps/desktop/src/main/remote-desktop/linuxViewerDisplay.tsnew file mode 100644index 0000000000..f42e2cd458--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxViewerDisplay.ts@@ -0,0 +1,152 @@+import { app } from 'electron';+import { spawn } from 'node:child_process';+import { accessSync, constants } from 'node:fs';+import path from 'node:path';+import type { RemoteDesktopDisplay } from '@cindy/device-link';+import type { ViewerDisplayHandle } from './viewerDisplay';+import { linuxDisplay, linuxMonitor, linuxMonitors, supportsLinuxDisplay } from './linuxDesktop';++function script(): string {+ return app.isPackaged+ ? path.join(process.resourcesPath, 'tools', 'remote-desktop', 'linux-viewer-display.py')+ : path.join(app.getAppPath(), 'native', 'remote-desktop', 'linux-viewer-display.py');+}+export function supportsLinuxViewerDisplay(): boolean {+ if (!supportsLinuxDisplay()) return false;+ try {+ accessSync('/usr/bin/python3', constants.X_OK);+ accessSync(script(), constants.R_OK);+ return true;+ } catch {+ return false;+ }+}++/** The independent helper undoes its temporary mirror even when Electron exits.+ * This adapts the existing viewer-display lease, not a second display lifecycle. */+export async function createLinuxViewerDisplay(+ sourceId: string,+ isCurrent: () => boolean,+ onFailure: () => void,+): Promise<ViewerDisplayHandle> {+ if (!supportsLinuxViewerDisplay()) throw new Error('DESKTOP_VIEWER_DISPLAY_UNAVAILABLE');+ const original = await linuxMonitor(sourceId);+ if (!isCurrent()) throw new Error('DESKTOP_LEASE_EXPIRED');+ const child = spawn('/usr/bin/python3', ['-I', '-u', script(), original.name], { stdio: 'pipe' });+ let closed = false,+ busy = false;+ let id: string | undefined;+ const failed = () => {+ if (!closed) {+ dispose();+ onFailure();+ }+ };+ child.stderr.resume();+ child.stdin.on('error', failed);+ child.once('error', failed);+ child.once('exit', failed);+ const exited = new Promise<number | null>((resolve) => {+ child.once('exit', resolve);+ child.once('error', () => resolve(1));+ });+ const heartbeat = setInterval(() => {+ if (!closed && !child.stdin.destroyed) child.stdin.write('{"op":"ping"}\n');+ }, 2000);+ heartbeat.unref();+ const dispose = () => {+ if (closed) return;+ closed = true;+ clearInterval(heartbeat);+ child.stdin.end();+ // SIGTERM runs the same restoration finally block; never SIGKILL a helper+ // that may still own a mirrored physical display.+ const timer = setTimeout(() => child.kill('SIGTERM'), 10000);+ timer.unref();+ void exited.then(() => clearTimeout(timer));+ };+ return {+ get displayId() {+ return id;+ },+ async resize(width, height, current) {+ if (closed || !current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ if (busy) throw new Error('DESKTOP_DISPLAY_BUSY');+ busy = true;+ try {+ const result = await new Promise<RemoteDesktopDisplay>((resolve, reject) => {+ let buffer = '';+ const finish = (result?: RemoteDesktopDisplay) => {+ clearTimeout(timer);+ child.stdout.off('data', receive);+ child.off('exit', ended);+ child.off('error', ended);+ if (result) resolve(result);+ else reject(new Error('DESKTOP_VIEWER_DISPLAY_UNAVAILABLE'));+ };+ const ended = () => finish();+ const receive = (chunk: Buffer) => {+ buffer += chunk.toString();+ if (buffer.length > 4096) return finish();+ if (!buffer.includes('\n')) return;+ try {+ const value = JSON.parse(buffer);+ if (+ typeof value.id !== 'string' ||+ !/^hyprland:CindyRemote-[a-f0-9]{16}$/.test(value.id) ||+ value.width !== width ||+ value.height !== height ||+ typeof value.name !== 'string'+ )+ return finish();+ finish(value);+ } catch {+ finish();+ }+ };+ const timer = setTimeout(ended, 8000);+ child.stdout.on('data', receive);+ child.once('exit', ended);+ child.once('error', ended);+ child.stdin.write(JSON.stringify({ width, height }) + '\n');+ });+ if (closed || !current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ id = result.id;+ const actual = linuxDisplay(await linuxMonitor(id));+ if (!current() || closed) throw new Error('DESKTOP_LEASE_EXPIRED');+ if (actual.width !== width || actual.height !== height)+ throw new Error('DESKTOP_VIEWER_DISPLAY_UNAVAILABLE');+ return actual;+ } catch (error) {+ dispose();+ throw error;+ } finally {+ busy = false;+ }+ },+ async restore(current) {+ dispose();+ let timer: ReturnType<typeof setTimeout> | undefined;+ try {+ const code = await Promise.race([+ exited,+ new Promise<never>((_, reject) => {+ timer = setTimeout(+ () => reject(new Error('DESKTOP_VIEWER_DISPLAY_UNAVAILABLE')),+ 12000,+ );+ }),+ ]);+ if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ if (code !== 0) throw new Error('DESKTOP_VIEWER_DISPLAY_UNAVAILABLE');+ const monitors = await linuxMonitors();+ if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ // An unplugged source has no remaining geometry to restore.+ return linuxDisplay(monitors.find((m) => m.name === original.name) ?? original);+ } finally {+ clearTimeout(timer);+ }+ },+ dispose,+ };+}diff --git a/apps/desktop/src/main/remote-desktop/linuxWindowActions.ts b/apps/desktop/src/main/remote-desktop/linuxWindowActions.tsnew file mode 100644index 0000000000..6a131cc8e3--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/linuxWindowActions.ts@@ -0,0 +1,167 @@+import { execFile } from 'node:child_process';+import { randomBytes } from 'node:crypto';+import { accessSync, constants } from 'node:fs';+import { promisify } from 'node:util';+import type { RemoteDesktopWindow } from '@cindy/device-link';+import { linuxMonitor } from './linuxDesktop';++const exec = promisify(execFile);+export function supportsOmarchyMenu(): boolean {+ if (process.platform !== 'linux') return false;+ try {+ accessSync('/usr/bin/omarchy', constants.X_OK);+ accessSync('/usr/bin/omarchy-menu', constants.X_OK);+ return true;+ } catch {+ return false;+ }+}+async function openOmarchyMenu(): Promise<void> {+ if (!supportsOmarchyMenu()) throw new Error('DESKTOP_INPUT_UNSUPPORTED');+ await exec('/usr/bin/omarchy', ['menu', 'summon'], { timeout: 2000, maxBuffer: 16384 });+}+const invoke = async (args: string[]): Promise<string> => {+ const { stdout } = await exec('/usr/bin/hyprctl', args, { timeout: 2000, maxBuffer: 512000 });+ return stdout.trim();+};+type Monitor = { name: string; activeWorkspace: { id: number; name: string } };+/** Host actions never depend on the user's key bindings. A temporary empty+ * workspace preserves window positions; only our still-selected workspace is+ * restored, so local navigation is never undone on disconnect. */+export class LinuxWindowActions {+ private tail: Promise<unknown> = Promise.resolve();+ private generation = 0;+ private lua?: boolean;+ private desktop?: { monitor: string; original: number; temporary: string };+ constructor(+ private readonly run = invoke,+ private readonly monitor = linuxMonitor,+ private readonly openMenu = openOmarchyMenu,+ ) {}+ private async clients(): Promise<RemoteDesktopWindow[]> {+ const value: unknown = JSON.parse(await this.run(['-j', 'clients']));+ if (!Array.isArray(value) || value.length > 2048) throw new Error('DESKTOP_INPUT_UNAVAILABLE');+ return value+ .filter(+ (w) =>+ w?.mapped &&+ !w.hidden &&+ /^0x[a-f0-9]{1,16}$/.test(w.address) &&+ typeof w.title === 'string' &&+ typeof w.class === 'string',+ )+ .slice(0, 256)+ .map((w) => ({ id: w.address, title: w.title.slice(0, 256), app: w.class.slice(0, 128) }));+ }+ private async dispatch(+ name: 'focuswindow' | 'focusmonitor' | 'workspace',+ value: string,+ check: () => void = () => {},+ ): Promise<void> {+ // Hyprland 0.55+ uses typed Lua dispatchers. Probe syntax without changing+ // configuration; never retry an already-issued action with another syntax.+ this.lua ??= await this.run(['eval', 'assert(type(hl.dsp.focus) == "function")']).then(+ (value) => value === 'ok',+ () => false,+ );+ check();+ const field = { focuswindow: 'window', focusmonitor: 'monitor', workspace: 'workspace' }[name];+ if (!field || !/^[A-Za-z0-9_.:+-]{1,128}$/.test(value))+ throw new Error('DESKTOP_INPUT_UNAVAILABLE');+ const luaValue =+ name === 'workspace' && /^[1-9][0-9]*$/.test(value) ? value : JSON.stringify(value);+ const args = this.lua+ ? ['eval', `hl.dispatch(hl.dsp.focus({${field}=${luaValue}}))`]+ : ['dispatch', name, value];+ if ((await this.run(args)) !== 'ok') throw new Error('DESKTOP_INPUT_UNAVAILABLE');+ }+ async request(+ action: 'list' | 'activate' | 'desktop' | 'workspaceLeft' | 'workspaceRight' | 'omarchyMenu',+ id: string | undefined,+ displayId: string,+ current: () => boolean,+ ): Promise<RemoteDesktopWindow[] | null> {+ const generation = this.generation;+ const check = () => {+ if (generation !== this.generation || !current()) throw new Error('DESKTOP_LEASE_EXPIRED');+ };+ const operation = this.tail+ .catch(() => {})+ .then(async () => {+ check();+ if (action === 'list') {+ const windows = await this.clients();+ check();+ return windows;+ }+ if (action === 'activate') {+ const windows = await this.clients();+ check();+ if (!windows.some((window) => window.id === id))+ throw new Error('DESKTOP_INPUT_UNAVAILABLE');+ await this.restore();+ check();+ await this.dispatch('focuswindow', `address:${id}`);+ check();+ return null;+ }+ if (action === 'workspaceLeft' || action === 'workspaceRight' || action === 'omarchyMenu') {+ await this.restore();+ check();+ const selected = await this.monitor(displayId);+ check();+ await this.dispatch('focusmonitor', selected.name, check);+ check();+ if (action === 'omarchyMenu') await this.openMenu();+ else await this.dispatch('workspace', action === 'workspaceLeft' ? 'm-1' : 'm+1', check);+ check();+ return null;+ }+ if (this.desktop) {+ await this.restore();+ check();+ return null;+ }+ const selected = await this.monitor(displayId);+ check();+ const monitors: Monitor[] = JSON.parse(await this.run(['-j', 'monitors']));+ check();+ const target = monitors.find((m) => m.name === selected.name);+ if (+ !target ||+ !Number.isSafeInteger(target.activeWorkspace?.id) ||+ target.activeWorkspace.id <= 0+ )+ throw new Error('DESKTOP_INPUT_UNAVAILABLE');+ this.desktop = {+ monitor: target.name,+ original: target.activeWorkspace.id,+ temporary: `cindy-desktop-${randomBytes(8).toString('hex')}`,+ };+ await this.dispatch('focusmonitor', target.name);+ check();+ await this.dispatch('workspace', `name:${this.desktop.temporary}`);+ check();+ return null;+ });+ this.tail = operation;+ return operation;+ }+ private async restore(): Promise<void> {+ const saved = this.desktop;+ if (!saved) return;+ const monitors: Monitor[] = JSON.parse(await this.run(['-j', 'monitors']));+ const selected = monitors.find((m) => m.name === saved.monitor);+ if (selected?.activeWorkspace.name === saved.temporary) {+ await this.dispatch('focusmonitor', saved.monitor);+ await this.dispatch('workspace', String(saved.original));+ }+ this.desktop = undefined;+ }+ stop(): Promise<void> {+ this.generation++;+ const stopped = this.tail.catch(() => {}).then(() => this.restore());+ this.tail = stopped;+ return stopped;+ }+}diff --git a/apps/desktop/src/main/remote-desktop/nativeCapture.ts b/apps/desktop/src/main/remote-desktop/nativeCapture.tsindex 7f69ce181d..841014ee52 100644--- a/apps/desktop/src/main/remote-desktop/nativeCapture.ts+++ b/apps/desktop/src/main/remote-desktop/nativeCapture.ts@@ -12,10 +12,15 @@ import { promisify } from 'node:util';import { openWindowsDesktopConnection, type WindowsDesktopConnection } from './windowsHost';import { decodeWindowsCursorFrame } from './windowsCursorFrame';+import { resolveLinuxCaptureBinary } from './linuxCapture';+import { WAYLAND_DISPLAY_ID } from './waylandCapture';+import { linuxMonitor } from './linuxDesktop';+const exec = promisify(execFile);const name = 'cindy-macos-desktop-capture';let building: Promise<string> | null = null;async function binary(): Promise<string> {+ if (process.platform === 'linux') return resolveLinuxCaptureBinary();if (app.isPackaged) return path.join(process.resourcesPath, 'tools', 'remote-desktop', name);if (building) return building;building = (async () => {@@ -80,8 +85,8 @@ async function binary(): Promise<string> {}/** One capture child for the current lease. No sockets, files, or frame history.- * macOS uses a user-session child; Windows uses the authorized SYSTEM broker.- * Neither adapter keeps frame history on disk.+ * macOS/Linux use user-session children; Windows uses the authorized SYSTEM broker.+ * No adapter keeps frame history on disk.*/export class NativeDesktopCapture {private excludedWindows = '';@@ -141,8 +146,9 @@ export class NativeDesktopCapture {const jpeg = (await this.windows.request('f')).trim();if (generation !== this.generation) return null;if (overlay) {- return decodeWindowsCursorFrame(jpeg, selected.scaleFactor,- (pixels, size) => nativeImage.createFromBitmap(pixels, size).toPNG());+ return decodeWindowsCursorFrame(jpeg, selected.scaleFactor, (pixels, size) =>+ nativeImage.createFromBitmap(pixels, size).toPNG(),+ );}return generation === this.generation &&jpeg.length <= 240000 &&@@ -156,23 +162,40 @@ export class NativeDesktopCapture {if (generation === this.generation) this.busy = false;}}- const config = overlay ? [settings?.fps ?? 30, settings?.bitrate ?? 0].join(':') : '';+ const config =+ overlay || process.platform === 'linux'+ ? [overlay, settings?.fps ?? 30, settings?.bitrate ?? 0].join(':')+ : '';if (this.child && this.config !== config) this.stop();- if (process.platform !== 'darwin' || !/^[0-9]{1,10}$/.test(display)) return null;+ const linux = process.platform === 'linux';+ if (+ linux+ ? display !== WAYLAND_DISPLAY_ID && !/^hyprland:[A-Za-z0-9_.-]{1,80}$/.test(display)+ : process.platform !== 'darwin' || !/^[0-9]{1,10}$/.test(display)+ )+ return null;if (this.busy) return null;if (this.display && this.display !== display) this.stop();this.busy = true;const generation = this.generation;try {if (!this.child) {+ const output = linux && display !== WAYLAND_DISPLAY_ID ? await linuxMonitor(display) : null;const executable = await binary();if (generation !== this.generation) return null;const quality =settings?.bitrate === 20_000_000 ? 0.95 : settings?.bitrate === 8_000_000 ? 0.8 : 0.65;- const args = overlay- ? [display, 'cursor-overlay', String(settings?.fps ?? 30), String(quality)]- : [display];- if (this.excludedWindows) args.push(this.excludedWindows);+ const args = linux+ ? [+ overlay ? 'cursor-overlay' : 'video',+ String(output?.scale ?? screen.getAllDisplays()[0]?.scaleFactor ?? 1),+ String(Math.round(quality * 100)),+ ...(output ? [output.name] : []),+ ]+ : overlay+ ? [display, 'cursor-overlay', String(settings?.fps ?? 30), String(quality)]+ : [display];+ if (!linux && this.excludedWindows) args.push(this.excludedWindows);const child = spawn(executable, args, { stdio: 'pipe' });this.child = child;this.display = display;@@ -208,7 +231,7 @@ export class NativeDesktopCapture {};const receive = (chunk: Buffer) => {text += chunk.toString('ascii');- if (text.length > (overlay ? 1_500_000 : 240_001)) {+ if (text.length > (overlay || linux ? 1_500_000 : 240_001)) {this.stop();return;}diff --git a/apps/desktop/src/main/remote-desktop/viewerDisplay.ts b/apps/desktop/src/main/remote-desktop/viewerDisplay.tsindex 7fb3f47407..daafbb3c86 100644--- a/apps/desktop/src/main/remote-desktop/viewerDisplay.ts+++ b/apps/desktop/src/main/remote-desktop/viewerDisplay.ts@@ -5,12 +5,14 @@ import fs from 'node:fs/promises';import path from 'node:path';import { promisify } from 'node:util';import type { RemoteDesktopDisplay } from '@cindy/device-link';+import { createLinuxViewerDisplay, supportsLinuxViewerDisplay } from './linuxViewerDisplay';const exec = promisify(execFile);let build: Promise<string> | undefined;/** Prototype only: SPI is not shipped until supported OS/signing tests are complete. */export async function viewerDisplaySupported(): Promise<boolean> {+ if (process.platform === 'linux') return supportsLinuxViewerDisplay();try {await binary();return true;@@ -114,6 +116,8 @@ export async function createViewerDisplay(isCurrent: () => boolean,onFailure: () => void,): Promise<ViewerDisplayHandle> {+ if (process.platform === 'linux')+ return createLinuxViewerDisplay(sourceDisplayId, isCurrent, onFailure);const executable = await binary();if (!isCurrent()) throw new Error('DESKTOP_LEASE_EXPIRED');const child: ChildProcessWithoutNullStreams = spawn(executable, [], { stdio: 'pipe' });diff --git a/apps/desktop/src/main/remote-desktop/waylandCapture.ts b/apps/desktop/src/main/remote-desktop/waylandCapture.tsnew file mode 100644index 0000000000..22d1020e88--- /dev/null+++ b/apps/desktop/src/main/remote-desktop/waylandCapture.ts@@ -0,0 +1,30 @@+/** PipeWire selects one surface interactively; it does not enumerate monitors. */+export const WAYLAND_DISPLAY_ID = 'wayland-portal';+export function isWaylandDesktop(+ platform: string,+ env: Record<string, string | undefined>,+): boolean {+ return (+ platform === 'linux' && (env.XDG_SESSION_TYPE === 'wayland' || Boolean(env.WAYLAND_DISPLAY))+ );+}++/** Do not guess a physical monitor from an empty display_id or an array position. */+export function selectPortalSource<T extends { id: string }>(sources: readonly T[]): T | null {+ return sources.length === 1 && sources[0].id.startsWith('screen:') ? sources[0] : null;+}++/** Native screencopy covers the union of all outputs, including gaps between+ * monitors. Preserve that aspect ratio in the lease: video contains its pixels+ * inside this box while the JPEG backing layer fills it.+ */+export function waylandDesktopSize(+ displays: readonly { bounds: { x: number; y: number; width: number; height: number } }[],+): { width: number; height: number } {+ const bounds = displays.map((display) => display.bounds);+ if (!bounds.length) return { width: 1280, height: 720 };+ return {+ width: Math.max(...bounds.map((b) => b.x + b.width)) - Math.min(...bounds.map((b) => b.x)),+ height: Math.max(...bounds.map((b) => b.y + b.height)) - Math.min(...bounds.map((b) => b.y)),+ };+}diff --git a/apps/desktop/src/preload/desktopCapturePreload.ts b/apps/desktop/src/preload/desktopCapturePreload.tsindex 4c343b7385..670d204528 100644--- a/apps/desktop/src/preload/desktopCapturePreload.ts+++ b/apps/desktop/src/preload/desktopCapturePreload.ts@@ -23,6 +23,7 @@ const api: DesktopCaptureApi = {ipcRenderer.invoke(DESKTOP_LOCAL.INPUT, lease, sequence, events),viewHeartbeat: (lease) => ipcRenderer.invoke(DESKTOP_LOCAL.VIEW_HEARTBEAT, lease),nativeFrame: (lease) => ipcRenderer.invoke(DESKTOP_LOCAL.NATIVE_FRAME, lease),+ nativeAudio: (lease) => ipcRenderer.invoke(DESKTOP_LOCAL.NATIVE_AUDIO, lease),};if (location.search === '?mode=files') {const files: FilePeerHostApi = {diff --git a/apps/desktop/src/renderer/features/remote-desktop/__tests__/nativeAudioStream.test.ts b/apps/desktop/src/renderer/features/remote-desktop/__tests__/nativeAudioStream.test.tsnew file mode 100644index 0000000000..83c16ec67c--- /dev/null+++ b/apps/desktop/src/renderer/features/remote-desktop/__tests__/nativeAudioStream.test.ts@@ -0,0 +1,70 @@+import { afterEach, expect, it, vi } from 'vitest';+import { nativeAudioStream } from '../nativeAudioStream';++afterEach(() => {+ vi.unstubAllGlobals();+ vi.useRealTimers();+});+function setup() {+ vi.useFakeTimers();+ const track = { stop: vi.fn() };+ const close = vi.fn(async () => {});+ const channels: Float32Array[] = [];+ const nodes: { stop: ReturnType<typeof vi.fn>; start: ReturnType<typeof vi.fn> }[] = [];+ vi.stubGlobal(+ 'AudioContext',+ class {+ currentTime = 0;+ close = close;+ async resume() {}+ createMediaStreamDestination() {+ return { stream: { getTracks: () => [track], getAudioTracks: () => [track] } };+ }+ createBuffer(_channels: number, frames: number) {+ const data = [new Float32Array(frames), new Float32Array(frames)];+ channels.push(...data);+ return { getChannelData: (channel: number) => data[channel] };+ }+ createBufferSource() {+ const node = { connect: vi.fn(), disconnect: vi.fn(), stop: vi.fn(), start: vi.fn() };+ nodes.push(node);+ return node;+ }+ },+ );+ return { track, close, channels, nodes };+}+it('deinterleaves bounded stereo PCM and erases sources and polling on stop', async () => {+ const h = setup();+ const pcm = new Uint8Array(new Float32Array([0.5, -0.25, NaN, 2]).buffer);+ const read = vi.fn(async () => pcm);+ const owner = await nativeAudioStream(read, () => true, vi.fn());+ expect([...h.channels[0]]).toEqual([0.5, 0]);+ expect([...h.channels[1]]).toEqual([-0.25, 1]);+ owner.stop();+ await vi.advanceTimersByTimeAsync(100);+ expect(read).toHaveBeenCalledOnce();+ expect(h.track.stop).toHaveBeenCalledOnce();+ expect(h.nodes[0].stop).toHaveBeenCalledOnce();+ expect(h.close).toHaveBeenCalledOnce();+});+it('discards a read that completes after authorization ends', async () => {+ const h = setup();+ let valid = true;+ let finish!: (value: Uint8Array) => void;+ const pending = nativeAudioStream(+ () =>+ new Promise((resolve) => {+ finish = resolve;+ }),+ () => valid,+ vi.fn(),+ );+ const rejected = expect(pending).rejects.toThrow('DESKTOP_AUDIO_UNAVAILABLE');+ await Promise.resolve();+ valid = false;+ finish(new Uint8Array(80));+ await rejected;+ expect(h.nodes).toHaveLength(0);+ expect(h.close).toHaveBeenCalledOnce();+});diff --git a/apps/desktop/src/renderer/features/remote-desktop/__tests__/nativeCaptureStream.test.ts b/apps/desktop/src/renderer/features/remote-desktop/__tests__/nativeCaptureStream.test.tsnew file mode 100644index 0000000000..ef14b9effa--- /dev/null+++ b/apps/desktop/src/renderer/features/remote-desktop/__tests__/nativeCaptureStream.test.ts@@ -0,0 +1,87 @@+// @vitest-environment jsdom+import { afterEach, expect, it, vi } from 'vitest';+import { nativeCaptureStream } from '../nativeCaptureStream';+afterEach(() => {+ vi.restoreAllMocks();+ vi.unstubAllGlobals();+ vi.useRealTimers();+});+function setup() {+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] });+ const track = { stop: vi.fn() };+ const drawImage = vi.fn();+ const bitmap = { width: 1600, height: 1000, close: vi.fn() };+ const canvas = {+ width: 0,+ height: 0,+ getContext: () => ({ drawImage, clearRect: vi.fn() }),+ captureStream: vi.fn(() => ({ getTracks: () => [track] })),+ };+ vi.spyOn(document, 'createElement').mockImplementation(+ (() => canvas) as unknown as typeof document.createElement,+ );+ vi.stubGlobal(+ 'createImageBitmap',+ vi.fn(async () => bitmap),+ );+ return { track, drawImage, bitmap, canvas };+}+it('subtracts capture/decode time from the interval without overlapping reads', async () => {+ const h = setup();+ const times: number[] = [];+ let active = 0,+ maximum = 0;+ const read = async () => {+ times.push(performance.now());+ maximum = Math.max(maximum, ++active);+ await new Promise((resolve) => setTimeout(resolve, 20));+ active--;+ return 'anBlZw==';+ };+ const pending = nativeCaptureStream(read, () => true, vi.fn(), undefined, 30);+ await vi.advanceTimersByTimeAsync(20);+ const owner = await pending;+ await vi.advanceTimersByTimeAsync(160);+ owner.stop();+ expect(maximum).toBe(1);+ expect(times.length).toBeGreaterThanOrEqual(5);+ expect(times[2] - times[1]).toBeLessThanOrEqual(34);+ expect(h.canvas.captureStream).toHaveBeenCalledWith(30);+ expect(h.track.stop).toHaveBeenCalled();+});+it('drops an in-flight decoded image after stop', async () => {+ const h = setup();+ const owner = await nativeCaptureStream(+ async () => 'anBlZw==',+ () => true,+ vi.fn(),+ );+ let finish!: (value: ImageBitmap) => void;+ vi.mocked(createImageBitmap).mockImplementationOnce(+ () =>+ new Promise((resolve) => {+ finish = resolve;+ }),+ );+ await vi.advanceTimersByTimeAsync(67);+ owner.stop();+ finish(h.bitmap);+ await vi.advanceTimersByTimeAsync(0);+ expect(h.drawImage).toHaveBeenCalledOnce();+ expect(h.bitmap.close).toHaveBeenCalledTimes(2);+ expect(vi.getTimerCount()).toBe(0);+});+it('clears the independent cursor when falling back to frames with a baked pointer', async () => {+ setup();+ const pointer = { visible: false };+ const read = vi+ .fn()+ .mockResolvedValueOnce({ jpeg: 'anBlZw==', cursor: pointer })+ .mockResolvedValue('anBlZw==');+ const cursor = vi.fn();+ const owner = await nativeCaptureStream(read, () => true, vi.fn(), cursor);+ expect(cursor).toHaveBeenLastCalledWith(pointer);+ await vi.advanceTimersByTimeAsync(67);+ expect(cursor).toHaveBeenLastCalledWith(null);+ owner.stop();+});diff --git a/apps/desktop/src/renderer/features/remote-desktop/__tests__/portalCaptureStream.test.ts b/apps/desktop/src/renderer/features/remote-desktop/__tests__/portalCaptureStream.test.tsnew file mode 100644index 0000000000..79879ebc03--- /dev/null+++ b/apps/desktop/src/renderer/features/remote-desktop/__tests__/portalCaptureStream.test.ts@@ -0,0 +1,133 @@+// @vitest-environment jsdom+import { afterEach, expect, it, vi } from 'vitest';+import { PortalCaptureStream } from '../portalCaptureStream';++const owners: PortalCaptureStream[] = [];+afterEach(() => {+ owners.splice(0).forEach((owner) => owner.stop());+ vi.restoreAllMocks();+ vi.unstubAllGlobals();+ vi.useRealTimers();+});+function setup() {+ vi.useFakeTimers();+ const ended = vi.fn();+ const owner = new PortalCaptureStream(ended);+ owners.push(owner);+ let resolve!: (value: MediaStream) => void;+ let reject!: (reason: Error) => void;+ const capture = vi.fn(+ () =>+ new Promise<MediaStream>((yes, no) => {+ resolve = yes;+ reject = no;+ }),+ );+ vi.stubGlobal('navigator', { mediaDevices: { getDisplayMedia: capture } });+ const track = Object.assign(new EventTarget(), {+ stop: vi.fn(),+ muted: false,+ readyState: 'live',+ });+ const cloned = { getTracks: () => [{ stop: vi.fn() }] } as unknown as MediaStream;+ const stream = {+ active: true,+ getTracks: () => [track],+ getVideoTracks: () => [track],+ clone: vi.fn(() => cloned),+ } as unknown as MediaStream;+ const video = {+ muted: false,+ srcObject: null,+ play: vi.fn(async () => {}),+ pause: vi.fn(),+ readyState: 2,+ videoWidth: 1920,+ videoHeight: 1200,+ };+ const canvas = {+ width: 0,+ height: 0,+ getContext: () => ({ drawImage: vi.fn() }),+ toDataURL: vi.fn(() => 'data:image/jpeg;base64,anBlZw=='),+ };+ vi.spyOn(document, 'createElement').mockImplementation(((tag: string) =>+ tag === 'video' ? video : canvas) as typeof document.createElement);+ return {+ owner,+ ended,+ capture,+ resolve: () => resolve(stream),+ reject: (error: Error) => reject(error),+ stream,+ track,+ video,+ canvas,+ };+}+it('waits for local consent beyond five seconds without opening more pickers, then serves bounded frames and clones', async () => {+ const h = setup();+ h.owner.prepare('lease');+ expect(h.owner.frame('lease')).toBeNull();+ const capture = h.owner.capture('lease');+ await vi.advanceTimersByTimeAsync(20_000);+ h.owner.prepare('lease');+ expect(h.capture).toHaveBeenCalledOnce();+ expect(h.ended).not.toHaveBeenCalled();+ h.resolve();+ expect(await capture).toBe(h.stream.clone());+ expect(h.owner.frame('lease')).toBe('anBlZw==');+ expect(h.canvas.width).toBe(1280);+ expect(h.canvas.height).toBe(800);+ await h.owner.capture('lease');+ expect(h.capture).toHaveBeenCalledOnce();+ expect(h.track.stop).not.toHaveBeenCalled();+ h.track.muted = true;+ expect(h.owner.frame('lease')).toBeNull();+ h.owner.stop();+ expect(h.track.stop).toHaveBeenCalledOnce();+ expect(h.video.srcObject).toBeNull();+});+it('keeps denial sticky for the lease instead of prompting on every frame or video retry', async () => {+ const h = setup();+ h.owner.prepare('lease');+ const rejected = expect(h.owner.capture('lease')).rejects.toThrow('denied');+ h.reject(new Error('denied'));+ await rejected;+ h.owner.prepare('lease');+ expect(() => h.owner.frame('lease')).toThrow('DESKTOP_VIDEO_UNAVAILABLE');+ expect(h.capture).toHaveBeenCalledOnce();+});+it.each(['stop', 'timeout'] as const)('discards a late user selection after %s', async (kind) => {+ const h = setup();+ h.owner.prepare('lease');+ const rejected = expect(h.owner.capture('lease')).rejects.toThrow('DESKTOP_VIDEO_STOPPED');+ if (kind === 'stop') h.owner.stop();+ else await vi.advanceTimersByTimeAsync(120_000);+ h.resolve();+ await rejected;+ expect(h.track.stop).toHaveBeenCalledOnce();+ expect(h.ended).toHaveBeenCalledTimes(kind === 'timeout' ? 1 : 0);+ expect(() => h.owner.frame('lease')).toThrow('DESKTOP_VIDEO_STOPPED');+});+it('stops the lease when the user ends sharing, and rejects wrong-lease reads', async () => {+ const h = setup();+ h.owner.prepare('lease');+ h.resolve();+ await h.owner.capture('lease');+ await expect(h.owner.capture('other')).rejects.toThrow('DESKTOP_VIDEO_STOPPED');+ expect(() => h.owner.frame('other')).toThrow('DESKTOP_VIDEO_STOPPED');+ h.track.dispatchEvent(new Event('ended'));+ expect(h.ended).toHaveBeenCalledOnce();+ expect(h.track.stop).toHaveBeenCalledOnce();+ expect(h.video.srcObject).toBeNull();+});+it('drops oversized JPEGs rather than sending unbounded relay payloads', async () => {+ const h = setup();+ h.owner.prepare('lease');+ h.resolve();+ await h.owner.capture('lease');+ h.canvas.toDataURL.mockReturnValue('data:image/jpeg;base64,' + 'a'.repeat(4_000_000));+ expect(h.owner.frame('lease')).toBeNull();+ expect(h.canvas.toDataURL).toHaveBeenCalledTimes(4);+});diff --git a/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts b/apps/desktop/src/renderer/features/remote-desktop/captureHost.tsindex 33c7c14f1b..f6e70cbfab 100644--- a/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts+++ b/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts@@ -9,9 +9,15 @@ import {} from '@cindy/device-link';import 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 {+ const portal = new PortalCaptureStream(() => {+ stop();+ void api.stop().catch(() => {});+ });let peer: RTCPeerConnection | null = null;let stream: MediaStream | null = null;let generation = 0;@@ -19,6 +25,7 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {let latestCursor: RemoteDesktopCursor | null | undefined;let cursorTimer: ReturnType<typeof setInterval> | null = null;let native: Awaited<ReturnType<typeof nativeCaptureStream>> | null = null;+ let audio: Awaited<ReturnType<typeof nativeAudioStream>> | null = null;let recoverCapture: (() => void) | null = null;let activeLease: string | null = null;let attemptId: string | undefined;@@ -44,6 +51,8 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {cursorTimer = null;native?.stop();native = null;+ audio?.stop();+ audio = null;recoverCapture = null;activeLease = null;if (heartbeat) clearInterval(heartbeat);@@ -54,6 +63,20 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {stream = null;};const unsubscribe = api.onCommand((command) => {+ if (command.op === 'prepare') {+ if (command.portalCapture && command.lease) portal.prepare(command.lease);+ return;+ }+ if (command.op === 'frame') {+ try {+ void api+ .reply(command.id, command.lease ? portal.frame(command.lease) : null)+ .catch(() => {});+ } catch {+ void api.reply(command.id, { error: 'DESKTOP_VIDEO_UNAVAILABLE' }).catch(() => {});+ }+ return;+ }if (command.op === 'ice') {const rtc = peer,current = generation;@@ -115,9 +138,10 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {command.op !== 'offer' ||!command.lease ||!command.sdp ||- (!command.sourceId && !command.nativeCapture)+ (!command.sourceId && !command.nativeCapture && !command.portalCapture))return;+ if (!command.portalCapture) portal.stop();const current = generation;const lease = command.lease;activeLease = lease;@@ -166,7 +190,9 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {(value) => {if (current === generation) latestCursor = value;},- command.cursorOverlay ? (command.settings?.fps ?? 30) : 15,+ command.cursorOverlay || command.continuousNativeCapture+ ? (command.settings?.fps ?? 30)+ : 15,);if (current !== generation) {result.stop();@@ -176,7 +202,8 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {return result.stream;};let captured: MediaStream;- if (command.cursorOverlay) {+ if (command.portalCapture) captured = await portal.capture(lease);+ else if (command.cursorOverlay) {// Chromium in our runtime exposes no cursor constraint. Use the// cursor-free native video while retaining the normal audio track.let audioSource: MediaStream | null = null;@@ -208,6 +235,23 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {captured.getTracks().forEach((track) => track.stop());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');@@ -388,5 +432,6 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {return () => {unsubscribe();stop();+ portal.stop();};}diff --git a/apps/desktop/src/renderer/features/remote-desktop/nativeAudioStream.ts b/apps/desktop/src/renderer/features/remote-desktop/nativeAudioStream.tsnew file mode 100644index 0000000000..96fc1e7872--- /dev/null+++ b/apps/desktop/src/renderer/features/remote-desktop/nativeAudioStream.ts@@ -0,0 +1,73 @@+/** Bounded PCM scheduling into the existing WebRTC stream; never plays locally. */+export async function nativeAudioStream(+ read: () => Promise<Uint8Array>,+ current: () => boolean,+ failed: () => void,+): Promise<{ track: MediaStreamTrack; stop(): void }> {+ const context = new AudioContext({ sampleRate: 48000, latencyHint: 'interactive' });+ const destination = context.createMediaStreamDestination();+ const sources = new Set<AudioBufferSourceNode>();+ let stopped = false;+ let timer: ReturnType<typeof setTimeout> | undefined;+ let next = 0;+ const stop = () => {+ if (stopped) return;+ stopped = true;+ clearTimeout(timer);+ for (const source of sources) source.stop();+ sources.clear();+ destination.stream.getTracks().forEach((track) => track.stop());+ void context.close().catch(() => {});+ };+ const poll = async () => {+ if (stopped || !current()) return stop();+ try {+ const bytes = await read();+ if (stopped || !current()) return stop();+ if (!(bytes instanceof Uint8Array) || bytes.byteLength > 38400 || bytes.byteLength % 8)+ throw new Error('DESKTOP_AUDIO_UNAVAILABLE');+ if (bytes.length) {+ const frames = bytes.length / 8;+ const data = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);+ const buffer = context.createBuffer(2, frames, 48000);+ for (let channel = 0; channel < 2; channel++) {+ const output = buffer.getChannelData(channel);+ for (let i = 0; i < frames; i++) {+ const value = data.getFloat32(i * 8 + channel * 4, true);+ output[i] = Number.isFinite(value) ? Math.max(-1, Math.min(1, value)) : 0;+ }+ }+ // Discard queued history after a renderer stall; preserve only live audio.+ if (next > context.currentTime + 0.15) {+ for (const source of sources) source.stop();+ sources.clear();+ next = 0;+ }+ next = Math.max(context.currentTime + 0.02, next);+ const source = context.createBufferSource();+ source.buffer = buffer;+ source.connect(destination);+ source.onended = () => {+ sources.delete(source);+ source.disconnect();+ };+ sources.add(source);+ source.start(next);+ next += frames / 48000;+ }+ timer = setTimeout(() => void poll(), 20);+ } catch {+ stop();+ if (current()) failed();+ }+ };+ try {+ await context.resume();+ await poll();+ if (stopped) throw new Error('DESKTOP_AUDIO_UNAVAILABLE');+ return { track: destination.stream.getAudioTracks()[0], stop };+ } catch {+ stop();+ throw new Error('DESKTOP_AUDIO_UNAVAILABLE');+ }+}diff --git a/apps/desktop/src/renderer/features/remote-desktop/nativeCaptureStream.ts b/apps/desktop/src/renderer/features/remote-desktop/nativeCaptureStream.tsindex 9c31c94941..3e79e75867 100644--- a/apps/desktop/src/renderer/features/remote-desktop/nativeCaptureStream.ts+++ b/apps/desktop/src/renderer/features/remote-desktop/nativeCaptureStream.ts@@ -20,8 +20,11 @@ export async function nativeCaptureStream(const current = epoch;const frame = await read();const jpeg = typeof frame === 'string' ? frame : frame?.jpeg;- if (!jpeg || stopped || !alive() || current !== epoch) return false;- const bytes = Uint8Array.from(atob(jpeg), (value) => value.charCodeAt(0));+ if (!frame || !jpeg || stopped || !alive() || current !== epoch) return false;+ const binary = atob(jpeg);+ const bytes = new Uint8Array(binary.length);+ // Avoid Uint8Array.from's per-character iterator/callback on large frames.+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);const bitmap = await createImageBitmap(new Blob([bytes], { type: 'image/jpeg' }));try {if (stopped || !alive() || current !== epoch) return false;@@ -30,7 +33,9 @@ export async function nativeCaptureStream(canvas.height = bitmap.height;}context.drawImage(bitmap, 0, 0);- if (frame && typeof frame !== 'string') cursor(frame.cursor);+ // A fallback frame includes the pointer in its pixels. Clear the last+ // independent cursor so switching backends cannot leave two pointers.+ cursor(typeof frame === 'string' ? null : frame.cursor);lastFrame = performance.now();return true;} finally {@@ -50,10 +55,15 @@ export async function nativeCaptureStream(stop();return;}+ const started = performance.now();try {await draw();if (performance.now() - lastFrame > 5000) throw new Error('DESKTOP_VIDEO_UNAVAILABLE');- if (!stopped && alive()) timer = setTimeout(() => void pull(), Math.round(1000 / fps));+ if (!stopped && alive())+ timer = setTimeout(+ () => void pull(),+ Math.max(0, 1000 / fps - (performance.now() - started)),+ );else stop();} catch {stop();diff --git a/apps/desktop/src/renderer/features/remote-desktop/portalCaptureStream.ts b/apps/desktop/src/renderer/features/remote-desktop/portalCaptureStream.tsnew file mode 100644index 0000000000..a9db3ed64f--- /dev/null+++ b/apps/desktop/src/renderer/features/remote-desktop/portalCaptureStream.ts@@ -0,0 +1,134 @@+import { REMOTE_DESKTOP_MAX_FRAME_BYTES } from '@cindy/device-link';++/** One system-approved stream per lease, independent of WebRTC attempt lifetime.+ * Relay frames and peer clones share this source; neither may reopen the picker. */+export class PortalCaptureStream {+ private lease: string | null = null;+ private pending: Promise<MediaStream> | null = null;+ private stream: MediaStream | null = null;+ private error: Error | null = null;+ private video: HTMLVideoElement | null = null;+ private timer: ReturnType<typeof setTimeout> | undefined;+ private generation = 0;++ constructor(private readonly ended: () => void) {}++ prepare(lease: string): void {+ if (this.lease === lease) return;+ this.stop();+ this.lease = lease;+ const generation = this.generation;+ const current = () => this.generation === generation;+ // User interaction is not a five-second enumeration. RPCs remain short and+ // can keep the lease alive while the local system picker waits for consent.+ this.timer = setTimeout(() => {+ if (current()) {+ this.stop();+ this.ended();+ }+ }, 120_000);+ this.pending = navigator.mediaDevices+ .getDisplayMedia({+ audio: false,+ video: { frameRate: { ideal: 30, max: 60 } },+ })+ .then((stream) => {+ if (!current()) {+ stream.getTracks().forEach((track) => track.stop());+ throw new Error('DESKTOP_VIDEO_STOPPED');+ }+ clearTimeout(this.timer);+ this.stream = stream;+ const track = stream.getVideoTracks()[0];+ if (!track) throw new Error('DESKTOP_VIDEO_UNAVAILABLE');+ track.addEventListener(+ 'ended',+ () => {+ if (current()) {+ this.stop();+ this.ended();+ }+ },+ { once: true },+ );+ this.video = document.createElement('video');+ this.video.muted = true;+ this.video.srcObject = stream;+ void this.video.play().catch(() => {+ if (current()) {+ this.stop();+ this.ended();+ }+ });+ return stream;+ })+ .catch((error: unknown) => {+ if (current()) {+ clearTimeout(this.timer);+ this.error = new Error('DESKTOP_VIDEO_UNAVAILABLE');+ this.stream?.getTracks().forEach((track) => track.stop());+ this.stream = null;+ }+ throw error;+ });+ // Preparation has no awaiting RPC. Keep failure sticky for this lease so+ // fallback polling cannot turn a denied picker into an authorization loop.+ void this.pending.catch(() => {});+ }++ async capture(lease: string): Promise<MediaStream> {+ if (lease !== this.lease || !this.pending) throw new Error('DESKTOP_VIDEO_STOPPED');+ const generation = this.generation;+ const stream = await this.pending;+ if (generation !== this.generation || this.error || !stream.active)+ throw new Error('DESKTOP_VIDEO_STOPPED');+ return stream.clone(); // Peer shutdown must not stop the portal owner.+ }++ frame(lease: string): string | null {+ if (lease !== this.lease) throw new Error('DESKTOP_VIDEO_STOPPED');+ if (this.error) throw this.error;+ const video = this.video;+ const track = this.stream?.getVideoTracks()[0];+ if (+ !video ||+ !track ||+ track.muted ||+ track.readyState !== 'live' ||+ video.readyState < 2 ||+ !video.videoWidth ||+ !video.videoHeight+ )+ return null;+ const canvas = document.createElement('canvas');+ let scale = Math.min(1, 1280 / Math.max(video.videoWidth, video.videoHeight));+ for (let attempt = 0; attempt < 4; attempt++, scale *= 0.75) {+ canvas.width = Math.max(1, Math.floor(video.videoWidth * scale));+ canvas.height = Math.max(1, Math.floor(video.videoHeight * scale));+ const context = canvas.getContext('2d');+ if (!context) return null;+ context.drawImage(video, 0, 0, canvas.width, canvas.height);+ const data = canvas.toDataURL('image/jpeg', 0.55);+ if (!data.startsWith('data:image/jpeg;base64,')) return null;+ const jpeg = data.slice('data:image/jpeg;base64,'.length);+ if (jpeg.length <= Math.ceil(REMOTE_DESKTOP_MAX_FRAME_BYTES / 3) * 4) return jpeg;+ }+ return null;+ }++ stop(): void {+ this.generation++;+ clearTimeout(this.timer);+ this.timer = undefined;+ this.stream?.getTracks().forEach((track) => track.stop());+ this.stream = null;+ this.pending = null;+ this.error = null;+ this.lease = null;+ if (this.video) {+ this.video.pause();+ this.video.srcObject = null;+ this.video = null;+ }+ }+}diff --git a/apps/desktop/src/shared/remoteDesktop.ts b/apps/desktop/src/shared/remoteDesktop.tsindex 205a051845..6afd21d13a 100644--- a/apps/desktop/src/shared/remoteDesktop.ts+++ b/apps/desktop/src/shared/remoteDesktop.ts@@ -19,6 +19,7 @@ export const DESKTOP_LOCAL = {INPUT: 'remote-desktop:host-input',VIEW_HEARTBEAT: 'remote-desktop:view-heartbeat',NATIVE_FRAME: 'remote-desktop:native-frame',+ NATIVE_AUDIO: 'remote-desktop:native-audio',WINDOWS_SUPPORT: 'remote-desktop:windows-support',PERMISSIONS: 'remote-desktop:permissions',OPEN_PERMISSION: 'remote-desktop:open-permission',@@ -27,11 +28,17 @@ export const DESKTOP_LOCAL = {export interface DesktopHostCommand {iceServers?: DesktopIceServer[];id: string;- op: 'offer' | 'stop' | 'capture-reset' | 'ice';+ op: 'offer' | 'stop' | 'capture-reset' | 'ice' | 'prepare' | 'frame';+ /** Local-only: retain the system-selected Wayland stream for this lease. */+ portalCapture?: boolean;attemptId?: string;candidates?: RemoteDesktopIceCandidate[];after?: number;nativeCapture?: boolean;+ /** Local-only: persistent Linux capture follows the negotiated video rate. */+ continuousNativeCapture?: boolean;+ /** Local-only output monitor, enabled only by the main process audio grant. */+ nativeAudio?: boolean;cursorOverlay?: boolean;lease?: string;sourceId?: string;@@ -73,5 +80,6 @@ export interface DesktopCaptureApi {reply(id: string, result: DesktopHostReply): Promise<void>;viewHeartbeat(lease: string): Promise<void>;nativeFrame(lease: string): Promise<string | RemoteDesktopCursorFrame | null>;+ nativeAudio?(lease: string): Promise<Uint8Array>;input(lease: string, sequence: number, events: DesktopInput[]): Promise<void>;}diff --git a/apps/mobile/src/i18n/locales/en/remoteDesktop.json b/apps/mobile/src/i18n/locales/en/remoteDesktop.jsonindex aaaeb11e80..674bc116f8 100644--- a/apps/mobile/src/i18n/locales/en/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/en/remoteDesktop.json@@ -12,11 +12,11 @@"clipboardSyncPermission": "Sync is paused. Allow paste access, then retry. Your setting stays on.","clipboardSyncRetry": "Retry sync","credentialSigningRequired": "The Mac development build is missing its signing configuration. Restart Cindy on the Mac with signing configured, then try again.",- "credentialPasswordRejected": "The Mac login password was not accepted. Enter it again.",+ "credentialPasswordRejected": "The computer login password was not accepted. Enter it again.","credentialCancelled": "Password verification was cancelled. Tap reconnect when you are ready.","credentialIdentityChanged": "The computer identity could not be verified. No password was sent to an unverified device.","credentialExpired": "The secure connection expired. Reconnect to verify again.",- "credentialRequired": "Complete Mac password verification, then reconnect. If verification is unavailable, update Cindy on both devices.",+ "credentialRequired": "Complete computer password verification, then reconnect. If verification is unavailable, update Cindy on both devices.","takeoverConnection": "Take over connection","connectionBusyTakeover": "Another device is connected to this desktop. Taking over will disconnect that device.","clipboard": "Clipboard",@@ -95,6 +95,11 @@"keys": "Keys","showDesktop": "Desktop","allWindows": "All windows",+ "workspaceLeft": "Left desktop",+ "workspaceRight": "Right desktop",+ "omarchyMenu": "Omarchy",+ "noWindows": "No open windows",+ "windowsFailed": "Could not load or switch windows. Tap to retry.","operations": "Controls","inputMode": "Input mode","displayNumber": "Display {{number}}",@@ -141,12 +146,13 @@"credentialUnlockUnavailable": "Could not safely unlock this Mac. Select your account on its lock screen, then reconnect; if it still fails, unlock the Mac locally.","security": "Security","autoUnlock": "Automatically unlock computer",- "autoUnlockHint": "Save your Mac login password on this device to unlock the computer when connecting.",+ "autoUnlockHint": "Save your computer login password on this device to unlock the computer when connecting.",+ "linuxUnlockUnavailable": "This Linux lock screen or its unlock service is not supported or available. You can still connect and unlock the computer manually.","faceIdVerification": "Face ID verification","biometricVerification": "Biometric verification","biometricVerificationHint": "Verify your identity before using the saved password.","autoUnlockStorageHint": "The password is stored encrypted on this device only. Settings and passwords do not sync with your account.",- "autoUnlockUnavailable": "Automatic unlock is unavailable. You can still connect and unlock the Mac manually.",+ "autoUnlockUnavailable": "Automatic unlock is unavailable. You can still connect and unlock the computer manually.","lockOnExit": "Lock Computer on Exit","lockOnExitHint": "Locks when you leave remote desktop. Reconnecting or switching apps does not lock the computer.","lockOnExitFailed": "Could not confirm that the computer locked. Check the computer before leaving it unattended.",diff --git a/apps/mobile/src/i18n/locales/ja/remoteDesktop.json b/apps/mobile/src/i18n/locales/ja/remoteDesktop.jsonindex 2603576c31..6ae2b45f44 100644--- a/apps/mobile/src/i18n/locales/ja/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/ja/remoteDesktop.json@@ -12,11 +12,11 @@"clipboardSyncPermission": "同期を一時停止しました。ペーストを許可してから再試行してください。設定はオンのままです。","clipboardSyncRetry": "同期を再試行","credentialSigningRequired": "Mac の開発版に署名設定がありません。Mac で署名を設定して Cindy を再起動し、もう一度お試しください。",- "credentialPasswordRejected": "Mac のログインパスワードを確認できませんでした。もう一度入力してください。",+ "credentialPasswordRejected": "パソコンのログインパスワードを確認できませんでした。もう一度入力してください。","credentialCancelled": "パスワードの確認をキャンセルしました。準備ができたら再接続してください。","credentialIdentityChanged": "コンピュータの識別情報を確認できません。未確認のデバイスにはパスワードを送信しません。","credentialExpired": "安全な接続の有効期限が切れました。再接続して確認してください。",- "credentialRequired": "Mac のパスワードを確認してから再接続してください。確認できない場合は、両方のデバイスの Cindy を更新してください。",+ "credentialRequired": "パソコンのパスワードを確認してから再接続してください。確認できない場合は、両方のデバイスの Cindy を更新してください。","takeoverConnection": "接続を引き継ぐ","connectionBusyTakeover": "別のデバイスが接続中です。接続を引き継ぐと、そのデバイスは切断されます。","clipboard": "クリップボード",@@ -95,6 +95,11 @@"keys": "キー","showDesktop": "デスクトップ","allWindows": "すべてのウィンドウ",+ "workspaceLeft": "左のデスクトップ",+ "workspaceRight": "右のデスクトップ",+ "omarchyMenu": "Omarchy",+ "noWindows": "開いているウィンドウはありません",+ "windowsFailed": "ウィンドウの読み込みまたは切り替えに失敗しました。タップして再試行してください。","operations": "操作","inputMode": "操作方法","displayNumber": "ディスプレイ {{number}}",@@ -141,12 +146,13 @@"credentialUnlockUnavailable": "この Mac を安全にロック解除できませんでした。ロック画面で自分のアカウントを選んで再接続してください。解決しない場合は Mac で手動解除してください。","security": "セキュリティ","autoUnlock": "コンピューターを自動ロック解除",- "autoUnlockHint": "Mac のログインパスワードをこのデバイスに保存し、接続時にパソコンのロックを解除します。",+ "autoUnlockHint": "パソコンのログインパスワードをこのデバイスに保存し、接続時にパソコンのロックを解除します。",+ "linuxUnlockUnavailable": "この Linux のロック画面または解除サービスは未対応か利用できません。接続してパソコンを手動でロック解除することはできます。","faceIdVerification": "Face ID 認証","biometricVerification": "生体認証","biometricVerificationHint": "保存したパスワードを使う前に本人確認を行います。","autoUnlockStorageHint": "パスワードはこの端末にのみ暗号化して保存されます。設定とパスワードはアカウントに同期されません。",- "autoUnlockUnavailable": "自動ロック解除を利用できません。接続して Mac を手動でロック解除できます。",+ "autoUnlockUnavailable": "自動ロック解除を利用できません。接続してパソコンを手動でロック解除できます。","lockOnExit": "終了時にパソコンをロック","lockOnExitHint": "リモートデスクトップを終了するとロックします。再接続やアプリ切り替えではロックしません。","lockOnExitFailed": "パソコンのロックを確認できませんでした。パソコンの状態を確認してください。",diff --git a/apps/mobile/src/i18n/locales/ko/remoteDesktop.json b/apps/mobile/src/i18n/locales/ko/remoteDesktop.jsonindex 0f10e15b69..284d0fffb5 100644--- a/apps/mobile/src/i18n/locales/ko/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/ko/remoteDesktop.json@@ -12,11 +12,11 @@"clipboardSyncPermission": "동기화가 일시 중지되었습니다. 붙여넣기를 허용한 후 다시 시도해 주세요. 설정은 켜진 상태로 유지됩니다.","clipboardSyncRetry": "동기화 재시도","credentialSigningRequired": "Mac 개발 버전에 서명 설정이 없습니다. Mac에서 서명을 설정하고 Cindy를 다시 시작한 후 다시 시도해 주세요.",- "credentialPasswordRejected": "Mac 로그인 암호를 확인하지 못했습니다. 다시 입력해 주세요.",+ "credentialPasswordRejected": "컴퓨터 로그인 암호를 확인하지 못했습니다. 다시 입력해 주세요.","credentialCancelled": "암호 확인을 취소했습니다. 준비되면 다시 연결해 주세요.","credentialIdentityChanged": "컴퓨터의 신원을 확인할 수 없습니다. 확인되지 않은 기기로 암호를 보내지 않습니다.","credentialExpired": "보안 연결이 만료되었습니다. 다시 연결하여 확인해 주세요.",- "credentialRequired": "Mac 암호를 확인한 후 다시 연결하세요. 확인할 수 없으면 두 기기에서 Cindy를 업데이트하세요.",+ "credentialRequired": "컴퓨터 암호를 확인한 후 다시 연결하세요. 확인할 수 없으면 두 기기에서 Cindy를 업데이트하세요.","takeoverConnection": "연결 넘겨받기","connectionBusyTakeover": "다른 기기가 연결되어 있습니다. 연결을 넘겨받으면 해당 기기의 연결이 끊어집니다.","clipboard": "클립보드",@@ -95,6 +95,11 @@"keys": "키","showDesktop": "데스크톱","allWindows": "모든 창",+ "workspaceLeft": "왼쪽 데스크톱",+ "workspaceRight": "오른쪽 데스크톱",+ "omarchyMenu": "Omarchy",+ "noWindows": "열린 창이 없습니다",+ "windowsFailed": "창을 불러오거나 전환하지 못했습니다. 탭하여 다시 시도하세요.","operations": "조작","inputMode": "입력 방식","displayNumber": "디스플레이 {{number}}",@@ -141,12 +146,13 @@"credentialUnlockUnavailable": "이 Mac의 잠금을 안전하게 해제하지 못했습니다. 잠금 화면에서 본인 계정을 선택한 후 다시 연결하세요. 계속 실패하면 Mac에서 직접 잠금을 해제하세요.","security": "보안","autoUnlock": "컴퓨터 자동 잠금 해제",- "autoUnlockHint": "Mac 로그인 암호를 이 기기에 저장하고 연결할 때 컴퓨터 잠금을 해제합니다.",+ "autoUnlockHint": "컴퓨터 로그인 암호를 이 기기에 저장하고 연결할 때 컴퓨터 잠금을 해제합니다.",+ "linuxUnlockUnavailable": "이 Linux 잠금 화면 또는 잠금 해제 서비스는 지원되지 않거나 사용할 수 없습니다. 연결한 뒤 컴퓨터를 수동으로 잠금 해제할 수 있습니다.","faceIdVerification": "Face ID 인증","biometricVerification": "생체 인증","biometricVerificationHint": "저장된 암호를 사용하기 전에 본인 인증을 합니다.","autoUnlockStorageHint": "암호는 현재 기기에만 암호화되어 저장됩니다. 설정과 암호는 계정에 동기화되지 않습니다.",- "autoUnlockUnavailable": "자동 잠금 해제를 사용할 수 없습니다. 연결한 뒤 Mac을 수동으로 잠금 해제할 수 있습니다.",+ "autoUnlockUnavailable": "자동 잠금 해제를 사용할 수 없습니다. 연결한 뒤 컴퓨터를 수동으로 잠금 해제할 수 있습니다.","lockOnExit": "종료 시 컴퓨터 잠금","lockOnExitHint": "원격 데스크톱을 종료하면 잠급니다. 재연결이나 앱 전환 시에는 잠그지 않습니다.","lockOnExitFailed": "컴퓨터가 잠겼는지 확인하지 못했습니다. 컴퓨터 상태를 확인해 주세요.",diff --git a/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json b/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.jsonindex 88e14f4970..f1b146dde3 100644--- a/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json@@ -12,11 +12,11 @@"clipboardSyncPermission": "同步已暂停,请允许粘贴权限后重试。开关保持开启。","clipboardSyncRetry": "重试同步","credentialSigningRequired": "Mac 上的开发版缺少签名配置。请在 Mac 上配置签名并重新启动 Cindy,然后重试。",- "credentialPasswordRejected": "Mac 登录密码验证失败,请重新输入。",+ "credentialPasswordRejected": "电脑登录密码验证失败,请重新输入。","credentialCancelled": "已取消密码验证,准备好后可重新连接。","credentialIdentityChanged": "无法确认电脑身份,不会向未经验证的设备发送密码。","credentialExpired": "安全连接已过期,请重新连接并验证。",- "credentialRequired": "请完成 Mac 密码验证后重新连接。如果无法验证,请更新手机和电脑上的 Cindy。",+ "credentialRequired": "请完成电脑密码验证后重新连接。如果无法验证,请更新手机和电脑上的 Cindy。","takeoverConnection": "接管连接","connectionBusyTakeover": "已有其他设备连接此远程桌面。接管连接后,上一台设备会断开。","clipboard": "剪贴板",@@ -95,6 +95,11 @@"keys": "按键","showDesktop": "显示桌面","allWindows": "所有窗口",+ "workspaceLeft": "左侧桌面",+ "workspaceRight": "右侧桌面",+ "omarchyMenu": "Omarchy",+ "noWindows": "暂无打开的窗口",+ "windowsFailed": "读取或切换窗口失败,轻点重试。","operations": "操作","inputMode": "操作方式","displayNumber": "显示器 {{number}}",@@ -141,12 +146,13 @@"credentialUnlockUnavailable": "暂时无法安全解锁这台 Mac。请在锁屏界面选中你的账户后重连;若仍失败,请在电脑上手动解锁。","security": "安全","autoUnlock": "自动解锁电脑",- "autoUnlockHint": "在此设备保存 Mac 登录密码,连接时自动解锁电脑。",+ "autoUnlockHint": "在此设备保存电脑登录密码,连接时自动解锁电脑。",+ "linuxUnlockUnavailable": "此 Linux 锁屏或其解锁服务暂不支持或不可用。你仍可连接,并手动解锁电脑。","faceIdVerification": "Face ID 验证","biometricVerification": "生物识别验证","biometricVerificationHint": "使用保存的密码前,验证你的身份。","autoUnlockStorageHint": "密码仅加密保存在当前设备。设置和密码不随账号同步。",- "autoUnlockUnavailable": "暂时无法自动解锁。你仍可连接,并手动解锁 Mac。",+ "autoUnlockUnavailable": "暂时无法自动解锁。你仍可连接,并手动解锁电脑。","lockOnExit": "退出后锁定电脑","lockOnExitHint": "退出远程桌面时锁屏。重连或切换 App 不会触发。","lockOnExitFailed": "未能确认电脑已锁屏,请检查电脑的锁屏状态。",diff --git a/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json b/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.jsonindex 4c621e63fe..5674199311 100644--- a/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json@@ -12,11 +12,11 @@"clipboardSyncPermission": "同步已暫停,請允許貼上權限後重試。開關保持開啟。","clipboardSyncRetry": "重試同步","credentialSigningRequired": "Mac 上的開發版缺少簽名設定。請在 Mac 上設定簽名並重新啟動 Cindy,然後重試。",- "credentialPasswordRejected": "Mac 登入密碼驗證失敗,請重新輸入。",+ "credentialPasswordRejected": "電腦登入密碼驗證失敗,請重新輸入。","credentialCancelled": "已取消密碼驗證,準備好後可重新連線。","credentialIdentityChanged": "無法確認電腦身分,不會向未經驗證的裝置傳送密碼。","credentialExpired": "安全連線已過期,請重新連線並驗證。",- "credentialRequired": "請完成 Mac 密碼驗證後重新連線。如果無法驗證,請更新手機和電腦上的 Cindy。",+ "credentialRequired": "請完成電腦密碼驗證後重新連線。如果無法驗證,請更新手機和電腦上的 Cindy。","takeoverConnection": "接管連線","connectionBusyTakeover": "已有其他裝置連線至此遠端桌面。接管連線後,上一台裝置會中斷。","clipboard": "剪貼簿",@@ -95,6 +95,11 @@"keys": "按鍵","showDesktop": "顯示桌面","allWindows": "所有視窗",+ "workspaceLeft": "左側桌面",+ "workspaceRight": "右側桌面",+ "omarchyMenu": "Omarchy",+ "noWindows": "目前沒有開啟的視窗",+ "windowsFailed": "讀取或切換視窗失敗,輕點重試。","operations": "操作","inputMode": "操作方式","displayNumber": "顯示器 {{number}}",@@ -141,12 +146,13 @@"credentialUnlockUnavailable": "暫時無法安全解鎖這台 Mac。請在鎖定畫面選取你的帳號後重新連線;若仍失敗,請在電腦上手動解鎖。","security": "安全","autoUnlock": "自動解鎖電腦",- "autoUnlockHint": "在此裝置儲存 Mac 登入密碼,連線時自動解鎖電腦。",+ "autoUnlockHint": "在此裝置儲存電腦登入密碼,連線時自動解鎖電腦。",+ "linuxUnlockUnavailable": "此 Linux 鎖定畫面或其解鎖服務暫不支援或無法使用。你仍可連線,並手動解鎖電腦。","faceIdVerification": "Face ID 驗證","biometricVerification": "生物辨識驗證","biometricVerificationHint": "使用儲存的密碼前,驗證你的身分。","autoUnlockStorageHint": "密碼僅加密儲存在目前裝置。設定和密碼不會隨帳號同步。",- "autoUnlockUnavailable": "暫時無法自動解鎖。你仍可連線,並手動解鎖 Mac。",+ "autoUnlockUnavailable": "暫時無法自動解鎖。你仍可連線,並手動解鎖電腦。","lockOnExit": "退出後鎖定電腦","lockOnExitHint": "離開遠端桌面時鎖定螢幕。重新連線或切換 App 不會觸發。","lockOnExitFailed": "無法確認電腦已鎖定螢幕,請檢查電腦狀態。",diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsxindex d70e55e613..647837f054 100644--- a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx@@ -26,7 +26,13 @@ import {presentationDragIndicator,shapes,} from "@expo/ui/swift-ui/modifiers";-import { Keyboard, SlidersHorizontal } from "lucide-react-native";+import {+ ArrowLeft,+ ArrowRight,+ Menu,+ Keyboard,+ SlidersHorizontal,+} from "lucide-react-native";import { useTranslation } from "react-i18next";import { useSafeAreaInsets } from "react-native-safe-area-context";import {@@ -46,11 +52,10 @@ import type {RemoteDesktopToolbar as Toolbar,} from "./RemoteDesktopChrome";-// Four 44pt native hit targets with a 4pt inset inside one glass capsule.+// 44pt native hit targets with a 4pt inset inside one glass capsule.const target = 44;const inset = 4;const breadth = target + inset * 2;-const length = target * 4 + inset * 2;export function RemoteDesktopToolbar(props: ComponentProps<typeof Toolbar>) {const { colors, mode } = useTheme();@@ -58,19 +63,30 @@ export function RemoteDesktopToolbar(props: ComponentProps<typeof Toolbar>) {const glass = useLiquidGlassAvailable();const actions = [{- key: "allWindows",- Icon: AllWindowsIcon,- onPress: props.onWindows,+ key: props.onWorkspaceLeft ? "workspaceLeft" : "allWindows",+ Icon: props.onWorkspaceLeft ? ArrowLeft : AllWindowsIcon,+ onPress: props.onWorkspaceLeft ?? props.onWindows,disabled: !props.canControl,selected: false,},{- key: "showDesktop",- Icon: ShowDesktopIcon,- onPress: props.onDesktop,+ key: props.onWorkspaceRight ? "workspaceRight" : "showDesktop",+ Icon: props.onWorkspaceRight ? ArrowRight : ShowDesktopIcon,+ onPress: props.onWorkspaceRight ?? props.onDesktop,disabled: !props.canControl,selected: false,},+ ...(props.onOmarchyMenu+ ? [+ {+ key: "omarchyMenu",+ Icon: Menu,+ onPress: props.onOmarchyMenu,+ disabled: !props.canControl,+ selected: false,+ },+ ]+ : []),{key: "keyboard",Icon: Keyboard,@@ -86,6 +102,7 @@ export function RemoteDesktopToolbar(props: ComponentProps<typeof Toolbar>) {selected: props.operations,},];+ const length = target * actions.length + inset * 2;const Stack = props.landscape ? VStack : HStack;return (<Host@@ -165,6 +182,7 @@ export function RemoteDesktopPanel(props: ComponentProps<typeof Panel>) {const safe = useSafeAreaInsets();const visible = props.visible ?? true;const toolbarOnLeft = props.toolbarOnLeft ?? false;+ const length = target * (props.toolbarActionCount ?? 4) + inset * 2;const railTop =safe.top + Math.max(0, (size.height - safe.top - safe.bottom - length) / 2);// Keep one RN surface for header and body. Changing SwiftUI siblings whilediff --git a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsxindex a63686ef42..534ae250de 100644--- a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx@@ -4,6 +4,9 @@ import { Pressable, ScrollView, StyleSheet, View } from "react-native";import {Keyboard,SlidersHorizontal,+ ArrowLeft,+ ArrowRight,+ Menu,type LucideIcon,} from "lucide-react-native";import { AllWindowsIcon, ShowDesktopIcon } from "./RemoteDesktopIcons";@@ -31,6 +34,9 @@ export function RemoteDesktopToolbar({onDesktop,onKeyboard,onOperations,+ onWorkspaceLeft,+ onWorkspaceRight,+ onOmarchyMenu,}: {landscape: boolean;canControl: boolean;@@ -40,6 +46,9 @@ export function RemoteDesktopToolbar({onDesktop(): void;onKeyboard(): void;onOperations(): void;+ onWorkspaceLeft?: () => void;+ onWorkspaceRight?: () => void;+ onOmarchyMenu?: () => void;}) {const { t } = useTranslation();const { colors } = useTheme();@@ -52,17 +61,27 @@ export function RemoteDesktopToolbar({disabled?: boolean;}> = [{- key: "allWindows",- icon: AllWindowsIcon,- press: onWindows,+ key: onWorkspaceLeft ? "workspaceLeft" : "allWindows",+ icon: onWorkspaceLeft ? ArrowLeft : AllWindowsIcon,+ press: onWorkspaceLeft ?? onWindows,disabled: !canControl,},{- key: "showDesktop",- icon: ShowDesktopIcon,- press: onDesktop,+ key: onWorkspaceRight ? "workspaceRight" : "showDesktop",+ icon: onWorkspaceRight ? ArrowRight : ShowDesktopIcon,+ press: onWorkspaceRight ?? onDesktop,disabled: !canControl,},+ ...(onOmarchyMenu+ ? [+ {+ key: "omarchyMenu",+ icon: Menu,+ press: onOmarchyMenu,+ disabled: !canControl,+ },+ ]+ : []),{key: "keyboard",icon: Keyboard,@@ -131,6 +150,7 @@ export function RemoteDesktopPanel({landscape: boolean;topInset: number;toolbarOnLeft?: boolean;+ toolbarActionCount?: number;title: string;caption: string;onClose(): void;diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsxindex c40bacb56f..cc864ff590 100644--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx@@ -91,6 +91,7 @@ import { useRemoteDesktopSafety } from "./useRemoteDesktopSafety";import { useVideoSettingsPreference } from "./useVideoSettingsPreference";import { PermissionGuide } from "./PermissionGuide";import { RemoteDesktopBackButton } from "./RemoteDesktopBackButton";+import { RemoteDesktopWindows } from "./RemoteDesktopWindows";import { RemoteDesktopNetworkStatus } from "./RemoteDesktopNetworkStatus";import type { DesktopNetworkStats } from "./networkStats";import {@@ -233,6 +234,10 @@ export default function RemoteDesktopScreen() {const connecting = useRef(false);const ready = useRef(false);const streaming = useRef(false);+ // A relay route can briefly disappear while this viewer's RTC stream lives.+ // Keep only this lease for at most 8 s (host lease is 12 s); never reset links+ // shared by other tasks or devices to recover a desktop viewer.+ const transientFailureAt = useRef<number | null>(null);const mediaAttempt = useRef<string | null>(null);const receiveWindow = useRef({since: Date.now(),@@ -245,6 +250,10 @@ export default function RemoteDesktopScreen() {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 [viewerViewport, setViewerViewport] = useState({ width: 0, height: 0 });const viewportGeneration = useRef(0);@@ -509,6 +518,7 @@ export default function RemoteDesktopScreen() {timing.current?.("stopped");timing.current = null;generation.current++;+ transientFailureAt.current = null;unlockFrame.current?.(false);unlockFrame.current = null;presentation.current = false;@@ -748,6 +758,17 @@ export default function RemoteDesktopScreen() {capsRef.current = { deviceId, value: result };setHostCaps({ deviceId, value: result });if (supportsAutoUnlock(result.platform)) {+ // Linux capture may be unavailable until its locker releases the session.+ if (result.platform === "linux") {+ return securityRef.current.maybeUnlock(async () => {+ if (+ current !== generation.current ||+ !focusedRef.current ||+ !recovery.current.enabled+ )+ throw new Error("CREDENTIAL_CANCELLED");+ });+ }const firstFrame = new Promise<boolean>((resolve) => {unlockFrame.current = resolve;});@@ -981,6 +1002,7 @@ export default function RemoteDesktopScreen() {// when a local transition timed out, retry a release or restore the// local bit so a held key cannot stay down behind a view-only phone.if (active.current !== current || presentation.current) return;+ transientFailureAt.current = null;if (result.controlling === false) {// startInput can still be settling while this heartbeat was in// flight. Clearing a pending take-control here would leave later@@ -998,6 +1020,14 @@ export default function RemoteDesktopScreen() {applyConfirmedControl(current, true);}).catch((cause) => {+ if (active.current !== current) return;+ if (+ streaming.current &&+ remoteDesktopErrorCode(cause) === "DEVICE_OFFLINE"+ ) {+ transientFailureAt.current ??= Date.now();+ if (Date.now() - transientFailureAt.current < 8000) return;+ }// A missing reply does not prove renewal failed; the next interval// retries within the lease. Explicit host revocation still stops us.if (@@ -1180,8 +1210,23 @@ export default function RemoteDesktopScreen() {t,]);useEffect(() => {- if (link.status !== "online" && !presentation.current) pause();- else if (!active.current) void connectRef.current();+ if (link.status !== "online" && !presentation.current) {+ if (!active.current || !streaming.current) {+ pause();+ return;+ }+ transientFailureAt.current ??= Date.now();+ const lease = active.current;+ const timer = setTimeout(+ () => {+ if (active.current === lease && linkRef.current.status !== "online")+ pause();+ },+ Math.max(0, 8000 - (Date.now() - transientFailureAt.current)),+ );+ return () => clearTimeout(timer);+ }+ if (!active.current) void connectRef.current();}, [link.status, pause]);const onMessage = (event: WebViewMessageEvent) => {@@ -1678,6 +1723,21 @@ export default function RemoteDesktopScreen() {.map((code) => ({ kind: "key", code, down: false })),],});+ const workspaceAction = (+ action: "workspaceLeft" | "workspaceRight" | "omarchyMenu",+ ) => {+ if (!lease?.controlling) return;+ const current = active.current;+ void request({ op: "windowAction", action, lease: lease.lease }).catch(+ () => {+ if (active.current === current)+ Alert.alert(+ t(`remoteDesktop.${action}`),+ t("remoteDesktop.settingFailed"),+ );+ },+ );+ };const button = (label: string,onPress: () => void,@@ -1957,6 +2017,20 @@ export default function RemoteDesktopScreen() {top={edgePadding.paddingTop + spacing.sm}/>)}+ {windowsOpen &&+ focused &&+ lease?.controlling &&+ caps?.windowActions && (+ <RemoteDesktopWindows+ key={lease.lease}+ lease={lease.lease}+ request={request}+ caption={deviceName}+ landscape={landscape}+ topInset={edgePadding.paddingTop}+ onClose={() => setWindowsOpen(false)}+ />+ )}{(operations || Platform.OS === "ios") && (<ViewpointerEvents="box-none"@@ -1976,6 +2050,7 @@ export default function RemoteDesktopScreen() {><RemoteDesktopPaneltoolbarOnLeft={toolbarOnLeft}+ toolbarActionCount={caps?.omarchyMenu ? 5 : 4}visible={operations && focused}landscape={landscape}topInset={edgePadding.paddingTop}@@ -2122,20 +2197,55 @@ export default function RemoteDesktopScreen() {><RemoteDesktopToolbarlandscape={landscape}+ onWorkspaceLeft={+ caps?.workspaceNavigation+ ? () => workspaceAction("workspaceLeft")+ : undefined+ }+ onWorkspaceRight={+ caps?.workspaceNavigation+ ? () => workspaceAction("workspaceRight")+ : undefined+ }+ onOmarchyMenu={+ caps?.omarchyMenu+ ? () => workspaceAction("omarchyMenu")+ : undefined+ }canControl={Boolean(lease?.controlling)}keyboard={keyboard}operations={operations}- onWindows={() =>+ onWindows={() => {+ if (caps?.windowActions) {+ setOperations(false);+ Keyboard.dismiss();+ setKeyboard(false);+ setWindowsOpen(true);+ return;+ }shortcut(caps?.platform === "darwin"? ["ControlLeft", "ArrowUp"]: ["MetaLeft", "Tab"],- )- }+ );+ }}onDesktop={() =>- shortcut(- caps?.platform === "darwin" ? ["F11"] : ["MetaLeft", "KeyD"],- )+ caps?.windowActions && lease?.controlling+ ? void request({+ op: "windowAction",+ action: "desktop",+ lease: lease.lease,+ }).catch(() =>+ Alert.alert(+ t("remoteDesktop.showDesktop"),+ t("remoteDesktop.settingFailed"),+ ),+ )+ : shortcut(+ caps?.platform === "darwin"+ ? ["F11"]+ : ["MetaLeft", "KeyD"],+ )}onKeyboard={() => {setOperations(false);diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsxnew file mode 100644index 0000000000..5f446ebc8e--- /dev/null+++ b/apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx@@ -0,0 +1,145 @@+import { useEffect, useRef, useState } from "react";+import { ActivityIndicator, Pressable, View } from "react-native";+import { useTranslation } from "react-i18next";+import type {+ RemoteDesktopRequest,+ RemoteDesktopWindow,+} from "@cindy/device-link";+import { Text } from "@/components/AppText";+import { radius, spacing, typeScale, useTheme } from "@/theme";+import { RemoteDesktopPanel } from "./RemoteDesktopChrome";++export function RemoteDesktopWindows({+ lease,+ request,+ onClose,+ landscape,+ topInset,+ caption,+}: {+ lease: string;+ request<T>(request: RemoteDesktopRequest): Promise<T>;+ onClose(): void;+ landscape: boolean;+ topInset: number;+ caption: string;+}) {+ const { t } = useTranslation();+ const { colors } = useTheme();+ const [windows, setWindows] = useState<RemoteDesktopWindow[] | null>(null);+ const [failed, setFailed] = useState(false);+ const [busy, setBusy] = useState(false);+ const alive = useRef(false);+ const [retry, setRetry] = useState(0);+ useEffect(() => {+ let current = true;+ alive.current = true;+ setFailed(false);+ setWindows(null);+ void request<RemoteDesktopWindow[]>({+ op: "windowAction",+ action: "list",+ lease,+ })+ .then((items) => {+ if (+ !Array.isArray(items) ||+ items.length > 256 ||+ items.some(+ (item) =>+ !item ||+ typeof item.id !== "string" ||+ !/^0x[a-f0-9]{1,16}$/.test(item.id) ||+ typeof item.title !== "string" ||+ item.title.length > 256 ||+ typeof item.app !== "string" ||+ item.app.length > 128,+ )+ )+ throw new Error("INVALID_RESPONSE");+ if (current) setWindows(items);+ })+ .catch(() => {+ if (current) setFailed(true);+ });+ return () => {+ current = false;+ alive.current = false;+ };+ }, [lease, request, retry]);+ const activate = async (id: string) => {+ if (busy) return;+ setBusy(true);+ try {+ await request({ op: "windowAction", action: "activate", lease, id });+ if (alive.current) onClose();+ } catch {+ if (alive.current) setFailed(true);+ } finally {+ if (alive.current) setBusy(false);+ }+ };+ return (+ <RemoteDesktopPanel+ landscape={landscape}+ topInset={topInset}+ title={t("remoteDesktop.allWindows")}+ caption={caption}+ onClose={onClose}+ >+ {failed ? (+ <Pressable+ accessibilityRole="button"+ onPress={() => setRetry((value) => value + 1)}+ style={{ padding: spacing.md }}+ >+ <Text style={{ color: colors.textPrimary }}>+ {t("remoteDesktop.windowsFailed")}+ </Text>+ </Pressable>+ ) : windows === null ? (+ <ActivityIndicator color={colors.textSecondary} />+ ) : windows.length === 0 ? (+ <Text style={{ color: colors.textSecondary }}>+ {t("remoteDesktop.noWindows")}+ </Text>+ ) : (+ <View style={{ gap: spacing.sm }}>+ {windows.map((window) => (+ <Pressable+ key={window.id}+ accessibilityRole="button"+ disabled={busy}+ onPress={() => {+ void activate(window.id);+ }}+ style={{+ minHeight: 56,+ padding: spacing.md,+ borderRadius: radius.control,+ backgroundColor: colors.surfaceElevated,+ gap: spacing.xs,+ }}+ >+ <Text+ numberOfLines={2}+ style={{ fontSize: typeScale.body, color: colors.textPrimary }}+ >+ {window.title || window.app}+ </Text>+ <Text+ numberOfLines={1}+ style={{+ fontSize: typeScale.caption,+ color: colors.textSecondary,+ }}+ >+ {window.app}+ </Text>+ </Pressable>+ ))}+ </View>+ )}+ </RemoteDesktopPanel>+ );+}diff --git a/apps/mobile/src/remote-desktop/__tests__/autoUnlockSettings.test.tsx b/apps/mobile/src/remote-desktop/__tests__/autoUnlockSettings.test.tsxindex 209c1bd922..191db3d518 100644--- a/apps/mobile/src/remote-desktop/__tests__/autoUnlockSettings.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/autoUnlockSettings.test.tsx@@ -138,7 +138,7 @@ it("shows Face ID setting failures without exposing native error details", async"remoteDesktop.autoUnlockUnavailable",);});-it.each(["win32", "linux", undefined])(+it.each(["win32", undefined])("does not access credentials for unsupported host %s",async (platform) => {fixture.hostPlatform = platform;@@ -155,6 +155,37 @@ it.each(["win32", "linux", undefined])(expect(fixture.ensure).not.toHaveBeenCalled();},);+it("uses the existing native credential flow for a locked Linux host", async () => {+ fixture.hostPlatform = "linux";+ fixture.settings.autoUnlock = true;+ fixture.invoke.mockResolvedValue({+ version: 1,+ state: "locked",+ ready: true,+ descriptor: "test-descriptor",+ });+ await act(async () => value.maybeUnlock());+ expect(fixture.ensure).toHaveBeenCalledOnce();+});+it("does not retrieve a password or run authentication for an unsupported Linux locker", async () => {+ fixture.hostPlatform = "linux";+ fixture.settings.autoUnlock = true;+ fixture.invoke.mockResolvedValue({ version: 1, state: "unavailable" });+ await act(async () => value.maybeUnlock());+ expect(fixture.ensure).not.toHaveBeenCalled();+ expect(fixture.biometric).not.toHaveBeenCalled();+ expect(value.notice).toBe("remoteDesktop.linuxUnlockUnavailable");+});+it("explains unsupported Linux setup without opening a password form", async () => {+ fixture.hostPlatform = "linux";+ fixture.invoke.mockRejectedValue(new Error("CREDENTIAL_UNLOCK_UNAVAILABLE"));+ await act(async () => value.onAutoUnlock(true));+ expect(fixture.ensure).not.toHaveBeenCalled();+ expect(fixture.alert).toHaveBeenCalledWith(+ "remoteDesktop.autoUnlock",+ "remoteDesktop.linuxUnlockUnavailable",+ );+});it("uses the just-discovered Mac platform before a React render", async () => {fixture.hostPlatform = undefined;await act(async () => value.maybeUnlock());diff --git a/apps/mobile/src/remote-desktop/__tests__/nativeChrome.test.tsx b/apps/mobile/src/remote-desktop/__tests__/nativeChrome.test.tsxindex 7484563b7a..ccdf144d7a 100644--- a/apps/mobile/src/remote-desktop/__tests__/nativeChrome.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/nativeChrome.test.tsx@@ -95,6 +95,9 @@ vi.mock("@expo/ui/swift-ui/modifiers", () =>),);vi.mock("lucide-react-native", () => ({+ ArrowLeft: () => null,+ ArrowRight: () => null,+ Menu: () => null,Keyboard: () => null,SlidersHorizontal: () => null,}));@@ -170,6 +173,56 @@ it("keeps operations usable without control, with compact landscape order", () =v.close();});+it.each([false, true])(+ "shows Omarchy desktop navigation with five accessible targets (landscape=%s)",+ (landscape) => {+ const left = vi.fn(),+ right = vi.fn(),+ menu = vi.fn();+ const props = {+ landscape,+ canControl: true,+ keyboard: false,+ operations: false,+ onWindows: vi.fn(),+ onDesktop: vi.fn(),+ onKeyboard: vi.fn(),+ onOperations: vi.fn(),+ onWorkspaceLeft: left,+ onWorkspaceRight: right,+ onOmarchyMenu: menu,+ };+ const v = mount(<RemoteDesktopToolbar {...props} />);+ for (const key of ["workspaceLeft", "workspaceRight", "omarchyMenu"])+ act(() =>+ v.host+ .querySelector<HTMLButtonElement>(+ `[data-testid="remoteDesktop.${key}"]`,+ )!+ .click(),+ );+ expect(left).toHaveBeenCalledOnce();+ expect(right).toHaveBeenCalledOnce();+ expect(menu).toHaveBeenCalledOnce();+ expect(v.host.querySelectorAll("button")).toHaveLength(5);+ const surface = v.host.firstElementChild as HTMLElement;+ expect(landscape ? surface.style.height : surface.style.width).toBe(+ "228px",+ );+ expect(+ v.host.querySelector('[data-testid="remoteDesktop.showDesktop"]'),+ ).toBeNull();+ v.render(<RemoteDesktopToolbar {...props} canControl={false} />);+ for (const key of ["workspaceLeft", "workspaceRight", "omarchyMenu"])+ expect(+ v.host.querySelector<HTMLButtonElement>(+ `[data-testid="remoteDesktop.${key}"]`,+ )!.disabled,+ ).toBe(true);+ v.close();+ },+);+it.each([false, true])("keeps one hosted surface while navigating and updating the header (landscape=%s)",(landscape) => {@@ -267,5 +320,7 @@ it("anchors the popover to the centered rail and opens inward after either rotatislandRight ? "leading" : "trailing",);}+ v.render(<RemoteDesktopPanel {...props} toolbarActionCount={5} />);+ expect((v.host.firstElementChild as HTMLElement).style.top).toBe("80.5px");v.close();});diff --git a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsxindex c6fafbd210..82197ade7f 100644--- a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx@@ -212,6 +212,8 @@ vi.mock("lucide-react-native", () => ({createLucideIcon: () => () => null,Clipboard: () => null,ArrowLeft: () => null,+ ArrowRight: () => null,+ Menu: () => null,RotateCw: () => null,Volume2: () => null,VolumeX: () => null,@@ -448,6 +450,32 @@ describe("remote desktop controls", () => {expect(host.textContent).toContain("remoteDesktop.connectionTimeout");});+ it("uses advertised Omarchy actions instead of the legacy desktop buttons", async () => {+ const original = fixture.invoke.getMockImplementation()!;+ fixture.invoke.mockImplementation(async (...args) => {+ const result = await original(...args);+ return args[2][0].op === "capabilities"+ ? {+ ...result,+ platform: "linux",+ workspaceNavigation: true,+ omarchyMenu: true,+ }+ : result;+ });+ await connect();+ for (const action of ["workspaceLeft", "workspaceRight", "omarchyMenu"])+ await act(async () => button(action).click());+ expect(requests().filter((r) => r.op === "windowAction")).toEqual(+ ["workspaceLeft", "workspaceRight", "omarchyMenu"].map((action) => ({+ op: "windowAction",+ action,+ lease: "lease",+ })),+ );+ expect(button("showDesktop")).toBeNull();+ expect(button("allWindows")).toBeNull();+ });it("retries an initial capabilities timeout normally on a legacy host", async () => {const original = fixture.invoke.getMockImplementation()!;let attempts = 0;@@ -1055,7 +1083,6 @@ describe("remote desktop controls", () => {it.each([["android", "darwin"],["ios", "win32"],- ["ios", "linux"],["ios", undefined],])("hides unsupported unlock settings for %s / %s while retaining exit locking",@@ -1226,6 +1253,27 @@ describe("remote desktop controls", () => {{ op: "stop", lease: "lease", lockScreen: true },]);});+ it("prepares Linux unlock before capture without waiting for a first frame", async () => {+ fixture.hostPlatform = "linux";+ let finish!: () => void;+ const prompt = vi.fn();+ fixture.maybeUnlock.mockImplementationOnce(async (beforeAuthentication) => {+ await beforeAuthentication!();+ prompt();+ await new Promise<void>((resolve) => {+ finish = resolve;+ });+ });+ await act(async () => {+ fixture.message!({ nativeEvent: { data: '{"type":"ready"}' } });+ });+ expect(prompt).toHaveBeenCalledOnce();+ expect(requests().some((r) => r.op === "start")).toBe(false);+ await act(async () => {+ finish();+ });+ expect(requests().filter((r) => r.op === "start")).toHaveLength(1);+ });it.each(["framePresented", "streaming"])("prepares authentication alongside capture and waits for %s before Face ID",async (firstFrame) => {@@ -2022,6 +2070,60 @@ describe("remote desktop controls", () => {expect(fixture.invoke).toHaveBeenCalledTimes(1);expect(requests().some((r) => r.op === "start")).toBe(false);});+ it("keeps live video through a brief relay route interruption", async () => {+ await connect();+ act(() =>+ fixture.message!({+ nativeEvent: { data: '{"type":"streaming","epoch":"lease"}' },+ }),+ );+ fixture.status = "offline";+ act(() => root.render(<RemoteDesktopScreen />));+ await act(async () => vi.advanceTimersByTimeAsync(2000));+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);+ fixture.status = "online";+ await act(async () => root.render(<RemoteDesktopScreen />));+ await act(async () => vi.advanceTimersByTimeAsync(9000));+ expect(requests().filter((r) => r.op === "start")).toHaveLength(1);+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);+ });+ it("bounds offline video grace and still obeys explicit host revocation", async () => {+ await connect();+ act(() =>+ fixture.message!({+ nativeEvent: { data: '{"type":"streaming","epoch":"lease"}' },+ }),+ );+ fixture.status = "offline";+ act(() => root.render(<RemoteDesktopScreen />));+ await act(async () => vi.advanceTimersByTimeAsync(8100));+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(1);+ });+ it.each(["DEVICE_OFFLINE", "ACCESS_REVOKED"])(+ "limits transient heartbeat handling to offline errors: %s",+ async (code) => {+ await connect();+ act(() =>+ fixture.message!({+ nativeEvent: { data: '{"type":"streaming","epoch":"lease"}' },+ }),+ );+ const original = fixture.invoke.getMockImplementation()!;+ fixture.invoke.mockImplementation((...args) =>+ args[2][0].op === "heartbeat"+ ? Promise.reject(Object.assign(new Error(code), { code }))+ : original(...args),+ );+ await act(async () => vi.advanceTimersByTimeAsync(3100));+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(+ code === "DEVICE_OFFLINE" ? 0 : 1,+ );+ if (code === "DEVICE_OFFLINE") {+ await act(async () => vi.advanceTimersByTimeAsync(9000));+ expect(requests().some((r) => r.op === "stop")).toBe(true);+ }+ },+ );it("renews again after a lost heartbeat reply without replacing the live lease", async () => {await connect();const original = fixture.invoke.getMockImplementation()!;diff --git a/apps/mobile/src/remote-desktop/__tests__/windows.test.tsx b/apps/mobile/src/remote-desktop/__tests__/windows.test.tsxnew file mode 100644index 0000000000..f853b71350--- /dev/null+++ b/apps/mobile/src/remote-desktop/__tests__/windows.test.tsx@@ -0,0 +1,94 @@+// @vitest-environment jsdom+import { act } from "react";+import { createRoot } from "react-dom/client";+import { afterEach, expect, it, vi } from "vitest";+import { RemoteDesktopWindows } from "../RemoteDesktopWindows";+vi.mock("react-native", () => ({+ View: ({ children }: any) => <div>{children}</div>,+ Pressable: ({ children, onPress, disabled }: any) => (+ <button onClick={onPress} disabled={disabled}>+ {children}+ </button>+ ),+ ActivityIndicator: () => <span>loading</span>,+}));+vi.mock("@/components/AppText", () => ({+ Text: ({ children }: any) => <span>{children}</span>,+}));+vi.mock("@/theme", () => ({+ useTheme: () => ({ colors: {} }),+ radius: {},+ spacing: {},+ typeScale: {},+}));+vi.mock("react-i18next", () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));+vi.mock("../RemoteDesktopChrome", () => ({+ RemoteDesktopPanel: ({ children }: any) => <div>{children}</div>,+}));+let dispose = () => {};+afterEach(() => {+ act(dispose);+});+async function mount(request: any) {+ const element = document.createElement("div");+ const root = createRoot(element);+ const close = vi.fn();+ dispose = () => root.unmount();+ await act(async () => {+ root.render(+ <RemoteDesktopWindows+ lease="lease"+ request={request}+ onClose={close}+ landscape={false}+ topInset={0}+ caption="Test"+ />,+ );+ });+ return { element, close };+}+it("lists host windows and activates the selected ID under the same lease", async () => {+ const request = vi+ .fn()+ .mockResolvedValueOnce([{ id: "0xabc", title: "Document", app: "Editor" }])+ .mockResolvedValue(null);+ const h = await mount(request);+ expect(h.element.textContent).toContain("Document");+ await act(async () => {+ h.element.querySelector("button")!.click();+ });+ expect(request).toHaveBeenLastCalledWith({+ op: "windowAction",+ action: "activate",+ id: "0xabc",+ lease: "lease",+ });+ expect(h.close).toHaveBeenCalledOnce();+});+it("shows a retry for invalid responses and ignores late lists after closing", async () => {+ const request = vi+ .fn()+ .mockResolvedValue([{ id: ";exec", title: "bad", app: "bad" }]);+ const h = await mount(request);+ expect(h.element.textContent).toContain("remoteDesktop.windowsFailed");+ let finish!: (value: unknown) => void;+ request.mockImplementationOnce(+ () =>+ new Promise((resolve) => {+ finish = resolve;+ }),+ );+ await act(async () => {+ h.element.querySelector("button")!.click();+ });+ act(dispose);+ dispose = () => {};+ await act(async () => {+ finish([{ id: "0xabc", title: "late", app: "Editor" }]);+ });+ expect(h.element.textContent).toBe("");+ expect(h.close).not.toHaveBeenCalled();+});diff --git a/apps/mobile/src/remote-desktop/autoUnlockSupport.ts b/apps/mobile/src/remote-desktop/autoUnlockSupport.tsindex be380fd1e5..0c800f6c44 100644--- a/apps/mobile/src/remote-desktop/autoUnlockSupport.ts+++ b/apps/mobile/src/remote-desktop/autoUnlockSupport.ts@@ -1,5 +1,8 @@import { Platform } from "react-native";export function supportsAutoUnlock(hostPlatform: string | undefined) {- return Platform.OS === "ios" && hostPlatform === "darwin";+ return (+ Platform.OS === "ios" &&+ (hostPlatform === "darwin" || hostPlatform === "linux")+ );}diff --git a/apps/mobile/src/remote-desktop/useAutoUnlockSettings.ts b/apps/mobile/src/remote-desktop/useAutoUnlockSettings.tsindex 950052fad8..8e6b390920 100644--- a/apps/mobile/src/remote-desktop/useAutoUnlockSettings.ts+++ b/apps/mobile/src/remote-desktop/useAutoUnlockSettings.ts@@ -214,7 +214,11 @@ export function useAutoUnlockSettings(generation === epoch.current &&activeTarget.current === target) {- const key = credentialErrorKey(error);+ const key =+ getHostPlatform() === "linux" &&+ credentialErrorKey(error) === "credentialUnlockUnavailable"+ ? "linuxUnlockUnavailable"+ : credentialErrorKey(error);const message = t(`remoteDesktop.${key === "credentialRequired" ? "autoUnlockUnavailable" : key}`,);@@ -292,6 +296,14 @@ export function useAutoUnlockSettings({ preSend: current.check },);current.check();+ if (+ status?.version === 1 &&+ status.state === "unavailable" &&+ getHostPlatform() === "linux"+ ) {+ setNotice(t("remoteDesktop.linuxUnlockUnavailable"));+ return;+ }if (status?.version !== 1 || status.state !== "locked") return;if (!beforeAuthentication) attempted.current = true;await change(() =>diff --git a/docs/design-rules/design-inventory.md b/docs/design-rules/design-inventory.mdindex 9cd2b25df4..4c58967380 100644--- a/docs/design-rules/design-inventory.md+++ b/docs/design-rules/design-inventory.md@@ -62,7 +62,7 @@| `mobile.files` | mobile | 任务文件与预览 | app/files/[sessionId].tsx / app/files/preview/[sessionId].tsx | AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, HomeEntryProvider, HtmlFileReader, ImageLightbox, IncomingShareBridge, MarkdownFileReader, MobileLoginHandoffContext, MobileLoginHandoffStage, MobilePrimitives, PushNotificationsBridge, QuietSyncIndicator, SheetModal, SheetSurface, StartupSplashOverlay, ThemeProvider, [sessionId], _layout, gestureHandler, mediaPlayerWebView, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/files/[sessionId].tsx, apps/mobile/app/files/preview/[sessionId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HtmlFileReader.tsx, apps/mobile/src/session/ImageLightbox.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MarkdownFileReader.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/mathWebViewHtml.ts, apps/mobile/src/session/mediaPlayerWebView.tsx, apps/mobile/src/session/mediaPlayerWebViewHtml.ts, apps/mobile/src/session/selectableMarkdownHtml.ts, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 202 | 39 || `mobile.home` | mobile | 主机与资源首页 | app/index.tsx / app/devices/index.tsx | AccountSwitcherSheet, AndroidUpdateSheet, AppText, AuthContext, AutomationTimerIcon, BlurBackdrop, CenteredScreen, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, ConversationSearchFilterSheet, DeviceLinkContext, HomeChromeDrawer, HomeChromeFrost, HomeEntryProvider, HomeGlassMenuPanel, HomeHeaderGlassButton, HomeNativeStackHeader, HomeProjectMachineLabel, HomeSearchBar, IncomingShareBridge, MobileAgentMark, MobileLoginHandoffContext, MobileLoginHandoffStage, MobilePrimitives, MobileVendorIcon, NativePullDownMenu, NativeSwitch, PushNotificationsBridge, QuietSyncIndicator, RemoteAccessGuide, RemoteTaskSuggestions, RenameSessionModal, SessionActionSheet, SessionHeaderNativeControls, SessionHeaderNativeControls.ios, SessionOptionsExpoSheet, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, SwipeableSessionRow, SwipeableSessionRow.ios, ThemeProvider, _layout, gestureHandler, index, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/devices/index.tsx, apps/mobile/app/index.tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileAgentMark.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/MobileVendorIcon.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteAccessGuide.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/session/AccountSwitcherSheet.tsx, apps/mobile/src/session/AutomationTimerIcon.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/ConversationSearchFilterSheet.tsx, apps/mobile/src/session/HomeChromeDrawer.tsx, apps/mobile/src/session/HomeChromeFrost.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeGlassMenuPanel.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/HomeProjectMachineLabel.tsx, apps/mobile/src/session/HomeSearchBar.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/RemoteTaskSuggestions.tsx, apps/mobile/src/session/RenameSessionModal.tsx, apps/mobile/src/session/SessionActionSheet.tsx, apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx, apps/mobile/src/session/SessionHeaderNativeControls.tsx, apps/mobile/src/session/SessionOptionsExpoSheet.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/SwipeableSessionRow.ios.tsx, apps/mobile/src/session/SwipeableSessionRow.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 170 | 60 || `mobile.overlay.connection-startup` | mobile | 根布局挂载的启动与连接反馈 | app/_layout.tsx → StartupSplashOverlay / ConnectionNoticeProvider;各页面 ConnectionBanner | AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ConnectionNoticeProvider, ContextSheet, ContextSheet.ios, DeviceLinkContext, HomeEntryProvider, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobilePrimitives, PushNotificationsBridge, QuietSyncIndicator, SheetModal, SheetSurface, StartupSplashOverlay, ThemeProvider, _layout, gestureHandler, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 170 | 16 |-| `mobile.remote-desktop` | mobile | 远程桌面 | app/devices/desktop/[deviceId].tsx | AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, HomeEntryProvider, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobilePrimitives, NativePullDownMenu, NativeSwitch, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, SheetModal, SheetSurface, StartupSplashOverlay, ThemeProvider, [deviceId], _layout, gestureHandler, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/devices/desktop/[deviceId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 170 | 47 |+| `mobile.remote-desktop` | mobile | 远程桌面 | app/devices/desktop/[deviceId].tsx | AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, HomeEntryProvider, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobilePrimitives, NativePullDownMenu, NativeSwitch, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, SheetModal, SheetSurface, StartupSplashOverlay, ThemeProvider, [deviceId], _layout, gestureHandler, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/devices/desktop/[deviceId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 170 | 48 || `mobile.resources` | mobile | 远程资源列表与详情 | app/resources/[collectionId].tsx / app/resources/[collectionId]/[resourceId].tsx | AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, HomeEntryProvider, HomeNativeStackHeader, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobilePrimitives, NativePullDownMenu, NativeSwitch, PushNotificationsBridge, QuietSyncIndicator, RemoteCompanionAvatar, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, ThemeProvider, [collectionId], [resourceId], _layout, gestureHandler, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/resources/[collectionId].tsx, apps/mobile/app/resources/[collectionId]/[resourceId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteCompanionAvatar.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 170 | 22 || `mobile.settings` | mobile | 设置(含调试与日志上传可见入口) | app/settings.tsx | AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, HomeEntryProvider, HomeNativeStackHeader, IncomingShareBridge, MobileChoicePickerList, MobileLoginHandoffContext, MobileLoginHandoffStage, MobilePrimitives, NativePullDownMenu, NativeSwitch, PushNotificationsBridge, QuietSyncIndicator, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, ThemeProvider, _layout, gestureHandler, peerFileTransport, settings, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/settings.tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileChoicePickerList.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 170 | 24 |diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex eee1c96bfe..78797880e9 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -23,6 +23,19 @@不得退回会留下系统分辨率变化的旧路径;不支持的选择返回“不支持”。旧控制端的无`temporary` 请求及响应保持兼容,其旧行为不代表新恢复能力已生效。此扩展不修改 relay。+## 远程桌面窗口操作++新增可选能力 `windowActions`,只在支持的主机上发送 `windowAction`:`list` 返回有界窗口+列表,`activate` 只接受当前系统枚举的窗口 ID,`desktop` 切换临时空工作区并支持恢复。+三种操作均要求当前同账号控制 lease;撤权后的迟到回复不得暴露窗口标题或继续操作。+新手机对未声明能力的旧电脑保留原快捷键;旧手机仍可连接新电脑。本扩展只走既有业务+隧道,不新增 relay 消息类型、不修改服务端授权或协议实现。++可选能力 `workspaceNavigation` 与 `omarchyMenu` 分别声明左右桌面切换和 Omarchy 菜单。+新控制端仅在能力为真时发送 `windowAction` 的 `workspaceLeft` / `workspaceRight` /+`omarchyMenu`;缺省保留旧工具栏,不向旧主机发送新动作。旧端的 `desktop` 语义不变。+工作区切换作用于采集屏幕,菜单使用本机固定入口,所有操作沿用控制 lease 与撤权检查。+## 自动化检查恢复投影运行状态和已读回执保留历史事实。当前警告只保留未被**同一自动化**更新成功运行恢复的失败;diff --git a/docs/remote-desktop-credentials.md b/docs/remote-desktop-credentials.mdindex 7db9504e87..1f04630304 100644--- a/docs/remote-desktop-credentials.md+++ b/docs/remote-desktop-credentials.md@@ -8,10 +8,11 @@ Mobile places **Security** at the bottom of the remote desktop control panel,after display settings. Automatic unlock defaults off. Face ID only protects asaved password; turning automatic unlock off deletes the local saved password.-Automatic unlock targets iOS controlling macOS. Android hides the unsupported+Automatic unlock targets iOS controlling macOS or supported Linux lock screens+(see the Linux integration and acceptance limits below). Android hides the unsupportedautomatic-unlock and biometric settings; its independent lock-on-exit settingremains available when the host advertises support. This does not add a new server,-identity registry, database migration, or deployment requirement. The existing+identity registry, database migration, or server deployment requirement. The existingrelay still authenticates the account and carries messages. Native iOS/macOScredential code performs no identity-directory HTTP requests or polling.@@ -214,3 +215,80 @@ change height within its viewport limit; the stable-height contract applies tothe settings panel and asynchronous feedback, not to different keyboard layouts.Light/Dark use the same geometry and semantic colors. Automated layout-contractchecks do not replace physical-device visual acceptance.++## Linux: existing system interfaces only++The Linux adapter reuses the v1 signed/encrypted credential messages and the iOS+native password vault. It adds no relay message, server dependency or migration.+Ordinary viewing/control remains independent of automatic unlock. An unsupported+or unavailable Linux locker returns `CREDENTIAL_UNLOCK_UNAVAILABLE` before any+password form opens; a saved-password reconnect checks status before reading the+secret or requesting biometrics. The phone explains the limitation and retains+ordinary remote access.++On Linux, the viewer completes optional automatic-unlock preparation before starting+capture, since a locked compositor may not provide frames. Leaving the viewer cancels+the pending start. macOS retains its existing first-frame-before-biometrics flow.++The implemented target is **Hyprlock on Hyprland**, using its documented+[SIGUSR1 unlock interface](https://wiki.hypr.land/Hypr-Ecosystem/hyprlock/).+The helper first verifies the current user's password and account through the+system `hyprlock` PAM service. It then rechecks the current local, active Wayland+session, user, compositor lock, and the same root-owned Hyprlock executable/PID+start time. A pidfd targets that exact process. One signal is sent, and success+requires the compositor lock to disappear; PAM success alone is insufficient.+There is no keyboard injection, root service, compositor force-unlock, PAM edit,+replacement locker or installation of an Omarchy extension.++The compositor probe requires `solitaryBlockedBy` in `hyprctl -j monitors` and+uses its `LOCK` reason (also used by Omarchy's existing session-lock probe).+Missing monitor/workspace evidence, inactive/foreign sessions, unknown lockers,+stranded locks and ambiguous processes fail as unavailable. Logind's advisory+`LockedHint` alone is not evidence of unlocking. Older Hyprland versions without+this probe are unsupported. SDDM/pre-login, disk encryption, GNOME/KDE and+Quickshell/Omarchy's built-in lock are not enabled by this implementation.++The isolated Python helper uses **JWCrypto** for ES256 and ECDH-ES/A256GCM with+the same strict JOSE header allowlists and session binding as the Swift core.+Only public descriptors, encrypted replies and authenticated desktop commands+cross Electron stdio; the PAM subprocess receives password bytes only through+its private stdin. Core dumps are disabled. Cancellation/parent exit closes+credential sessions and terminates pending PAM work. Repeated attempts are+deduplicated and limited across peer reconnects within the helper; the system+PAM failure policy remains authoritative across process restarts.++Host signing identities are stored in the desktop **Secret Service**, scoped by+profile and region. Only a public fingerprint is written under userData. A locked,+missing or changed pinned key never falls back to plaintext or silent replacement.+Unlike macOS's helper-restricted Keychain key, Linux Secret Service does not+provide isolation from a compromised process running as the same OS user.++### Runtime and distribution++Linux packaging includes `native/remote-desktop/linux-credentials/*.py` (excluding+tests) and its requirements manifest. The optional feature requires system Python+3.11+, JWCrypto 1.6.1+, PyGObject with the Secret-1 typelib, libpam, loginctl,+Hyprland and Hyprlock with `/etc/pam.d/hyprlock`. The default Secret Service+collection must be available. Runtime code never downloads packages or changes+system configuration. Distribution builds/users must provide these optional+dependencies; otherwise the feature reports unavailable. This is not a claim+that every Linux installation gains automatic unlock after updating Cindy.++### Validation and release boundary++Run `node apps/desktop/native/remote-desktop/linux-credentials/test.mjs <python>`+with JWCrypto installed in that interpreter. Tests use only fake credentials and+temporary storage, cover cancellation, replacement lockers, failed PAM, replay,+key continuity and rate limits, and exchange messages with the independent Node+`jose` implementation. This verifies the wire profile, not a real iOS/Hyprlock+unlock. The development machine runs Quickshell, intentionally unsupported under+the user's existing-interface-only requirement; no real password or physical+lock/unlock has been exercised here.++The existing native password/biometric labels still say “Mac”. This change keeps+those bundled resources unchanged to avoid requiring a new mobile installation+solely for wording. Linux credential support does not depend on that label.+Correcting it to “computer” requires a separately approved native mobile release:+the resource is included in both iOS and Android runtime fingerprints, even though+Android automatic unlock remains hidden. Do not describe unpublished mobile code+as delivered to the phone.diff --git a/docs/remote-desktop.md b/docs/remote-desktop.mdindex 51eae651ef..8ab7623cef 100644--- a/docs/remote-desktop.md+++ b/docs/remote-desktop.md@@ -197,15 +197,15 @@ both sides. Duplicate candidates are applied once. A timed-out exchange doesnot tear down healthy video; polling is bounded to 30 seconds. SDP, candidateaddresses, credentials and desktop content are not added to logs.-| Phase | Bound |-| --- | --- |-| Desktop source enumeration | 2 seconds with native capture, 5 seconds otherwise |-| Desktop offer command | 18 seconds |-| Remote-desktop invoke | 30 seconds; other invoke channels are unchanged |-| Viewer waiting for answer | 25 seconds |-| ICE checks after answer | 15 seconds |-| Temporary media disconnect | 5-second grace period |-| Automatic media retries | 1, 3 and 8 seconds; restored after 30 seconds connected |+| Phase | Bound |+| -------------------------- | ------------------------------------------------------- |+| Desktop source enumeration | 2 seconds with native capture, 5 seconds otherwise |+| Desktop offer command | 18 seconds |+| Remote-desktop invoke | 30 seconds; other invoke channels are unchanged |+| Viewer waiting for answer | 25 seconds |+| ICE checks after answer | 15 seconds |+| Temporary media disconnect | 5-second grace period |+| Automatic media retries | 1, 3 and 8 seconds; restored after 30 seconds connected |On a transient disconnect the viewer keeps the picture, releases held input andshows the existing reconnecting badge. Input uses the existing authorized invoke@@ -355,11 +355,106 @@ remote input and CUA calls in this Cindy process: physical keyboard/mouse input,other applications, and separate Cindy processes are outside it. Native eventposting is not proof that an application has finished handling those events.+## Wayland capture lifetime++On Hyprland with the system `/usr/bin/grim` executable, Cindy uses native screencopy+for unattended viewing. Existing remote-control and remote-desktop opt-ins, peer+revocation checks and expiring leases authorize each connection. No portal picker,+restore token, system permission override or persistent image is involved. The+compositor's own capture permission still applies; a refusal produces no frame.+Hyprland outputs have stable `hyprland:<output-name>` IDs and logical geometry.+The legacy whole-desktop ID remains accepted for old viewers. The JPEG backing layer and+WebRTC video share the actual desktop aspect ratio, including 16:10 displays. Each+bounded JPEG pull is serialized, kept in memory and cancelled on disconnect.+The existing canvas/WebRTC and JPEG relay transports consume these frames.+For a selected unrotated output, a persistent Wayland screencopy child reuses its+connection and shared-memory pixel buffer. JPEG encoding uses libjpeg-turbo;+frames stay in memory, capped at a 1920-pixel long edge and 1 MB each, with serial pulls targeting the+negotiated 30/60 fps (not a guaranteed delivered rate). Capture/decode time counts+toward the frame interval instead of adding another full interval afterward.+Unsupported layouts or unavailable helpers use grim for the remainder of the+lease. Disconnect kills the child; EOF, a three-second capture/write deadline,+and a ten-second idle watchdog bound orphaned processes. No new peer protocol or+permission grant is introduced. This requires a running user desktop session; capture while locked, after logout or+before login is not promised. PipeWire audio support is described below.++Hyprland control is advertised only when the bundled input helper can find the+Wayland virtual-pointer and virtual-keyboard protocols. Taking control creates+user-session virtual devices; no root service, uinput permission change or shell+command injection is involved. Selected-output mouse coordinates are mapped into+the full logical layout, including negative origins and mixed scales. Layout+changes release input before its coordinate mapping can become stale.+The existing native-helper handshake, serialized acknowledgements,+input ownership and disconnect teardown apply. EOF releases held buttons/keys;+a six-second watchdog releases input if its parent stops responding (with a+one-second hard shutdown bound if the compositor is also stalled).+Text uses a temporary virtual keyboard and in-memory Unicode keymap, never the+clipboard or process arguments. Text is paced and sent in acknowledged chunks+of at most 256 code points so long pastes stay within the helper deadline. Physical key events use a US virtual keyboard layout. English and+Chinese text are validated; supplementary-plane symbols (including emoji) can+be truncated by Chromium’s Wayland text handling even with a correct keysym. Other Wayland+compositors keep their existing view-only portal path.++Linux native builds require `cc`, `pkg-config`, `wayland-scanner`, and development+headers for `wayland-client`, `xkbcommon`, `json-c`, `libturbojpeg`, and `libpng`; packaged builds include+the helpers and require the corresponding shared libraries. In development it is+compiled into the existing userData native cache. Missing support keeps viewing+available and does not advertise control. Native parser checks (no compositor or+input injection): `node --test apps/desktop/native/remote-desktop/linux-input/test.mjs`.+Capture buffer/stride/scaling checks use synthetic pixels with ASan/UBSan:+`node --test apps/desktop/native/remote-desktop/linux-capture/test.mjs`.++On this 2560×1600 Hyprland machine, the final persistent helper averaged 36.9 ms+per frame (including scaling/JPEG), compared with 317.2 ms for per-frame grim.+A local Chromium/WebRTC loop decoded 60 frames in five seconds, retained the+16:10 aspect ratio, and used the persistent helper throughout. That loop includes+the test driver's bridge and automatic WebRTC resolution adaptation; it is not a+phone/network latency benchmark or a guarantee of 30/60 fps. Desktop types,+related unit tests and native memory/bounds checks pass. Phone-side smoothness+and packaged Linux startup still require validation.++Other Linux Wayland environments (including XWayland applications) expose+one portal-selected surface. Electron's PipeWire source is not a physical monitor+enumeration and may have an empty `display_id`; see the+[Electron Linux caveat](https://www.electronjs.org/docs/latest/api/desktop-capturer#linux)+and [source contract](https://www.electronjs.org/docs/latest/api/structures/desktop-capturer-source).+The host advertises one view-only display slot. Its initial 1280×720 geometry is a+viewport placeholder; video/JPEG dimensions describe the selected surface. The+existing viewer fallback supplies its localized display name.++A lease creates one isolated capture window and starts one system picker. Local+consent may take up to two minutes, independently of each bounded video RPC. A+video attempt timing out stops only its peer; it does not reopen the picker.+Subsequent offers clone the same authorized stream, and the existing JPEG frame+operation snapshots that stream, without enumerating sources again. Frames while+permission is pending or the video track is muted are empty. Denial stays terminal+for that lease; polling does not ask again. There is no persistent capture token or+new unattended access grant.++Explicit stop, lease expiry, host disable/revocation, capture-process failure and+system sharing termination dispose the capture owner. Every late portal callback+rechecks both the owner generation and lease. Since Electron does not expose+cancellation for an in-flight `getSources`, a still-pending picker also blocks a+second picker after lease replacement; dismiss it before reconnecting. Its result+cannot authorize the replacement lease.++This changes Desktop internals only: old phone/desktop viewers retain the existing+capabilities, lease, offer, ICE and frame protocol. On the portal fallback, Linux input/audio support is+unchanged. X11, macOS and Windows retain their capture paths. No relay reconnect,+server change, mobile native dependency or runtime fingerprint change is needed.++Regression coverage includes delayed consent, one-shot selection, video timeout+with JPEG fallback, revocation before selection, stale replies, ended/muted tracks,+clone ownership and bounded JPEG size. Real compositor/phone validation still needs+the running build: select a screen locally, check video and JPEG fallback, retry+video without another picker, then stop sharing and verify capture terminates.+## Platform and verification limitsmacOS uses a signed Swift helper; Windows uses a Rust helper with Win32 SendInput.-Forge builds and packages both through the existing tools signing paths. Linux-currently offers viewing only. Neither helper bypasses OS security boundaries:+Forge builds and packages them through the existing tools signing paths. Linux+Hyprland uses the Wayland virtual input helper described above; other Linux+paths remain view-only. No helper bypasses OS security boundaries:Windows secure desktop/UAC and elevated applications can reject input, andmacOS lock/login screens and protected surfaces are not guaranteed controllable.System audio and explicit clipboard transfers are supported when advertised by the host. Virtual displays and remote power-on are not included. The phone keyboard sends committed text directly; the computer keyboard supplies modifiers and special keys.@@ -399,7 +494,20 @@ System audio defaults on with the viewer preference saved locally, supported onsingle-use display capture grant tied to the current offer, lease and trustedmain renderer. No microphone is captured. macOS packaging declaresNSAudioCaptureUsageDescription; development launchers must also have the OS-permission. Linux audio is not advertised.+permission. Hyprland hosts with `pw-record` capture the default PipeWire output+monitor as 48 kHz stereo float PCM. The trusted capture renderer schedules at most+150 ms into an AudioContext destination and adds its track to the existing WebRTC+stream; it never connects to local speakers. Main retains at most 100 ms of PCM,+checks the exact capture window and opted-in video lease on every read, and stops+the child on disconnect, capture failure, a stalled producer or absent consumer.+This does not add audio to the compatibility JPEG transport.++Linux host mute uses PipeWire `softMute` on the playback branch, retaining the+monitor signal for the phone. It restores the original state of the exact output+object (including its serial), even if the default output changes; an unplugged+output cannot cause restoration to modify a reused node ID. Requires `pactl`,+`pw-dump` and `pw-cli`. A null-output integration test verifies that playback mute+leaves the captured tone nonzero; Chromium/WebRTC tests verify remote decoding.`displayModes` and `resolution` operate on the lease's display. macOS usesCoreGraphics mode enumeration and applies only an available mode ID for the@@ -407,8 +515,182 @@ current login session. The operation requires control and rechecks lease andauthorization after native preparation. It changes the actual computer display,not just the encoded image. Geometry changes release capture/input; only thisremote desktop reconnects with fresh dimensions. The shared relay and other-peer links remain untouched. Windows/Linux display mode changes are currently-unavailable and are not advertised.+peer links remain untouched. Hyprland enumerates the selected output's native+modes and accepts only an ID from that enumeration. Both legacy and Lua config+interfaces are supported; no configuration files are written. Windows display+mode changes remain unavailable.++Hyprland phone-fit uses a uniquely named headless display and temporarily mirrors+it to the original output. A Python standard-library helper owns the mirror and+workspace moves. EOF, missed heartbeats and termination restore the source and+remove only its own output; restoration retries keep the in-memory snapshot alive+through temporary compositor errors. A missing source is treated as unplugged.+The helper requires a running user compositor and Python 3. It does not provide+pre-login access or a physical privacy screen. Explicit mirror/special-workspace+configurations are rejected rather than being silently replaced. Live scratch+output tests cover resize, EOF, heartbeat timeout and SIGTERM cleanup.++Linux clipboard transfer uses the existing bounded portable-format path and an+opaque content generation. Reads refuse a locked or unknown login session.+Hyprland reads use bounded `wl-paste` calls, so an unfocused Cindy window can+read the actual system clipboard. A bundled data-control writer offers text,+HTML, RTF and PNG together, without subprocess arguments or temporary files+containing clipboard data. It owns only the explicitly copied value until+replacement or app exit; it does not observe later clipboard changes. Native+parser checks run with ASan/UBSan via+`node --test apps/desktop/native/remote-desktop/linux-clipboard/test.mjs`.+Live tests verify simultaneous text/HTML/RTF offers and native text/HTML reads.+`loginctl lock-session` implements lock-on-exit; success requires `LockedHint=yes`,+not merely successful delivery of the lock request. An installed session locker+is required. Real phone clipboard, lock and sound playback still need end-to-end+validation with the running development build.++When the mobile viewer is already streaming, a transient relay `DEVICE_OFFLINE`+gets at most eight seconds to recover. A brief link-status transition does not+tear down a healthy RTC stream. Explicit revocation, local stop, backgrounding+and host lease expiry retain their existing behavior. Recovery is scoped to this+viewer; it never resets a shared relay or another peer's pending requests.++Hyprland cursor overlay uses `ext-image-copy-capture-v1` on the video helper's+Wayland connection. Bounded PNG cursor images and hotspots reuse the existing+cursor protocol. Hyprland 0.56 can return a transparent compositor-owned cursor;+in that case capture includes the OS pointer in the video and clears independent+cursor metadata. This preserves the actual pointer without a duplicate overlay.+Linux physical privacy uses the version-bound compositor integration below.+Persistent capture handles all eight Wayland output+rotations/reflections, including inverted and padded buffers, after bounded+scaling. Transformed outputs embed the compositor cursor into video; they do not+advertise a separately transformed cursor image. Layout changes during a frame+discard that frame and require fresh geometry. Synthetic native tests cover all+eight transforms with both buffer row directions under ASan/UBSan.++### macOS / Linux host parity audit (2026-09-18)++The comparison is against Cindy's implemented macOS host, not generic OS features.+Linux entries below refer to the Hyprland adapter; the generic portal fallback+remains view-only. An advertised capability and passing unit tests are not evidence+of physical phone end-to-end parity.++| Capability | macOS implementation | Hyprland implementation / remaining gap |+| ------------------------------------ | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| Video and reconnect | Native capture, WebRTC, JPEG fallback | Persistent Wayland capture, same viewer/transport/reconnect lifecycle; encoder and performance differ |+| Sound | ScreenCaptureKit system output | PipeWire output monitor; no microphone |+| Keyboard, pointer, committed text | Native input helper | Wayland virtual keyboard/pointer; same bounded input protocol |+| Cursor shape | Native cursor metadata | Separate cursor image/hotspot and cursor-free video on the supported Hyprland native path; unsupported layouts/backends retain the embedded pointer |+| Monitor selection | OS display enumeration | Compositor output enumeration |+| Frame rate and quality | Shared 30/60 fps and bitrate options | Same options and adaptive WebRTC path; targets are not a measured fps guarantee |+| Resolution and phone fit | CoreGraphics modes, temporary virtual display | Native modes, temporary headless output/mirror, restore-on-exit helper |+| Text, rich clipboard, image and sync | Native portable clipboard | Data-control clipboard, same limits and consent/lease checks |+| Local speaker mute | System output mute and restore | PipeWire playback soft mute preserving the remote monitor signal |+| Lock on disconnect | Verified native lock shortcut | Omarchy shell lock IPC plus compositor `secure` acknowledgement; other desktops use logind request plus `LockedHint`; requires a running locker |+| Automatic unlock | Native credential channel and system integration | Hyprlock only; current Omarchy Quickshell remains unsupported, as documented in `remote-desktop-credentials.md` |+| Physical privacy screen | Excluded masks on every display, physical-input interception, local exit confirmation | Hyprland 0.56.2 native output masking after the capture copy, physical/virtual input separation, local confirmation and owner watchdog |+| Desktop navigation | Mission Control / system shortcuts | Capability-gated left/right workspace buttons on the captured monitor and an Omarchy menu button when installed; legacy viewers retain the window picker and temporary empty-workspace toggle |+| PiP, rotation, gestures | Mobile viewer functionality | Same viewer functionality, subject to phone/runtime support |++Linux's window picker supplies selection/switching, not macOS Mission Control's+thumbnail animation. Quickshell auto-unlock remains unavailable under the+existing-system-interface constraint. These differences and the unverified+physical phone scenarios must not be described as complete macOS parity.++The mobile toolbar uses `workspaceNavigation` to replace its first two actions+with left/right desktops (`m-1` / `m+1`, existing workspaces on the selected+monitor). `omarchyMenu` adds a fifth action, invoking the fixed local+`omarchy menu summon` entry point. Keyboard and Controls remain available.+Both native iOS and shared mobile chrome size the toolbar for its action count;+the landscape popover stays anchored to Controls. Old hosts keep their original+toolbar, and all new host actions require an active controlling lease.++### Hyprland native privacy integration++`native/remote-desktop/hyprland-privacy` builds only against Hyprland 0.56.2.+Runtime checks the compositor commit and the complete plugin ABI hash before+installing hooks; unknown versions fail closed. Build dependencies are a C++26+compiler, `pkg-config`, matching Hyprland headers and `json-c`. Forge includes the+adapter when matching headers are present. Other builds do not advertise it.+Source-mode builds use the existing per-user native-helper cache. Merely reading+capabilities does not compile/load a plugin or change compositor configuration.++The same version-bound integration repairs Hyprland 0.56.2 cursor export for+compositor-owned cursors. A cursor-only framebuffer read uses the bounded SHM+cursor image after the original permission/source-overlap decision; ordinary+screen reads and denied cursor reads retain the compositor path. The cursor+buffer's stride-returning API is handled separately from client SHM allocation+lengths. Hotspot events are sent before the matching frame is ready, including+shape changes that complete a pending frame before the next monitor commit.+This feeds the existing Mac/mobile cursor overlay protocol, without a new wire+format or mobile native module. Nested-compositor checks cover arrow/text/arrow+image and hotspot changes, cursor permission denial, and privacy plus capture.+Physical phone end-to-end remains a manual validation target.++Software cursors are deferred until after the capture/mirror copy, then drawn+on the local output before its final presentation/privacy mask. Mirrored local+outputs restore the cursor with the desktop's aspect-fit geometry. Explicit+cursor-inclusive screencopy requests still draw a cursor; cursor-free requests+no longer inherit the software cursor from the mirror texture. Hyprland 0.56.2+reports cursor positions in logical coordinates, so the capture helper applies+the selected output scale before normalizing against physical video dimensions.+This prevents host position updates from pulling the phone pointer backwards+after a touchpad gesture on fractional-scale displays.++`linux-capture/test.mjs` covers coordinate normalization and clamping under+ASan/UBSan. The opt-in `linux-capture/cursor.integration.py <plugin.so> <capture>`+starts disposable nested compositors and compares cursor-region pixels at 100%+and 160% scale, for both separated and legacy embedded cursor modes. It never+loads the test plugin into the user's compositor. Additional nested checks+verified the local cursor remains visible, including the phone-fit mirror, and+privacy still shows Cindy locally while preserving the remote desktop image.++The first authorized connection prepares the optional compositor plugin through+`hyprctl` before allocating a lease or temporary output. Hyprland reloads its+configuration when plugins are loaded/unloaded, so preparation waits for that+reload and never runs under an active capture. Privacy toggles only use an+already-prepared matching plugin. No configuration files or system lock behavior+are changed. Mask drawing runs inside the normal final-copy pass, after saving+the unmasked capture/mirror image and before copying to the physical output.+It must not draw after `CHyprOpenGLImpl::end()` has invalidated framebuffer state:+that produced all-black continuous captures on the physical DRM output despite+passing nested-compositor tests. While privacy is active, each rendered output+is fully damaged before rendering so a previous mask cannot enter the next+capture through partial redraw. Text textures explicitly declare their sRGB+color space. No extra frame is scheduled by this redraw rule;+direct scanout is inhibited while owned. All enabled physical outputs, including+mirrors used by phone-fit mode, are covered; headless capture outputs stay unmasked.+The Linux mask embeds the same Cindy illustration and light/dark wordmarks as+`privacyScreenHtml` at build time, with horizontal/vertical layouts. Artwork is+part of the native cache identity; the compositor does not read image paths or+fetch resources. Both themes were visually checked in an isolated compositor,+with continuous remote capture remaining unmasked.+The host waits for first rendered+masks before acknowledging the toggle. Physical input is consumed before normal+bindings/application delivery; injected input can operate the desktop, but is+fenced during local exit confirmation. The initiating press/repeat/release cannot+answer the confirmation. Remote input drains before that confirmation opens.++The six-second compositor watchdog restores local access if the owning app dies+or stops renewing. Lease end, revocation and normal disable stop the mask. A late+start reply retires only its own token. Plugin updates can retire an idle build+atomically; an active owner's plugin is never unloaded. Local IPC uses the+existing same-user compositor trust boundary and never carries passwords.++Validated in an isolated nested Hyprland session: remote capture retained test+content while local output displayed privacy/confirmation; physical input opened+the confirmation, virtual Enter could not answer it, and local cancel/disconnect+worked in both Light and Dark. Watchdog expiry and idle-only retirement passed.+Native input-state tests run under ASan/UBSan. The September 18 black-frame+regression was reproduced on the actual 2560×1600 eDP-2 DRM output at scale 1.6:+old code yielded zero mean and zero standard deviation throughout privacy;+the corrected final-copy path preserved nonblack continuous capture frames.+Real phone end-to-end, touchscreen and other GPU combinations remain manual+validation targets.++The additive `windowActions` capability gates `windowAction` list/activate/desktop+requests. They require the controlling lease; only currently enumerated window+IDs reach fixed dispatchers. Lua and legacy Hyprland dispatcher syntax are probed+without changing settings. Replies after revocation are discarded. Desktop+restoration waits for in-flight actions and does not undo independent local+workspace navigation. Old viewers/hosts retain their existing shortcuts; the+relay and its authorization rules are unchanged.System PiP is offered only when WebKit reports support for this video and thenative presentation module and host backgroundViewing capability are present.@@ -486,7 +768,6 @@ Remaining platform adapters are explicitly separate:The macOS pre-login and Linux service adapters remain unimplemented. The remote business protocol and shared relay are unchanged. Recoveryaffects only this desktop lease/video track, not other connected peers.-### Windows system service (implementation awaiting Windows runtime validation)Packaged Windows builds include a native SCM service, a Main-only Node-API pipe@@ -519,10 +800,9 @@ TypeScript checking. Still required on Windows 10/11: signed package linking andinstallation, administrator consent/cancellation, lock/unlock, UAC, policy-enabledSAS, mixed-DPI displays, worker cleanup, upgrade/uninstall, and plugin rejection.Windows display-mode changes and pre-login/unattended post-reboot control are not-implemented. Linux remains deferred. Do not present this as fully validated+implemented. A Linux pre-login service remains deferred. Do not present this as fully validatedWindows support or advertise high-frame-rate secure capture.-### Keyboard clipboard actionsThe keyboard's leading clipboard button opens two actions in both phone and@@ -554,7 +834,6 @@ TypeScript and native compilation checks cover this implementation. Keyboard/meninteraction, application-specific selection support, and physical-phone transferhave not been exercised; manual verification remains with the user.-### Portable clipboard contentNew peers advertise optional `clipboardContent`; legacy `clipboardText` and its@@ -656,7 +935,6 @@ capture returning cursor geometry/raster metadata. Real phone gestures,application-by-application cursor transitions and sustained frame rate remainfor manual verification.-## Clipboard and connection handoffThe keyboard clipboard menu offers Copy to phone and Paste from phone. Copydiff --git a/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.ts b/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.tsindex ac2cb10985..3021e4a97c 100644--- a/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.ts+++ b/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.ts@@ -105,6 +105,37 @@ function deferred<T>() {return { promise, resolve, reject };}+it.each([false, true])(+ "waits for unlock preparation and respects cancellation=%s",+ async (cancel) => {+ const f = fixture();+ const ready = deferred<void>();+ const entered = deferred<void>();+ const connecting = f.session.connect({+ isCurrent: () => true,+ onCapabilities: () => {+ entered.resolve();+ return ready.promise;+ },+ });+ await entered.promise;+ expect(f.request.mock.calls.map(([r]) => r.op)).toEqual(["capabilities"]);+ const stopping = cancel ? f.session.stop() : undefined;+ ready.resolve();+ if (cancel) {+ await expect(connecting).rejects.toThrow("DESKTOP_VIDEO_STOPPED");+ await stopping;+ expect(f.request.mock.calls.map(([r]) => r.op)).toEqual(["capabilities"]);+ } else {+ await connecting;+ expect(f.request.mock.calls.map(([r]) => r.op)).toEqual([+ "capabilities",+ "start",+ ]);+ }+ },+);+it("does not mark a capabilities failure as a start attempt on an older host", async () => {const current = fixture();const onStart = vi.fn();diff --git a/packages/device-link/src/remoteDesktop.ts b/packages/device-link/src/remoteDesktop.tsindex 1cf7783c96..fa7be668d7 100644--- a/packages/device-link/src/remoteDesktop.ts+++ b/packages/device-link/src/remoteDesktop.ts@@ -113,6 +113,11 @@ export interface RemoteDesktopDisplay {width: number;height: number;}+export interface RemoteDesktopWindow {+ id: string;+ title: string;+ app: string;+}export interface RemoteDesktopCapabilities {version: 1;enabled: boolean;@@ -145,6 +150,10 @@ export interface RemoteDesktopCapabilities {clipboardInline?: boolean;privacyScreen?: boolean;hostMute?: boolean;+ /** Explicit host actions, independent of user-configured keyboard bindings. */+ windowActions?: boolean;+ workspaceNavigation?: boolean;+ omarchyMenu?: boolean;}export type DesktopPermission = "screenRecording" | "accessibility";export type DesktopPermissionStatus =@@ -169,6 +178,13 @@ export interface RemoteDesktopLease {controlling: boolean;}export type RemoteDesktopRequest =+ | { op: "windowAction"; lease: string; action: "list" | "desktop" }+ | {+ op: "windowAction";+ lease: string;+ action: "workspaceLeft" | "workspaceRight" | "omarchyMenu";+ }+ | { op: "windowAction"; lease: string; action: "activate"; id: string }| {op: "privacyScreen";lease: string;@@ -233,6 +249,23 @@ export function parseRemoteDesktopRequest(if (typeof v.lease !== "string" || v.lease.length > 128 || !v.lease)throw new Error("INVALID_LEASE");const lease = v.lease;+ if (v.op === "windowAction") {+ if (+ v.action === "list" ||+ v.action === "desktop" ||+ v.action === "workspaceLeft" ||+ v.action === "workspaceRight" ||+ v.action === "omarchyMenu"+ )+ return { op: v.op, lease, action: v.action };+ if (+ v.action === "activate" &&+ typeof v.id === "string" &&+ /^0x[a-f0-9]{1,16}$/.test(v.id)+ )+ return { op: v.op, lease, action: v.action, id: v.id };+ throw new Error("INVALID_REQUEST");+ }if (v.op === "privacyScreen" && typeof v.enabled === "boolean") {if (v.lockOnExit !== undefined && typeof v.lockOnExit !== "boolean")throw new Error("INVALID_REQUEST");diff --git a/packages/device-link/src/remoteDesktopViewerSession.ts b/packages/device-link/src/remoteDesktopViewerSession.tsindex f53dfd4705..221e2939f6 100644--- a/packages/device-link/src/remoteDesktopViewerSession.ts+++ b/packages/device-link/src/remoteDesktopViewerSession.ts@@ -18,7 +18,7 @@ interface ViewerConnectOptions {resume?: boolean;takeover?: boolean;isCurrent: () => boolean;- onCapabilities?: (caps: RemoteDesktopCapabilities) => void;+ onCapabilities?: (caps: RemoteDesktopCapabilities) => void | Promise<void>;onStart?: () => void;}@@ -80,7 +80,7 @@ export class RemoteDesktopViewerSession {if (!caps.enabled) throw new Error("DESKTOP_DISABLED");if (options.resume && !caps.automaticReconnect)throw new Error("CHANNEL_NOT_ALLOWED");- options.onCapabilities?.(caps);+ await options.onCapabilities?.(caps);check();const display =caps.displays.find((d) => d.id === options.displayId) ?? caps.displays[0];diff --git a/scripts/__tests__/restart-desktop-remote.test.mjs b/scripts/__tests__/restart-desktop-remote.test.mjsindex 987ee23932..20a46052e8 100644--- a/scripts/__tests__/restart-desktop-remote.test.mjs+++ b/scripts/__tests__/restart-desktop-remote.test.mjs@@ -55,6 +55,7 @@ import {shouldSuggestIsolatedNext,} from "../desktop-dev-verdict.mjs";import {+ applyLinuxRendererEvidence,collectDesktopWhoamiReport,identifyDesktopProcesses,mergeDesktopInstanceRecords,@@ -1329,3 +1330,29 @@ test("assertDesktopRestartStepSucceeded throws so runner can print a verdict", ((error) => error instanceof DesktopRestartStepError && error.alreadyHasVerdict === true,);});++test('Linux readiness binds the reported renderer to a live descendant in the same checkout', () => {+ const rootDir = path.resolve('/repo/cindy');+ const executable = path.join(rootDir, 'node_modules', 'electron', 'dist', 'electron');+ const scanned = [{ pid: 10, rootDir, ready: false, state: 'starting' }];+ const records = [{ pid: 10, rootDir, state: 'ready', rendererPid: 12 }];+ const processes = [+ { pid: 10, ppid: 1, command: `${executable} .` },+ { pid: 11, ppid: 10, command: `${executable} --type=zygote` },+ { pid: 12, ppid: 11, command: `${executable} --type=zygote` },+ ];+ assert.equal(applyLinuxRendererEvidence(scanned, records, processes, 'linux')[0].ready, true);+ for (const recordsVariant of [[], [{ ...records[0], rendererPid: 99 }],+ [{ ...records[0], rootDir: path.resolve('/other') }], [{ ...records[0], state: 'starting' }]]) {+ assert.equal(applyLinuxRendererEvidence(scanned, recordsVariant, processes, 'linux')[0].ready, false);+ }+ for (const replacement of [+ { ...processes[2], ppid: 99 },+ { ...processes[2], command: '/other/electron --type=zygote' },+ { ...processes[2], command: `${executable} --type=utility` },+ ]) {+ assert.equal(applyLinuxRendererEvidence(scanned, records, [...processes.slice(0, 2), replacement], 'linux')[0].ready, false);+ }+ assert.equal(applyLinuxRendererEvidence(scanned, records, processes, 'darwin')[0].ready, false);+ assert.equal(applyLinuxRendererEvidence(scanned, records, processes, 'win32')[0].ready, false);+});diff --git a/scripts/desktop-whoami.mjs b/scripts/desktop-whoami.mjsindex 1008dee4b9..ad593b70d6 100644--- a/scripts/desktop-whoami.mjs+++ b/scripts/desktop-whoami.mjs@@ -319,6 +319,25 @@ function printText(report) {}}+/** Linux sandboxed renderers can retain their zygote argv. Require a PID from+ * the main-window readiness report AND a live descendant from the same binary. */+export function applyLinuxRendererEvidence(scanned, records, processes, platform = process.platform) {+ if (platform !== 'linux') return scanned;+ return scanned.map((instance) => {+ if (instance.ready) return instance;+ const record = records.find((record) => record.pid === instance.pid+ && typeof record.rootDir === 'string'+ && normalize(record.rootDir) === normalize(instance.rootDir));+ if (record?.state !== 'ready' || !Number.isSafeInteger(record.rendererPid) || record.rendererPid <= 0)+ return instance;+ const renderer = descendants(instance.pid, processes).find((child) => child.pid === record.rendererPid);+ if (!renderer || !/(?:^|\s)--type=zygote(?:\s|$)/.test(renderer.command)+ || !commandContainsPath(renderer.command, path.join(instance.rootDir, 'node_modules', 'electron')))+ return instance;+ return { ...instance, ready: true, state: 'ready' };+ });+}+export function collectDesktopWhoamiReport(options = {}) {const expectedRoot = path.resolve(options.rootDir ?? rootDir);const env = options.env ?? process.env;@@ -331,7 +350,8 @@ export function collectDesktopWhoamiReport(options = {}) {...preliminary.map((item) => item.userDataDir).filter(Boolean).map((item) => path.resolve(item)),]);const records = options.records ?? readInstanceRecords(userDataDirs, worktrees);- const allInstances = mergeDesktopInstanceRecords(preliminary, records, worktrees);+ const scanned = applyLinuxRendererEvidence(preliminary, records, processes, options.platform);+ const allInstances = mergeDesktopInstanceRecords(scanned, records, worktrees);const expectedCommit = options.commit === undefined ? gitHead(expectedRoot) : options.commit;const match = allInstances.some((instance) =>normalize(instance.rootDir) === normalize(expectedRoot) &&