fix start error when using silent log-level

This commit is contained in:
pompurin404 2024-09-10 13:59:37 +08:00
parent dfdf044b48
commit c4618b4ddb
No known key found for this signature in database
3 changed files with 10 additions and 1 deletions

View File

@ -5,3 +5,7 @@
### New Features
- 支持自动开启轻量模式
### Bug Fixes
- 修复日志等级为静默时,无法正常启动的问题

View File

@ -21,6 +21,8 @@ export async function generateProfile(): Promise<void> {
const currentProfile = await overrideProfile(current, await getProfile(current))
const controledMihomoConfig = await getControledMihomoConfig()
const profile = deepMerge(currentProfile, controledMihomoConfig)
// 确保可以拿到基础日志信息
profile['log-level'] = 'info'
runtimeConfig = profile
runtimeConfigStr = yaml.stringify(profile)
await writeFile(mihomoWorkConfigPath(), runtimeConfigStr)

View File

@ -24,7 +24,8 @@ import {
stopMihomoConnections,
stopMihomoTraffic,
stopMihomoLogs,
stopMihomoMemory
stopMihomoMemory,
patchMihomoConfig
} from './mihomoApi'
import chokidar from 'chokidar'
import { readFile, rm, writeFile } from 'fs/promises'
@ -47,6 +48,7 @@ let retry = 10
export async function startCore(detached = false): Promise<Promise<void>[]> {
const { core = 'mihomo', autoSetDNS = true, encryptedPassword } = await getAppConfig()
const { 'log-level': logLevel } = await getControledMihomoConfig()
if (existsSync(path.join(dataDir(), 'core.pid'))) {
const pid = parseInt(await readFile(path.join(dataDir(), 'core.pid'), 'utf-8'))
try {
@ -136,6 +138,7 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
} catch {
// ignore
}
await patchMihomoConfig({ 'log-level': logLevel })
resolve()
}
})