|
|
@@ -25,9 +25,8 @@ async function logMessage(message, folderPath = null) {
|
|
|
// 注意:不输出到 console,只写入日志文件
|
|
|
try {
|
|
|
const targetFolderPath = folderPath || currentWorkflowFolderPath;
|
|
|
- if (targetFolderPath && window.electronAPI && window.electronAPI.appendLog) {
|
|
|
- // 异步写入,不等待完成
|
|
|
- window.electronAPI.appendLog(targetFolderPath, message).catch(err => {
|
|
|
+ if (targetFolderPath && electronAPI.appendLog) {
|
|
|
+ electronAPI.appendLog(targetFolderPath, message).catch(err => {
|
|
|
// 静默失败,不影响主流程
|
|
|
});
|
|
|
}
|
|
|
@@ -58,24 +57,18 @@ async function logOutVars(action, variableContext, folderPath = null) {
|
|
|
// await logMessage(logMsg, folderPath);
|
|
|
}
|
|
|
|
|
|
-// 导入聊天历史记录管理模块
|
|
|
-import { generateHistorySummary, getHistorySummary } from './func/chat/chat-history.js';
|
|
|
-// 导入 ocr-chat 执行函数
|
|
|
-import { executeOcrChat } from './func/chat/ocr-chat.js';
|
|
|
-// 导入 image-region-location 执行函数
|
|
|
-import { executeImageRegionLocation } from './func/image-region-location.js';
|
|
|
-// 导入 image-center-location 执行函数
|
|
|
-import { executeImageCenterLocation } from './func/image-center-location.js';
|
|
|
-// 导入 image-area-cropping 执行函数
|
|
|
-import { executeImageAreaCropping } from './func/image-area-cropping.js';
|
|
|
-// 导入 read-last-message 执行函数
|
|
|
-import { executeReadLastMessage } from './func/chat/read-last-message.js';
|
|
|
-// 导入 read-txt 执行函数
|
|
|
-import { executeReadTxt } from './func/read-txt.js';
|
|
|
-// 导入 save-txt 执行函数
|
|
|
-import { executeSaveTxt } from './func/save-txt.js';
|
|
|
-// 导入 smart-chat-append 执行函数
|
|
|
-import { executeSmartChatAppend } from './func/chat/smart-chat-append.js';
|
|
|
+const path = require('path')
|
|
|
+const funcDir = path.join(__dirname, 'Func')
|
|
|
+const { generateHistorySummary, getHistorySummary } = require(path.join(funcDir, 'chat', 'chat-history.js'))
|
|
|
+const { executeOcrChat } = require(path.join(funcDir, 'chat', 'ocr-chat.js'))
|
|
|
+const { executeImageRegionLocation } = require(path.join(funcDir, 'image-region-location.js'))
|
|
|
+const { executeImageCenterLocation } = require(path.join(funcDir, 'image-center-location.js'))
|
|
|
+const { executeImageAreaCropping } = require(path.join(funcDir, 'image-area-cropping.js'))
|
|
|
+const { executeReadLastMessage } = require(path.join(funcDir, 'chat', 'read-last-message.js'))
|
|
|
+const { executeReadTxt } = require(path.join(funcDir, 'read-txt.js'))
|
|
|
+const { executeSaveTxt } = require(path.join(funcDir, 'save-txt.js'))
|
|
|
+const { executeSmartChatAppend } = require(path.join(funcDir, 'chat', 'smart-chat-append.js'))
|
|
|
+const electronAPI = require('./node-api.js')
|
|
|
|
|
|
/**
|
|
|
* 解析时间字符串(格式:2026/1/13 02:09)
|
|
|
@@ -713,7 +706,7 @@ function parseValue(str) {
|
|
|
* @param {Object} workflow - 工作流配置对象
|
|
|
* @returns {Object} 解析后的工作流
|
|
|
*/
|
|
|
-export function parseWorkflow(workflow) {
|
|
|
+function parseWorkflow(workflow) {
|
|
|
if (!workflow || typeof workflow !== 'object') {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -805,7 +798,7 @@ export function parseWorkflow(workflow) {
|
|
|
* @param {Array} actions - 操作数组
|
|
|
* @returns {Array} 解析后的操作列表
|
|
|
*/
|
|
|
-export function parseActions(actions) {
|
|
|
+function parseActions(actions) {
|
|
|
if (!Array.isArray(actions)) {
|
|
|
return [];
|
|
|
}
|
|
|
@@ -1294,7 +1287,7 @@ function getActionName(action) {
|
|
|
* @param {number} height - 设备高度
|
|
|
* @returns {Object} 包含起始和结束坐标的对象 {x1, y1, x2, y2}
|
|
|
*/
|
|
|
-export function calculateSwipeCoordinates(direction, width, height) {
|
|
|
+function calculateSwipeCoordinates(direction, width, height) {
|
|
|
// 滑动距离为屏幕的 70%,起始和结束位置各留 15% 的边距
|
|
|
const margin = 0.15;
|
|
|
const swipeDistance = 0.7;
|
|
|
@@ -1346,7 +1339,7 @@ export function calculateSwipeCoordinates(direction, width, height) {
|
|
|
* @param {Object} resolution - 设备分辨率 {width, height}
|
|
|
* @returns {Promise<Object>} 执行结果 {success, error?, result?}
|
|
|
*/
|
|
|
-export async function executeAction(action, device, folderPath, resolution) {
|
|
|
+async function executeAction(action, device, folderPath, resolution) {
|
|
|
try {
|
|
|
// 检查条件
|
|
|
if (action.condition && !evaluateCondition(action.condition)) {
|
|
|
@@ -1383,18 +1376,18 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
// 如果设置了clear,先清空输入框
|
|
|
if (action.clear) {
|
|
|
for (let i = 0; i < 200; i++) {
|
|
|
- const clearResult = await window.electronAPI.sendKeyEvent(device, '67');
|
|
|
+ const clearResult = await electronAPI.sendKeyEvent(device, '67');
|
|
|
if (!clearResult.success) break;
|
|
|
await new Promise(resolve => setTimeout(resolve, 10));
|
|
|
}
|
|
|
await new Promise(resolve => setTimeout(resolve, 200));
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendText) {
|
|
|
+ if (!electronAPI || !electronAPI.sendText) {
|
|
|
return { success: false, error: '输入 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const textResult = await window.electronAPI.sendText(device, String(inputValue));
|
|
|
+ const textResult = await electronAPI.sendText(device, String(inputValue));
|
|
|
if (!textResult.success) {
|
|
|
return { success: false, error: `输入失败: ${textResult.error}` };
|
|
|
}
|
|
|
@@ -1457,11 +1450,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
return { success: false, error: 'click 操作的位置格式错误,需要 {x, y} 对象' };
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendTap) {
|
|
|
+ if (!electronAPI || !electronAPI.sendTap) {
|
|
|
return { success: false, error: '点击 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const tapResult = await window.electronAPI.sendTap(device, position.x, position.y);
|
|
|
+ const tapResult = await electronAPI.sendTap(device, position.x, position.y);
|
|
|
if (!tapResult.success) {
|
|
|
return { success: false, error: `点击失败: ${tapResult.error}` };
|
|
|
}
|
|
|
@@ -1493,11 +1486,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
? imagePath
|
|
|
: `${folderPath}/resources/${imagePath}`;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.matchImageAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.matchImageAndGetCoordinate) {
|
|
|
return { success: false, error: '图像匹配 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.matchImageAndGetCoordinate(device, fullPath);
|
|
|
+ const matchResult = await electronAPI.matchImageAndGetCoordinate(device, fullPath);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `图像匹配失败: ${matchResult.error}` };
|
|
|
}
|
|
|
@@ -1515,11 +1508,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
return { success: false, error: 'locate 操作(text)缺少文字内容' };
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.findTextAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.findTextAndGetCoordinate) {
|
|
|
return { success: false, error: '文字识别 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.findTextAndGetCoordinate(device, targetText);
|
|
|
+ const matchResult = await electronAPI.findTextAndGetCoordinate(device, targetText);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `文字识别失败: ${matchResult.error}` };
|
|
|
}
|
|
|
@@ -1590,11 +1583,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
y2 = coords.y2;
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendSwipe) {
|
|
|
+ if (!electronAPI || !electronAPI.sendSwipe) {
|
|
|
return { success: false, error: '滑动 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const swipeResult = await window.electronAPI.sendSwipe(device, x1, y1, x2, y2, 300);
|
|
|
+ const swipeResult = await electronAPI.sendSwipe(device, x1, y1, x2, y2, 300);
|
|
|
if (!swipeResult.success) {
|
|
|
return { success: false, error: `滑动失败: ${swipeResult.error}` };
|
|
|
}
|
|
|
@@ -1616,11 +1609,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
return { success: false, error: 'scroll 操作缺少方向参数' };
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendScroll) {
|
|
|
+ if (!electronAPI || !electronAPI.sendScroll) {
|
|
|
return { success: false, error: '滚动 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const scrollResult = await window.electronAPI.sendScroll(
|
|
|
+ const scrollResult = await electronAPI.sendScroll(
|
|
|
device,
|
|
|
direction,
|
|
|
resolution.width,
|
|
|
@@ -1655,11 +1648,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
keyCode = '4';
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendSystemKey) {
|
|
|
+ if (!electronAPI || !electronAPI.sendSystemKey) {
|
|
|
return { success: false, error: '系统按键 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const keyResult = await window.electronAPI.sendSystemKey(device, String(keyCode));
|
|
|
+ const keyResult = await electronAPI.sendSystemKey(device, String(keyCode));
|
|
|
if (!keyResult.success) {
|
|
|
return { success: false, error: `按键失败: ${keyResult.error}` };
|
|
|
}
|
|
|
@@ -1685,11 +1678,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
? imagePath
|
|
|
: `${folderPath}/${imagePath}`;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.matchImageAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.matchImageAndGetCoordinate) {
|
|
|
return { success: false, error: '图像匹配 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.matchImageAndGetCoordinate(device, fullPath);
|
|
|
+ const matchResult = await electronAPI.matchImageAndGetCoordinate(device, fullPath);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `图像匹配失败: ${matchResult.error}` };
|
|
|
}
|
|
|
@@ -1697,11 +1690,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
const { clickPosition } = matchResult;
|
|
|
const { x, y } = clickPosition;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendTap) {
|
|
|
+ if (!electronAPI || !electronAPI.sendTap) {
|
|
|
return { success: false, error: '点击 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const tapResult = await window.electronAPI.sendTap(device, x, y);
|
|
|
+ const tapResult = await electronAPI.sendTap(device, x, y);
|
|
|
if (!tapResult.success) {
|
|
|
return { success: false, error: `点击失败: ${tapResult.error}` };
|
|
|
}
|
|
|
@@ -1723,11 +1716,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
return { success: false, error: 'string-press 操作缺少文字内容' };
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.findTextAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.findTextAndGetCoordinate) {
|
|
|
return { success: false, error: '文字识别 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.findTextAndGetCoordinate(device, targetText);
|
|
|
+ const matchResult = await electronAPI.findTextAndGetCoordinate(device, targetText);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `文字识别失败: ${matchResult.error}` };
|
|
|
}
|
|
|
@@ -1735,11 +1728,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
const { clickPosition } = matchResult;
|
|
|
const { x, y } = clickPosition;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendTap) {
|
|
|
+ if (!electronAPI || !electronAPI.sendTap) {
|
|
|
return { success: false, error: '点击 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const tapResult = await window.electronAPI.sendTap(device, x, y);
|
|
|
+ const tapResult = await electronAPI.sendTap(device, x, y);
|
|
|
if (!tapResult.success) {
|
|
|
return { success: false, error: `点击失败: ${tapResult.error}` };
|
|
|
}
|
|
|
@@ -1762,21 +1755,21 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
? action.target
|
|
|
: `${folderPath}/${action.target}`;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.matchImageAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.matchImageAndGetCoordinate) {
|
|
|
return { success: false, error: '图像匹配 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.matchImageAndGetCoordinate(device, imagePath);
|
|
|
+ const matchResult = await electronAPI.matchImageAndGetCoordinate(device, imagePath);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `图像匹配失败: ${matchResult.error}` };
|
|
|
}
|
|
|
position = matchResult.clickPosition;
|
|
|
} else if (method === 'text') {
|
|
|
- if (!window.electronAPI || !window.electronAPI.findTextAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.findTextAndGetCoordinate) {
|
|
|
return { success: false, error: '文字识别 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.findTextAndGetCoordinate(device, action.target);
|
|
|
+ const matchResult = await electronAPI.findTextAndGetCoordinate(device, action.target);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `文字识别失败: ${matchResult.error}` };
|
|
|
}
|
|
|
@@ -1807,21 +1800,21 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
? action.target
|
|
|
: `${folderPath}/${action.target}`;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.matchImageAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.matchImageAndGetCoordinate) {
|
|
|
return { success: false, error: '图像匹配 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.matchImageAndGetCoordinate(device, imagePath);
|
|
|
+ const matchResult = await electronAPI.matchImageAndGetCoordinate(device, imagePath);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `图像匹配失败: ${matchResult.error}` };
|
|
|
}
|
|
|
position = matchResult.clickPosition;
|
|
|
} else if (method === 'text') {
|
|
|
- if (!window.electronAPI || !window.electronAPI.findTextAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.findTextAndGetCoordinate) {
|
|
|
return { success: false, error: '文字识别 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.findTextAndGetCoordinate(device, action.target);
|
|
|
+ const matchResult = await electronAPI.findTextAndGetCoordinate(device, action.target);
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `文字识别失败: ${matchResult.error}` };
|
|
|
}
|
|
|
@@ -1832,11 +1825,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
return { success: false, error: '无法获取点击位置' };
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendTap) {
|
|
|
+ if (!electronAPI || !electronAPI.sendTap) {
|
|
|
return { success: false, error: '点击 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const tapResult = await window.electronAPI.sendTap(device, position.x, position.y);
|
|
|
+ const tapResult = await electronAPI.sendTap(device, position.x, position.y);
|
|
|
if (!tapResult.success) {
|
|
|
return { success: false, error: `点击失败: ${tapResult.error}` };
|
|
|
}
|
|
|
@@ -1849,11 +1842,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
// resources 作为根目录
|
|
|
const imagePath = `${folderPath}/resources/${action.value}`;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.matchImageAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.matchImageAndGetCoordinate) {
|
|
|
return { success: false, error: '图像匹配 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.matchImageAndGetCoordinate(device, imagePath);
|
|
|
+ const matchResult = await electronAPI.matchImageAndGetCoordinate(device, imagePath);
|
|
|
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `图像匹配失败: ${matchResult.error}` };
|
|
|
@@ -1862,11 +1855,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
const { clickPosition } = matchResult;
|
|
|
const { x, y } = clickPosition;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendTap) {
|
|
|
+ if (!electronAPI || !electronAPI.sendTap) {
|
|
|
return { success: false, error: '点击 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const tapResult = await window.electronAPI.sendTap(device, x, y);
|
|
|
+ const tapResult = await electronAPI.sendTap(device, x, y);
|
|
|
|
|
|
if (!tapResult.success) {
|
|
|
return { success: false, error: `点击失败: ${tapResult.error}` };
|
|
|
@@ -1903,7 +1896,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
// 暂时直接使用 sendText
|
|
|
}
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendText) {
|
|
|
+ if (!electronAPI || !electronAPI.sendText) {
|
|
|
return { success: false, error: '输入 API 不可用' };
|
|
|
}
|
|
|
|
|
|
@@ -1912,7 +1905,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
// 发送退格键清空输入框(假设最多200个字符)
|
|
|
// 使用Android的KEYCODE_DEL,值为67
|
|
|
for (let i = 0; i < 200; i++) {
|
|
|
- const clearResult = await window.electronAPI.sendKeyEvent(device, '67');
|
|
|
+ const clearResult = await electronAPI.sendKeyEvent(device, '67');
|
|
|
if (!clearResult.success) {
|
|
|
break;
|
|
|
}
|
|
|
@@ -1922,7 +1915,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
await new Promise(resolve => setTimeout(resolve, 200));
|
|
|
}
|
|
|
|
|
|
- const textResult = await window.electronAPI.sendText(device, inputValue);
|
|
|
+ const textResult = await electronAPI.sendText(device, inputValue);
|
|
|
|
|
|
if (!textResult.success) {
|
|
|
return { success: false, error: `输入失败: ${textResult.error}` };
|
|
|
@@ -1942,7 +1935,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
|
|
|
case 'ocr': {
|
|
|
// OCR识别
|
|
|
- if (!window.electronAPI || !window.electronAPI.ocrLastMessage) {
|
|
|
+ if (!electronAPI || !electronAPI.ocrLastMessage) {
|
|
|
return { success: false, error: 'OCR API 不可用' };
|
|
|
}
|
|
|
|
|
|
@@ -1963,7 +1956,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
}
|
|
|
|
|
|
// 调用OCR API,传递工作流文件夹路径
|
|
|
- const ocrResult = await window.electronAPI.ocrLastMessage(device, method, avatarPath, area, folderPath);
|
|
|
+ const ocrResult = await electronAPI.ocrLastMessage(device, method, avatarPath, area, folderPath);
|
|
|
|
|
|
if (!ocrResult.success) {
|
|
|
return { success: false, error: `OCR识别失败: ${ocrResult.error}` };
|
|
|
@@ -3050,7 +3043,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
|
|
|
case 'swipe': {
|
|
|
// 滑动操作
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendSwipe) {
|
|
|
+ if (!electronAPI || !electronAPI.sendSwipe) {
|
|
|
return { success: false, error: '滑动 API 不可用' };
|
|
|
}
|
|
|
|
|
|
@@ -3060,7 +3053,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
resolution.height
|
|
|
);
|
|
|
|
|
|
- const swipeResult = await window.electronAPI.sendSwipe(device, x1, y1, x2, y2, 300);
|
|
|
+ const swipeResult = await electronAPI.sendSwipe(device, x1, y1, x2, y2, 300);
|
|
|
|
|
|
if (!swipeResult.success) {
|
|
|
return { success: false, error: `滑动失败: ${swipeResult.error}` };
|
|
|
@@ -3072,11 +3065,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
|
|
|
case 'string-press': {
|
|
|
// 向后兼容:文字识别并点击
|
|
|
- if (!window.electronAPI || !window.electronAPI.findTextAndGetCoordinate) {
|
|
|
+ if (!electronAPI || !electronAPI.findTextAndGetCoordinate) {
|
|
|
return { success: false, error: '文字识别 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const matchResult = await window.electronAPI.findTextAndGetCoordinate(device, action.value);
|
|
|
+ const matchResult = await electronAPI.findTextAndGetCoordinate(device, action.value);
|
|
|
|
|
|
if (!matchResult.success) {
|
|
|
return { success: false, error: `文字识别失败: ${matchResult.error}` };
|
|
|
@@ -3085,11 +3078,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
const { clickPosition } = matchResult;
|
|
|
const { x, y } = clickPosition;
|
|
|
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendTap) {
|
|
|
+ if (!electronAPI || !electronAPI.sendTap) {
|
|
|
return { success: false, error: '点击 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const tapResult = await window.electronAPI.sendTap(device, x, y);
|
|
|
+ const tapResult = await electronAPI.sendTap(device, x, y);
|
|
|
|
|
|
if (!tapResult.success) {
|
|
|
return { success: false, error: `点击失败: ${tapResult.error}` };
|
|
|
@@ -3101,11 +3094,11 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
|
|
|
case 'scroll': {
|
|
|
// 滚动操作(小幅度滚动)
|
|
|
- if (!window.electronAPI || !window.electronAPI.sendScroll) {
|
|
|
+ if (!electronAPI || !electronAPI.sendScroll) {
|
|
|
return { success: false, error: '滚动 API 不可用' };
|
|
|
}
|
|
|
|
|
|
- const scrollResult = await window.electronAPI.sendScroll(
|
|
|
+ const scrollResult = await electronAPI.sendScroll(
|
|
|
device,
|
|
|
action.value,
|
|
|
resolution.width,
|
|
|
@@ -3155,7 +3148,7 @@ export async function executeAction(action, device, folderPath, resolution) {
|
|
|
* @param {number} depth - 嵌套深度(用于递归)
|
|
|
* @returns {Promise<Object>} 执行结果 {success, error?, completedSteps}
|
|
|
*/
|
|
|
-export async function executeActionSequence(
|
|
|
+async function executeActionSequence(
|
|
|
actions,
|
|
|
device,
|
|
|
folderPath,
|
|
|
@@ -3484,3 +3477,5 @@ export async function executeActionSequence(
|
|
|
}
|
|
|
return { success: true, completedSteps };
|
|
|
}
|
|
|
+
|
|
|
+module.exports = { parseWorkflow, parseActions, calculateSwipeCoordinates, executeAction, executeActionSequence }
|