fix(engine): 解决在引擎状态不为 running 时强制关闭字幕引擎失败的问题

- 合并了 CaptionEngine 类中的 kill 和 forceKill 方法,删除了状态警告中的提前  return
- 更新了 README 文件中的macOS兼容性说明,添加了配置链接
This commit is contained in:
himeditator
2025-08-30 20:57:26 +08:00
parent f42458124e
commit 56fdc348f8
6 changed files with 13 additions and 30 deletions

View File

@@ -49,7 +49,7 @@
| 操作系统版本 | 处理器架构 | 获取系统音频输入 | 获取系统音频输出 | | 操作系统版本 | 处理器架构 | 获取系统音频输入 | 获取系统音频输出 |
| ------------------ | ---------- | ---------------- | ---------------- | | ------------------ | ---------- | ---------------- | ---------------- |
| Windows 11 24H2 | x64 | ✅ | ✅ | | Windows 11 24H2 | x64 | ✅ | ✅ |
| macOS Sequoia 15.5 | arm64 | ✅需要额外配置 | ✅ | | macOS Sequoia 15.5 | arm64 | ✅ [需要额外配置](./docs/user-manual/zh.md#macos-获取系统音频输出) | ✅ |
| Ubuntu 24.04.2 | x64 | ✅ | ✅ | | Ubuntu 24.04.2 | x64 | ✅ | ✅ |
| Kali Linux 2022.3 | x64 | ✅ | ✅ | | Kali Linux 2022.3 | x64 | ✅ | ✅ |
| Kylin Server V10 SP3 | x64 | ✅ | ✅ | | Kylin Server V10 SP3 | x64 | ✅ | ✅ |

View File

@@ -49,7 +49,7 @@ The software has been adapted for Windows, macOS, and Linux platforms. The teste
| OS Version | Architecture | System Audio Input | System Audio Output | | OS Version | Architecture | System Audio Input | System Audio Output |
| ------------------ | ------------ | ------------------ | ------------------- | | ------------------ | ------------ | ------------------ | ------------------- |
| Windows 11 24H2 | x64 | ✅ | ✅ | | Windows 11 24H2 | x64 | ✅ | ✅ |
| macOS Sequoia 15.5 | arm64 | ✅ Additional config required | ✅ | | macOS Sequoia 15.5 | arm64 | ✅ [Additional config required](./docs/user-manual/en.md#capturing-system-audio-output-on-macos) | ✅ |
| Ubuntu 24.04.2 | x64 | ✅ | ✅ | | Ubuntu 24.04.2 | x64 | ✅ | ✅ |
| Kali Linux 2022.3 | x64 | ✅ | ✅ | | Kali Linux 2022.3 | x64 | ✅ | ✅ |
| Kylin Server V10 SP3 | x64 | ✅ | ✅ | | Kylin Server V10 SP3 | x64 | ✅ | ✅ |

View File

@@ -49,7 +49,7 @@
| OS バージョン | アーキテクチャ | システムオーディオ入力 | システムオーディオ出力 | | OS バージョン | アーキテクチャ | システムオーディオ入力 | システムオーディオ出力 |
| ------------------ | ------------ | ------------------ | ------------------- | | ------------------ | ------------ | ------------------ | ------------------- |
| Windows 11 24H2 | x64 | ✅ | ✅ | | Windows 11 24H2 | x64 | ✅ | ✅ |
| macOS Sequoia 15.5 | arm64 | ✅ 追加設定が必要 | ✅ | | macOS Sequoia 15.5 | arm64 | ✅ [追加設定が必要](./docs/user-manual/ja.md#macos-でのシステムオーディオ出力の取得方法) | ✅ |
| Ubuntu 24.04.2 | x64 | ✅ | ✅ | | Ubuntu 24.04.2 | x64 | ✅ | ✅ |
| Kali Linux 2022.3 | x64 | ✅ | ✅ | | Kali Linux 2022.3 | x64 | ✅ | ✅ |
| Kylin Server V10 SP3 | x64 | ✅ | ✅ | | Kylin Server V10 SP3 | x64 | ✅ | ✅ |

View File

@@ -1,5 +1,5 @@
appId: com.himeditator.autocaption appId: com.himeditator.autocaption
productName: auto-caption productName: Auto Caption
directories: directories:
buildResources: build buildResources: build
files: files:
@@ -13,6 +13,9 @@ files:
- '!engine/*' - '!engine/*'
- '!docs/*' - '!docs/*'
- '!assets/*' - '!assets/*'
- '!.repomap/*'
- '!.virtualme/*'
extraResources: extraResources:
# For Windows # For Windows
- from: ./engine/dist/main.exe - from: ./engine/dist/main.exe

View File

@@ -160,7 +160,7 @@ class ControlWindow {
}) })
ipcMain.on('control.engine.forceKill', () => { ipcMain.on('control.engine.forceKill', () => {
captionEngine.forceKill() captionEngine.kill()
}) })
ipcMain.on('control.captionLog.clear', () => { ipcMain.on('control.captionLog.clear', () => {

View File

@@ -97,7 +97,6 @@ export class CaptionEngine {
public connect() { public connect() {
if(this.client) { Log.warn('Client already exists, ignoring...') } if(this.client) { Log.warn('Client already exists, ignoring...') }
// 清除启动超时计时器
if (this.startTimeoutID) { if (this.startTimeoutID) {
clearTimeout(this.startTimeoutID) clearTimeout(this.startTimeoutID)
this.startTimeoutID = undefined this.startTimeoutID = undefined
@@ -137,14 +136,13 @@ export class CaptionEngine {
this.status = 'starting' this.status = 'starting'
Log.info('Caption Engine Starting, PID:', this.process.pid) Log.info('Caption Engine Starting, PID:', this.process.pid)
// 设置启动超时机制
const timeoutMs = allConfig.controls.startTimeoutSeconds * 1000 const timeoutMs = allConfig.controls.startTimeoutSeconds * 1000
this.startTimeoutID = setTimeout(() => { this.startTimeoutID = setTimeout(() => {
if (this.status === 'starting') { if (this.status === 'starting') {
Log.warn(`Engine start timeout after ${allConfig.controls.startTimeoutSeconds} seconds, forcing kill...`) Log.warn(`Engine start timeout after ${allConfig.controls.startTimeoutSeconds} seconds, forcing kill...`)
this.status = 'starting-timeout' this.status = 'starting-timeout'
controlWindow.sendErrorMessage(i18n('engine.start.timeout')) controlWindow.sendErrorMessage(i18n('engine.start.timeout'))
this.forceKill() this.kill()
} }
}, timeoutMs) }, timeoutMs)
@@ -182,7 +180,6 @@ export class CaptionEngine {
} }
this.status = 'stopped' this.status = 'stopped'
clearInterval(this.timerID) clearInterval(this.timerID)
// 清理启动超时计时器
if (this.startTimeoutID) { if (this.startTimeoutID) {
clearTimeout(this.startTimeoutID) clearTimeout(this.startTimeoutID)
this.startTimeoutID = undefined this.startTimeoutID = undefined
@@ -194,7 +191,6 @@ export class CaptionEngine {
public stop() { public stop() {
if(this.status !== 'running'){ if(this.status !== 'running'){
Log.warn('Trying to stop engine which is not running, current status:', this.status) Log.warn('Trying to stop engine which is not running, current status:', this.status)
return
} }
this.sendCommand('stop') this.sendCommand('stop')
if(this.client){ if(this.client){
@@ -210,27 +206,12 @@ export class CaptionEngine {
} }
public kill(){ public kill(){
if(!this.process || !this.process.pid) return
if(this.status !== 'running'){ if(this.status !== 'running'){
Log.warn('Trying to kill engine which is not running, current status:', this.status) Log.warn('Trying to kill engine which is not running, current status:', this.status)
return
} }
this.sendCommand('stop') Log.warn('Killing engine process, PID:', this.process.pid)
if(this.client){
this.client.destroy()
this.client = undefined
}
this.status = 'stopping'
this.timerID = setTimeout(() => {
if(this.status !== 'stopping') return
Log.warn('Engine process still not stopped, trying to kill...')
this.forceKill()
}, 4000);
}
public forceKill(){
if(!this.process || !this.process.pid) return
Log.warn('Force killing engine process, PID:', this.process.pid)
// 清理启动超时计时器
if (this.startTimeoutID) { if (this.startTimeoutID) {
clearTimeout(this.startTimeoutID) clearTimeout(this.startTimeoutID)
this.startTimeoutID = undefined this.startTimeoutID = undefined
@@ -246,13 +227,12 @@ export class CaptionEngine {
} }
exec(cmd, (error) => { exec(cmd, (error) => {
if (error) { if (error) {
Log.error('Failed to force kill process:', error) Log.error('Failed to kill process:', error)
} else { } else {
Log.info('Process force killed successfully') Log.info('Process killed successfully')
} }
}) })
} }
this.status = 'stopping'
} }
} }