feat: close ovms process when app quit (#12101)

* feat:close ovms process while app quit

* add await for execAsync

* update 'will-quit' event
This commit is contained in:
Kejiang Ma 2025-12-24 15:26:19 +08:00 committed by GitHub
parent d9171e0596
commit f7312697e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 29 deletions

View File

@ -37,6 +37,7 @@ import { versionService } from './services/VersionService'
import { windowService } from './services/WindowService' import { windowService } from './services/WindowService'
import { initWebviewHotkeys } from './services/WebviewService' import { initWebviewHotkeys } from './services/WebviewService'
import { runAsyncFunction } from './utils' import { runAsyncFunction } from './utils'
import { ovmsManager } from './services/OvmsManager'
const logger = loggerService.withContext('MainEntry') const logger = loggerService.withContext('MainEntry')
@ -247,12 +248,15 @@ if (!app.requestSingleInstanceLock()) {
app.on('will-quit', async () => { app.on('will-quit', async () => {
// 简单的资源清理,不阻塞退出流程 // 简单的资源清理,不阻塞退出流程
await ovmsManager.stopOvms()
try { try {
await mcpService.cleanup() await mcpService.cleanup()
await apiServerService.stop() await apiServerService.stop()
} catch (error) { } catch (error) {
logger.warn('Error cleaning up MCP service:', error as Error) logger.warn('Error cleaning up MCP service:', error as Error)
} }
// finish the logger // finish the logger
logger.finish() logger.finish()
}) })

View File

@ -59,7 +59,7 @@ import NotificationService from './services/NotificationService'
import * as NutstoreService from './services/NutstoreService' import * as NutstoreService from './services/NutstoreService'
import ObsidianVaultService from './services/ObsidianVaultService' import ObsidianVaultService from './services/ObsidianVaultService'
import { ocrService } from './services/ocr/OcrService' import { ocrService } from './services/ocr/OcrService'
import OvmsManager from './services/OvmsManager' import { ovmsManager } from './services/OvmsManager'
import powerMonitorService from './services/PowerMonitorService' import powerMonitorService from './services/PowerMonitorService'
import { proxyManager } from './services/ProxyManager' import { proxyManager } from './services/ProxyManager'
import { pythonService } from './services/PythonService' import { pythonService } from './services/PythonService'
@ -107,7 +107,6 @@ const obsidianVaultService = new ObsidianVaultService()
const vertexAIService = VertexAIService.getInstance() const vertexAIService = VertexAIService.getInstance()
const memoryService = MemoryService.getInstance() const memoryService = MemoryService.getInstance()
const dxtService = new DxtService() const dxtService = new DxtService()
const ovmsManager = new OvmsManager()
const pluginService = PluginService.getInstance() const pluginService = PluginService.getInstance()
function normalizeError(error: unknown): Error { function normalizeError(error: unknown): Error {

View File

@ -102,32 +102,10 @@ class OvmsManager {
*/ */
public async stopOvms(): Promise<{ success: boolean; message?: string }> { public async stopOvms(): Promise<{ success: boolean; message?: string }> {
try { try {
// Check if OVMS process is running // close the OVMS process
const psCommand = `Get-Process -Name "ovms" -ErrorAction SilentlyContinue | Select-Object Id, Path | ConvertTo-Json` await execAsync(
const { stdout } = await execAsync(`powershell -Command "${psCommand}"`) `powershell -Command "Get-WmiObject Win32_Process | Where-Object { $_.CommandLine -like 'ovms.exe*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }"`
)
if (!stdout.trim()) {
logger.info('OVMS process is not running')
return { success: true, message: 'OVMS process is not running' }
}
const processes = JSON.parse(stdout)
const processList = Array.isArray(processes) ? processes : [processes]
if (processList.length === 0) {
logger.info('OVMS process is not running')
return { success: true, message: 'OVMS process is not running' }
}
// Terminate all OVMS processes using terminalProcess
for (const process of processList) {
const result = await this.terminalProcess(process.Id)
if (!result.success) {
logger.error(`Failed to terminate OVMS process with PID: ${process.Id}, ${result.message}`)
return { success: false, message: `Failed to terminate OVMS process: ${result.message}` }
}
logger.info(`Terminated OVMS process with PID: ${process.Id}`)
}
// Reset the ovms instance // Reset the ovms instance
this.ovms = null this.ovms = null
@ -584,4 +562,5 @@ class OvmsManager {
} }
} }
export default OvmsManager // Export singleton instance
export const ovmsManager = new OvmsManager()