Skip to content

Comments

feat: 新增游戏路径设置,未找到游戏窗口时自动打开游戏并延时重试#77

Closed
linlucath wants to merge 1 commit intoMistEO:mainfrom
linlucath:main
Closed

feat: 新增游戏路径设置,未找到游戏窗口时自动打开游戏并延时重试#77
linlucath wants to merge 1 commit intoMistEO:mainfrom
linlucath:main

Conversation

@linlucath
Copy link

@linlucath linlucath commented Feb 20, 2026

在设置中添加了游戏路径的选项, 从而可以自动打开游戏并开始任务
例如 C:\Program Files\Hypergryph Launcher\games\EndField Game\Endfield.exe

Summary by Sourcery

添加可配置的游戏可执行文件路径,并使用该路径在未找到游戏窗口时自动启动游戏并重试连接。

新功能:

  • 在常规设置中添加游戏路径设置,允许用户选择游戏可执行文件。
  • 当无法找到目标游戏窗口时,自动启动已配置的游戏,并在延迟后重试任务启动。

改进:

  • 在全局应用存储和配置文件中持久化新的游戏路径设置,并为英文和中文界面文本提供国际化(i18n)支持。
Original summary in English

Summary by Sourcery

Add a configurable game executable path and use it to auto-launch the game and retry connecting when no game window is found.

New Features:

  • Introduce a game path setting in the general settings that lets users select the game executable.
  • Automatically launch the configured game and retry task start after a delay when the target game window cannot be found.

Enhancements:

  • Persist the new game path setting in the global app store and configuration file, including i18n support for English and Chinese UI texts.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了两个问题,并给出了一些整体性的反馈:

  • 60 秒重试延迟在多个地方被硬编码(WINDOW_RETRY_DELAY_MS 和 i18n 文案);建议把它集中到一个常量或可配置项中,这样如果以后修改延迟,多个地方就不会出现不一致。
  • 在使用 maaService.runAction(path, '', basePath, false) 自动启动游戏时,建议在运行前校验一下 gamePath 是否指向了一个存在且可执行的文件,这样一旦配置错误就能更快失败,并给出更清晰的错误信息。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The 60-second retry delay is hard-coded in multiple places (WINDOW_RETRY_DELAY_MS and i18n messages); consider centralizing this as a single constant or configurable setting to avoid drift if the delay is ever changed.
- When auto-launching the game with `maaService.runAction(path, '', basePath, false)`, you might want to validate that `gamePath` points to an existing and executable file before attempting to run it, so that misconfigurations fail fast with a clearer message.

## Individual Comments

### Comment 1
<location> `src/stores/appStore.ts:1286` </location>
<code_context>
     },

+    // 游戏路径设置(窗口未找到时自动启动游戏)
+    gamePath: '',
+    setGamePath: (path) => set({ gamePath: path }),
+
</code_context>

<issue_to_address>
**issue (bug_risk):** The second `gamePath` initialization overwrites the value loaded from config, breaking persistence.

This `gamePath: ''` definition in the store’s initial state will override the earlier `config.settings.gamePath ?? ''` initialization, so any persisted path from config is discarded on startup. Please remove this initializer (and rely on `setGamePath`) or otherwise ensure the config-derived value is not overwritten.
</issue_to_address>

### Comment 2
<location> `src/components/Toolbar.tsx:486-489` </location>
<code_context>
+            }
+
+            log.info(`实例 ${targetInstance.name}: 未找到窗口,尝试启动游戏: ${path}`);
+            addLog(targetId, {
+              type: 'info',
+              message: t('action.autoLaunchGameStarting', { path }),
+            });
+
+            try {
+              await maaService.runAction(path, '', basePath, false);
+            } catch (launchErr) {
+              log.error(`实例 ${targetInstance.name}: 启动游戏失败:`, launchErr);
+              addLog(targetId, {
+                type: 'error',
+                message: t('action.autoLaunchGameFailed', { error: String(launchErr) }),
+              });
+              return false;
+            }
+
+            addLog(targetId, {
+              type: 'info',
+              message: t('action.autoLaunchGameWaiting', { seconds: 60 }),
+            });
+            await new Promise((resolve) => setTimeout(resolve, WINDOW_RETRY_DELAY_MS));
</code_context>

<issue_to_address>
**suggestion:** The hardcoded `60` seconds in the log can drift from `WINDOW_RETRY_DELAY_MS`.

Since `WINDOW_RETRY_DELAY_MS` is `60_000`, this log should derive the seconds from that constant (e.g. `WINDOW_RETRY_DELAY_MS / 1000`) so the message stays accurate if the delay changes.

```suggestion
            addLog(targetId, {
              type: 'info',
              message: t('action.autoLaunchGameWaiting', { seconds: WINDOW_RETRY_DELAY_MS / 1000 }),
            });
```
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的代码审查有帮助,欢迎分享 ✨
帮我提升审查质量!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've found 2 issues, and left some high level feedback:

  • The 60-second retry delay is hard-coded in multiple places (WINDOW_RETRY_DELAY_MS and i18n messages); consider centralizing this as a single constant or configurable setting to avoid drift if the delay is ever changed.
  • When auto-launching the game with maaService.runAction(path, '', basePath, false), you might want to validate that gamePath points to an existing and executable file before attempting to run it, so that misconfigurations fail fast with a clearer message.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The 60-second retry delay is hard-coded in multiple places (WINDOW_RETRY_DELAY_MS and i18n messages); consider centralizing this as a single constant or configurable setting to avoid drift if the delay is ever changed.
