feat: 新增脚本录制功能

This commit is contained in:
duanshuwen
2026-04-12 15:46:28 +08:00
parent 66bb07faf2
commit c16fc93685
38 changed files with 3336 additions and 51 deletions

View File

@@ -3,6 +3,18 @@ import { ipcMain, app } from 'electron';
import { IPC_EVENTS } from '@lib/constants';
import { launchLocalChrome } from '@electron/utils/chrome/launchLocalChrome'
import { executeScriptService } from '@electron/service/execute-script-service';
import {
listScripts,
getScript,
saveScript,
deleteScript,
toggleScript,
} from '@electron/service/script-store-service';
import { runScriptById } from '@electron/service/script-execution-service';
import {
startRecording,
stopRecording,
} from '@electron/service/script-recorder-service';
import fs from 'fs'
import path from 'path'
import log from 'electron-log';
@@ -17,6 +29,81 @@ function getScriptsDir() {
export function runTaskOperationService() {
const executeScriptServiceInstance = new executeScriptService();
// 脚本管理 IPC
ipcMain.handle(IPC_EVENTS.SCRIPT_LIST, async () => {
try {
return listScripts();
} catch (error: any) {
log.error('[SCRIPT_LIST] error:', error);
throw error;
}
});
ipcMain.handle(IPC_EVENTS.SCRIPT_GET, async (_event, id: string) => {
try {
return getScript(id);
} catch (error: any) {
log.error('[SCRIPT_GET] error:', error);
throw error;
}
});
ipcMain.handle(IPC_EVENTS.SCRIPT_SAVE, async (_event, input: any) => {
try {
return saveScript(input);
} catch (error: any) {
log.error('[SCRIPT_SAVE] error:', error);
throw error;
}
});
ipcMain.handle(IPC_EVENTS.SCRIPT_DELETE, async (_event, id: string) => {
try {
return deleteScript(id);
} catch (error: any) {
log.error('[SCRIPT_DELETE] error:', error);
throw error;
}
});
ipcMain.handle(IPC_EVENTS.SCRIPT_TOGGLE, async (_event, id: string, enabled: boolean) => {
try {
return toggleScript(id, enabled);
} catch (error: any) {
log.error('[SCRIPT_TOGGLE] error:', error);
throw error;
}
});
ipcMain.handle(IPC_EVENTS.SCRIPT_RUN, async (_event, id: string) => {
try {
const script = getScript(id);
return await runScriptById(id, script?.channel);
} catch (error: any) {
log.error('[SCRIPT_RUN] error:', error);
return { success: false, exitCode: null, stdoutTail: '', stderrTail: '', error: error?.message || 'Run failed' };
}
});
ipcMain.handle(IPC_EVENTS.SCRIPT_RECORD_START, async (_event, url?: string) => {
try {
return await startRecording(url);
} catch (error: any) {
log.error('[SCRIPT_RECORD_START] error:', error);
return { success: false, error: error?.message || 'Recording start failed' };
}
});
ipcMain.handle(IPC_EVENTS.SCRIPT_RECORD_STOP, async () => {
try {
return await stopRecording();
} catch (error: any) {
log.error('[SCRIPT_RECORD_STOP] error:', error);
return { success: false, error: error?.message || 'Recording stop failed' };
}
});
// 打开渠道
ipcMain.handle(IPC_EVENTS.OPEN_CHANNEL, async (_event, channels: any) => {
try {