Add native WGC screen capture for Windows

Uses Windows.Graphics.Capture to record the screen without the OS cursor
or the yellow capture border. Falls back to Electron capture on older Windows
or when the helper exe isn't available.
This commit is contained in:
tokenflow1m
2026-03-14 23:02:29 +09:00
parent 9332255beb
commit 7b26ec3a9e
15 changed files with 1369 additions and 11 deletions
+90
View File
@@ -0,0 +1,90 @@
import { execSync } from 'node:child_process';
import { mkdirSync, existsSync } from 'node:fs';
import path from 'node:path';
const projectRoot = process.cwd();
const sourceDir = path.join(projectRoot, 'electron', 'native', 'wgc-capture');
const buildDir = path.join(sourceDir, 'build');
if (process.platform !== 'win32') {
console.log('[build-wgc-capture] Skipping: host platform is not Windows.');
process.exit(0);
}
if (!existsSync(path.join(sourceDir, 'CMakeLists.txt'))) {
console.error('[build-wgc-capture] CMakeLists.txt not found at', sourceDir);
process.exit(1);
}
function findCmake() {
// Check PATH first
try {
execSync('cmake --version', { stdio: 'pipe' });
return 'cmake';
} catch {
// not on PATH
}
// VS 2022 bundled CMake
const vsEditions = ['Community', 'Professional', 'Enterprise', 'BuildTools'];
for (const edition of vsEditions) {
const cmakePath = path.join(
'C:', 'Program Files', 'Microsoft Visual Studio', '2022', edition,
'Common7', 'IDE', 'CommonExtensions', 'Microsoft', 'CMake', 'CMake', 'bin', 'cmake.exe'
);
if (existsSync(cmakePath)) {
return `"${cmakePath}"`;
}
}
return null;
}
const cmake = findCmake();
if (!cmake) {
console.error('[build-wgc-capture] CMake not found. Install Visual Studio with C++ CMake tools or standalone CMake.');
process.exit(1);
}
mkdirSync(buildDir, { recursive: true });
console.log('[build-wgc-capture] Configuring CMake...');
try {
execSync(`${cmake} .. -G "Visual Studio 17 2022" -A x64`, {
cwd: buildDir,
stdio: 'inherit',
timeout: 120000,
});
} catch {
console.log('[build-wgc-capture] VS 2022 generator not found, trying VS 2019...');
try {
execSync(`${cmake} .. -G "Visual Studio 16 2019" -A x64`, {
cwd: buildDir,
stdio: 'inherit',
timeout: 120000,
});
} catch (innerError) {
console.error('[build-wgc-capture] CMake configure failed:', innerError.message);
process.exit(1);
}
}
console.log('[build-wgc-capture] Building...');
try {
execSync(`${cmake} --build . --config Release`, {
cwd: buildDir,
stdio: 'inherit',
timeout: 300000,
});
} catch (error) {
console.error('[build-wgc-capture] Build failed:', error.message);
process.exit(1);
}
const exePath = path.join(buildDir, 'Release', 'wgc-capture.exe');
if (existsSync(exePath)) {
console.log(`[build-wgc-capture] Built successfully: ${exePath}`);
} else {
console.error('[build-wgc-capture] Expected exe not found at', exePath);
process.exit(1);
}