- When auto-launching the game with `maaService.runAction(path, '', basePath, false)`, you might want to validate that `gamePath` points to an existing and executable file before attempting to run it, so that misconfigurations fail fast with a clearer message.

## Individual Comments

### Comment 1
<location> `src/stores/appStore.ts:1286` </location>
<code_context>
     },

+    // 游戏路径设置(窗口未找到时自动启动游戏)
+    gamePath: '',
+    setGamePath: (path) => set({ gamePath: path }),
+
</code_context>

<issue_to_address>
**issue (bug_risk):** The second `gamePath` initialization overwrites the value loaded from config, breaking persistence.

This `gamePath: ''` definition in the store’s initial state will override the earlier `config.settings.gamePath ?? ''` initialization, so any persisted path from config is discarded on startup. Please remove this initializer (and rely on `setGamePath`) or otherwise ensure the config-derived value is not overwritten.
</issue_to_address>

### Comment 2
<location> `src/components/Toolbar.tsx:486-489` </location>
<code_context>
+            }
+
+            log.info(`实例 ${targetInstance.name}: 未找到窗口,尝试启动游戏: ${path}`);
+            addLog(targetId, {
+              type: 'info',
+              message: t('action.autoLaunchGameStarting', { path }),
+            });
+
+            try {
+              await maaService.runAction(path, '', basePath, false);
+            } catch (launchErr) {
+              log.error(`实例 ${targetInstance.name}: 启动游戏失败:`, launchErr);
+              addLog(targetId, {
+                type: 'error',
+                message: t('action.autoLaunchGameFailed', { error: String(launchErr) }),
+              });
+              return false;
+            }
+
+            addLog(targetId, {
+              type: 'info',
+              message: t('action.autoLaunchGameWaiting', { seconds: 60 }),
+            });
+            await new Promise((resolve) => setTimeout(resolve, WINDOW_RETRY_DELAY_MS));
</code_context>

<issue_to_address>
**suggestion:** The hardcoded `60` seconds in the log can drift from `WINDOW_RETRY_DELAY_MS`.

Since `WINDOW_RETRY_DELAY_MS` is `60_000`, this log should derive the seconds from that constant (e.g. `WINDOW_RETRY_DELAY_MS / 1000`) so the message stays accurate if the delay changes.

```suggestion
            addLog(targetId, {
              type: 'info',
              message: t('action.autoLaunchGameWaiting', { seconds: WINDOW_RETRY_DELAY_MS / 1000 }),
            });
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

},

// 游戏路径设置(窗口未找到时自动启动游戏)
gamePath: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): 第二次对 gamePath 的初始化会覆盖从配置中加载的值,从而破坏持久化。

这个在 store 初始状态中的 gamePath: '' 定义会覆盖之前的 config.settings.gamePath ?? '' 初始化,因此启动时任何从配置中持久化的路径都会被丢弃。请移除这一初始化(并依赖 setGamePath),或者确保不会覆盖从配置中得到的值。

Original comment in English

issue (bug_risk): The second gamePath initialization overwrites the value loaded from config, breaking persistence.

This gamePath: '' definition in the store’s initial state will override the earlier config.settings.gamePath ?? '' initialization, so any persisted path from config is discarded on startup. Please remove this initializer (and rely on setGamePath) or otherwise ensure the config-derived value is not overwritten.

Comment on lines +486 to +489
addLog(targetId, {
type: 'info',
message: t('action.autoLaunchGameWaiting', { seconds: 60 }),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: 日志中硬编码的 60 秒可能会与 WINDOW_RETRY_DELAY_MS 不一致。

由于 WINDOW_RETRY_DELAY_MS60_000,这条日志应当从该常量推导秒数(例如 WINDOW_RETRY_DELAY_MS / 1000),这样当延迟修改时,日志信息依然是准确的。

Suggested change
addLog(targetId, {
type: 'info',
message: t('action.autoLaunchGameWaiting', { seconds: 60 }),
});
addLog(targetId, {
type: 'info',
message: t('action.autoLaunchGameWaiting', { seconds: WINDOW_RETRY_DELAY_MS / 1000 }),
});
Original comment in English

suggestion: The hardcoded 60 seconds in the log can drift from WINDOW_RETRY_DELAY_MS.

Since WINDOW_RETRY_DELAY_MS is 60_000, this log should derive the seconds from that constant (e.g. WINDOW_RETRY_DELAY_MS / 1000) so the message stays accurate if the delay changes.

Suggested change
addLog(targetId, {
type: 'info',
message: t('action.autoLaunchGameWaiting', { seconds: 60 }),
});
addLog(targetId, {
type: 'info',
message: t('action.autoLaunchGameWaiting', { seconds: WINDOW_RETRY_DELAY_MS / 1000 }),
});

@linlucath linlucath marked this pull request as draft February 20, 2026 08:17
@MistEO
Copy link
Owner

MistEO commented Feb 20, 2026

不是有 “前置程序” 了吗

image

@linlucath
Copy link
Author

诶喔才发现 T^T, 那没事了, 写写其他的

@linlucath linlucath closed this Feb 20, 2026
@MistEO
Copy link
Owner

MistEO commented Feb 20, 2026

要不给前置程序加一个“检测进程已存在就不启动”这种的 switch ?免得游戏已经在运行了又打开一次

@linlucath
Copy link
Author

要不给前置程序加一个“检测进程已存在就不启动”这种的 switch ?免得游戏已经在运行了又打开一次

试了试好像终末地第二次打开只会多一个报错的窗口, 不会影响任务进行. 不知道其他游戏是怎样

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants