diff --git a/repo/js/AccountSwitchStateMachine/README.md b/repo/js/AccountSwitchStateMachine/README.md index c12b605f9a..d467852d29 100644 --- a/repo/js/AccountSwitchStateMachine/README.md +++ b/repo/js/AccountSwitchStateMachine/README.md @@ -82,7 +82,12 @@ - **勾选**:在切换前后检查当前账号UID,辅助判断切换是否成功 - **不勾选**:不进行UID校验 -### 6. 截图模式 +### 6. UID验证失败时尝试停止配置组 +- **勾选**:当UID验证失败时自动终止整个配置组(需配合停止快捷键使用) +- **不勾选**:仅记录错误日志,不干预后续任务 +- **停止快捷键**:填写 `VK_` 格式的虚拟键码(如 `VK_F8`),需与BetterGI全局设置一致 + +### 7. 截图模式 - **勾选**:进入截图模式,自动截图保存对应UID的账号图片 - **不勾选**:正常执行账号切换流程 @@ -137,6 +142,7 @@ A: UID用于: - **通知提醒**:切换成功或失败时发送系统通知 - **循环防护**:防止状态循环卡死 - **UID校验**:支持切换前后检查当前账号UID,提高切换准确性 +- **智能终止** UID验证失败时可自动终止整个配置组 - **截图模式**:自动截图保存账号图片,方便后续切换 ### 目录结构 @@ -216,6 +222,10 @@ AccountSwitchStateMachine/ ### 更新日志 +#### v1.1 +- **新增**:UID验证失败时自动终止配置组功能,支持配置对应键值 +- **优化**:修改了账号密码界面的识别条件,修复可能会出现的误识别问题 + #### v1.0 - 初始版本 - 实现状态机管理 diff --git a/repo/js/AccountSwitchStateMachine/assets/RecognitionObjects/ForgotPassword.png b/repo/js/AccountSwitchStateMachine/assets/RecognitionObjects/ForgotPassword.png new file mode 100644 index 0000000000..5d19b697a6 Binary files /dev/null and b/repo/js/AccountSwitchStateMachine/assets/RecognitionObjects/ForgotPassword.png differ diff --git a/repo/js/AccountSwitchStateMachine/assets/RecognitionObjects/LoginByPhone.png b/repo/js/AccountSwitchStateMachine/assets/RecognitionObjects/LoginByPhone.png new file mode 100644 index 0000000000..cd3382bf3d Binary files /dev/null and b/repo/js/AccountSwitchStateMachine/assets/RecognitionObjects/LoginByPhone.png differ diff --git a/repo/js/AccountSwitchStateMachine/assets/states.json b/repo/js/AccountSwitchStateMachine/assets/states.json index 158c1e18e6..ae50b46f1b 100644 --- a/repo/js/AccountSwitchStateMachine/assets/states.json +++ b/repo/js/AccountSwitchStateMachine/assets/states.json @@ -299,10 +299,30 @@ "id": "enterAccountAndPassword", "template": "assets/RecognitionObjects/EnterAccountAndPassword.png", "region": { - "x": 0, - "y": 0, - "width": 1920, - "height": 1080 + "x": 547, + "y": 168, + "width": 825, + "height": 744 + } + }, + { + "id": "phoneLogin", + "template": "assets/RecognitionObjects/LoginByPhone.png", + "region": { + "x": 547, + "y": 168, + "width": 825, + "height": 744 + } + }, + { + "id": "forgotPassword", + "template": "assets/RecognitionObjects/ForgotPassword.png", + "region": { + "x": 547, + "y": 168, + "width": 825, + "height": 744 } }, { @@ -316,7 +336,7 @@ } } ], - "logic": "enterAccountAndPassword && !confirm" + "logic": "((enterAccountAndPassword && phoneLogin) || (enterAccountAndPassword && forgotPassword) || (phoneLogin && forgotPassword)) && !confirm" } }, { @@ -404,9 +424,29 @@ "width": 439, "height": 116 } + }, + { + "id": "phoneLogin", + "template": "assets/RecognitionObjects/LoginByPhone.png", + "region": { + "x": 547, + "y": 168, + "width": 825, + "height": 744 + } + }, + { + "id": "forgotPassword", + "template": "assets/RecognitionObjects/ForgotPassword.png", + "region": { + "x": 547, + "y": 168, + "width": 825, + "height": 744 + } } ], - "logic": "login && !enterGame && !selectAccount && !enterAccountAndPassword && !confirm" + "logic": "login && !enterGame && !selectAccount && !enterAccountAndPassword && !confirm && !phoneLogin && !forgotPassword" } } -] +] \ No newline at end of file diff --git a/repo/js/AccountSwitchStateMachine/main.js b/repo/js/AccountSwitchStateMachine/main.js index 8af4ba5a55..67d8638173 100644 --- a/repo/js/AccountSwitchStateMachine/main.js +++ b/repo/js/AccountSwitchStateMachine/main.js @@ -4,6 +4,42 @@ let stateMachineConfig = null; // 全局游戏画面区域 let gameRegion = null; +/** + * 停止整个配置组 + * @param {string} reason - 停止原因 + */ +async function emergencyStopConfigGroup(reason) { + notification.error(`⛔ ${reason}\n\n已尝试终止后续任务`); + + await sleep(1000); + + try { + let hotkey = settings.stopHotkey || 'VK_F8'; + + if (typeof hotkey === 'string' && hotkey.trim()) { + hotkey = hotkey.trim().toUpperCase(); + + if (!hotkey.startsWith('VK_')) { + log.error('停止快捷键格式不正确,跳过按键'); + throw new Error(`[CONFIG_GROUP_STOPPED] ${reason}`); + } + } else { + log.error('停止快捷键未配置或格式错误,跳过按键'); + throw new Error(`[CONFIG_GROUP_STOPPED] ${reason}`); + } + + log.info(`模拟按下停止键 (${hotkey})...`); + keyPress(hotkey); + await sleep(500); + } catch (e) { + if (!e.message.includes('[CONFIG_GROUP_STOPPED]')) { + log.error(`按键模拟失败: ${e.message}`); + } + } + + throw new Error(`[CONFIG_GROUP_STOPPED] ${reason}`); +} + // 主逻辑 (async function () { // 只有当未开启截图模式时,才检查 verifyUid 和 targetUid @@ -141,10 +177,10 @@ let gameRegion = null; const uidFound = await findAndClick(accountRo, true, 5000); if (uidFound) { - log.info(`成功点击账号图片:${settings.targetUid}.png`); + log.info(`成功点击账号图片:${settings.targetUid}.png`); - // 定位到主界面 - log.info('开始:尝试切换到 mainUI 状态'); + // 定位到主界面 + log.info('开始:尝试切换到 mainUI 状态'); const mainUIResult = await goToState('mainUI'); if (mainUIResult) { log.info('成功到达 mainUI 状态,账号切换完成'); @@ -335,6 +371,13 @@ let gameRegion = null; log.warn(`切换后的账号UID ${currentUid} 与目标UID ${settings.targetUid} 不匹配,需要重新尝试`); currentSwitchSuccess = false; currentNotificationMessage = `切换失败,当前账号UID ${currentUid} 与目标UID ${settings.targetUid} 不匹配`; + + // UID验证失败时自动停止配置组(如果开启) + if (settings.uidMismatchAutoStop) { + await emergencyStopConfigGroup( + `UID验证失败!为防止在错误账号下继续执行,已尝试终止配置组` + ); + } } } diff --git a/repo/js/AccountSwitchStateMachine/manifest.json b/repo/js/AccountSwitchStateMachine/manifest.json index 4db86314d8..077c831645 100644 --- a/repo/js/AccountSwitchStateMachine/manifest.json +++ b/repo/js/AccountSwitchStateMachine/manifest.json @@ -1,11 +1,15 @@ { "manifest_version": 1, "name": "带状态机的账号切换", - "version": "1.0", + "version": "1.1", "description": "", "authors": [ { "name": "mno" + }, + { + "name": "lingyu", + "links": "https://github.com/aaahai00" } ], "settings_ui": "settings.json", diff --git a/repo/js/AccountSwitchStateMachine/settings.json b/repo/js/AccountSwitchStateMachine/settings.json index 6b88f356dc..61f18c2394 100644 --- a/repo/js/AccountSwitchStateMachine/settings.json +++ b/repo/js/AccountSwitchStateMachine/settings.json @@ -28,5 +28,16 @@ "name": "screenshotMode", "type": "checkbox", "label": "勾选后进入截图模式,自动截图保存对应UID的账号图片" + }, + { + "name": "uidMismatchAutoStop", + "type": "checkbox", + "label": "当UID验证失败时尝试终止配置组(原理是模拟指定键盘按键,需提前去BetterGI设置)" + }, + { + "name": "stopHotkey", + "type": "input-text", + "label": "终止配置组用的停止快捷键(需提前去BetterGI设置,与bgi停止快捷键需要一致)", + "default": "VK_F8" } -] +] \ No newline at end of file