mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-15 19:22:31 +08:00
fix trafficMonitor not stop
This commit is contained in:
parent
c0a1dc6056
commit
5291bbd596
|
@ -1,8 +1,4 @@
|
|||
### New Features
|
||||
|
||||
- 允许切换订阅卡片显示过期时间还是更新时间
|
||||
- 添加悬浮窗功能,可以在设置中开启
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- 修复某些 Windows 管理员权限无法正常启动的问题
|
||||
- 修复开启轻量模式后 TrafficMonitor 重复启动的问题
|
||||
- 修复 TrafficMonitor 重复开关后位置偏移的问题
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
import { ChildProcess, spawn } from 'child_process'
|
||||
import { getAppConfig } from '../config'
|
||||
import { resourcesFilesDir } from '../utils/dirs'
|
||||
import { dataDir, resourcesFilesDir } from '../utils/dirs'
|
||||
import path from 'path'
|
||||
import { existsSync } from 'fs'
|
||||
import { readFile, rm, writeFile } from 'fs/promises'
|
||||
|
||||
let child: ChildProcess
|
||||
|
||||
export async function startMonitor(detached = false): Promise<void> {
|
||||
if (process.platform !== 'win32') return
|
||||
if (existsSync(path.join(dataDir(), 'monitor.pid'))) {
|
||||
const pid = parseInt(await readFile(path.join(dataDir(), 'monitor.pid'), 'utf-8'))
|
||||
try {
|
||||
process.kill(pid, 'SIGINT')
|
||||
} catch {
|
||||
// ignore
|
||||
} finally {
|
||||
await rm(path.join(dataDir(), 'monitor.pid'))
|
||||
}
|
||||
}
|
||||
await stopMonitor()
|
||||
const { showTraffic = true } = await getAppConfig()
|
||||
if (!showTraffic) return
|
||||
|
@ -16,6 +28,9 @@ export async function startMonitor(detached = false): Promise<void> {
|
|||
stdio: detached ? 'ignore' : undefined
|
||||
})
|
||||
if (detached) {
|
||||
if (child && child.pid) {
|
||||
await writeFile(path.join(dataDir(), 'monitor.pid'), child.pid.toString())
|
||||
}
|
||||
child.unref()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user