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