Files
ZenEcho 489f3d4f1f feat: 新增游戏平台扫描、主题模式与重置功能
- 新增 BattleNet、WeGame、GOG 等游戏平台扫描支持
- 添加系统代理绕过列表和 Bootstrap DNS 配置
- 实现应用重置功能,支持清理数据并重启
- 增加主题模式选择(亮色/暗色/自动)
- 优化本地游戏扫描性能,支持并行扫描
- 改进代理监控,支持链式代理子进程检测
- 修复日志发送时的窗口销毁检查
- 更新图标和侧边栏布局
- 移除 prepare-singbox-core 脚本,简化构建流程
2026-02-22 03:57:55 +08:00

46 lines
1.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { spawn } from 'child_process'
/**
* 执行系统命令并返回结果
*
* 封装了 child_process.spawn,支持超时控制和 Windows 窗口隐藏。
*
* @param command - 要执行的命令(如 'ping', 'ipconfig')
* @param args - 命令参数数组
* @param timeoutMs - 超时时间(毫秒),默认 15000ms
* @returns Promise<{ code: number, output: string }>
* - code: 进程退出码,超时或错误时为 -1
* - output: 标准输出和标准错误合并后的字符串
*/
export function runCommand(command: string, args: string[], timeoutMs: number = 15000): Promise<{ code: number, output: string }> {
return new Promise((resolve) => {
const p = spawn(command, args, { windowsHide: true })
const chunks: Buffer[] = []
const onData = (d: any) => chunks.push(Buffer.isBuffer(d) ? d : Buffer.from(String(d)))
p.stdout?.on('data', onData)
p.stderr?.on('data', onData)
let timedOut = false
const timer = setTimeout(() => {
timedOut = true
p.kill()
}, timeoutMs)
p.on('close', (code) => {
clearTimeout(timer)
const output = Buffer.concat(chunks).toString('utf8').trim()
if (timedOut) {
resolve({ code: -1, output: output || '命令执行超时' })
return
}
resolve({ code: typeof code === 'number' ? code : -1, output })
})
p.on('error', (err) => {
clearTimeout(timer)
resolve({ code: -1, output: String(err?.message || err) })
})
})
}