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

@@ -59,6 +59,16 @@ export enum IPC_EVENTS {
// 打开渠道
OPEN_CHANNEL = 'open-channel',
// 脚本管理
SCRIPT_LIST = 'script:list',
SCRIPT_GET = 'script:get',
SCRIPT_SAVE = 'script:save',
SCRIPT_DELETE = 'script:delete',
SCRIPT_TOGGLE = 'script:toggle',
SCRIPT_RUN = 'script:run',
SCRIPT_RECORD_START = 'script:record-start',
SCRIPT_RECORD_STOP = 'script:record-stop',
// 更新
UPDATE_CHECK = 'update:check',
UPDATE_DOWNLOAD = 'update:download',

18
src/lib/script-api.ts Normal file
View File

@@ -0,0 +1,18 @@
import type {
AutomationScript,
ScriptSaveInput,
ScriptExecutionResult,
} from '@lib/script-types';
export const scriptApi = {
list: (): Promise<AutomationScript[]> => window.api.scriptApi.list(),
get: (id: string): Promise<AutomationScript | null> => window.api.scriptApi.get(id),
save: (input: ScriptSaveInput): Promise<AutomationScript> => window.api.scriptApi.save(input),
delete: (id: string): Promise<boolean> => window.api.scriptApi.delete(id),
toggle: (id: string, enabled: boolean): Promise<boolean> => window.api.scriptApi.toggle(id, enabled),
run: (id: string): Promise<ScriptExecutionResult> => window.api.scriptApi.run(id),
startRecording: (url?: string): Promise<{ success: boolean; code?: string; error?: string }> =>
window.api.scriptApi.startRecording(url),
stopRecording: (): Promise<{ success: boolean; code?: string; error?: string }> =>
window.api.scriptApi.stopRecording(),
};

53
src/lib/script-types.ts Normal file
View File

@@ -0,0 +1,53 @@
export interface ScriptLastRun {
time: string;
success: boolean;
error?: string;
}
export interface AutomationScript {
id: string;
name: string;
description: string;
filename: string;
enabled: boolean;
channel: string;
createdAt: string;
updatedAt: string;
code?: string;
lastRun?: ScriptLastRun;
}
export interface ScriptSaveInput {
id?: string;
name: string;
description: string;
code: string;
channel: string;
enabled: boolean;
}
export interface ScriptExecutionResult {
success: boolean;
exitCode: number | null;
stdoutTail: string;
stderrTail: string;
error?: string;
}
export type ScriptRecordingStatus = 'idle' | 'recording' | 'stopped';
export interface ScriptMetaItem {
id: string;
name: string;
description: string;
filename: string;
enabled: boolean;
channel: string;
createdAt: string;
updatedAt: string;
lastRun?: ScriptLastRun;
}
export interface ScriptsMeta {
scripts: ScriptMetaItem[];
}