feat: CDP remote debugging + screenshot IPC handler

This commit is contained in:
Chen Gu
2026-05-09 09:34:18 +08:00
parent a00abed20b
commit dc3db7549c
2 changed files with 23 additions and 0 deletions

View File

@@ -37,6 +37,10 @@ const electron_1 = require("electron");
const path = __importStar(require("path"));
const child_process_1 = require("child_process");
const fs = __importStar(require("fs"));
// 远程调试端口 — Val 通过 CDP 远程控制窗口
const REMOTE_DEBUG_PORT = 9222;
electron_1.app.commandLine.appendSwitch('remote-debugging-port', String(REMOTE_DEBUG_PORT));
electron_1.app.commandLine.appendSwitch('remote-debugging-address', '0.0.0.0');
let mainWindow = null;
let overlayProcess = null;
let monitorProcess = null;
@@ -226,6 +230,13 @@ electron_1.ipcMain.handle('open-external', async (_event, url) => {
});
electron_1.ipcMain.handle('get-resources-path', () => process.resourcesPath);
electron_1.ipcMain.handle('fs:exists', (_event, p) => fs.existsSync(p));
electron_1.ipcMain.handle('app:screenshot', async () => {
if (mainWindow && !mainWindow.isDestroyed()) {
const img = await mainWindow.webContents.capturePage();
return { success: true, data: img.toPNG().toString('base64') };
}
return { success: false, error: 'No window' };
});
// === 应用生命周期 ===
electron_1.app.whenReady().then(createWindow);
electron_1.app.on('window-all-closed', () => {

View File

@@ -3,6 +3,11 @@ import * as path from 'path';
import { spawn, execSync, ChildProcess } from 'child_process';
import * as fs from 'fs';
// 远程调试端口 — Val 通过 CDP 远程控制窗口
const REMOTE_DEBUG_PORT = 9222;
app.commandLine.appendSwitch('remote-debugging-port', String(REMOTE_DEBUG_PORT));
app.commandLine.appendSwitch('remote-debugging-address', '0.0.0.0');
let mainWindow: BrowserWindow | null = null;
let overlayProcess: ChildProcess | null = null;
let monitorProcess: ChildProcess | null = null;
@@ -204,6 +209,13 @@ ipcMain.handle('open-external', async (_event, url: string) => {
});
ipcMain.handle('get-resources-path', () => process.resourcesPath);
ipcMain.handle('fs:exists', (_event, p: string) => fs.existsSync(p));
ipcMain.handle('app:screenshot', async () => {
if (mainWindow && !mainWindow.isDestroyed()) {
const img = await mainWindow.webContents.capturePage();
return { success: true, data: img.toPNG().toString('base64') };
}
return { success: false, error: 'No window' };
});
// === 应用生命周期 ===
app.whenReady().then(createWindow);