support set core priority

This commit is contained in:
pompurin404 2024-11-14 21:06:14 +08:00
parent 9f6aac708b
commit 5bafb7ccc1
No known key found for this signature in database
6 changed files with 46 additions and 9 deletions

View File

@ -7,12 +7,11 @@
### Features ### Features
- 支持设置 `direct-nameserver` - 内置 Sub-Store 不使用缓存
- 支持设置 `route-exclude-address` - 允许控制是否为 Sub-Store 使用代理
- 允许设置内核进程优先级
- 提高进程优先级
### Bug Fixes ### Bug Fixes
- 不使用pac模式时不再启动pac服务器 - 修复寻找可用端口失败的问题
- 修复对话框上层可调整侧栏大小的问题
- 修复Windows系统路径错误
- 修复内核panic没有日志的问题

View File

@ -34,6 +34,7 @@ import { readFile, rm, writeFile } from 'fs/promises'
import { promisify } from 'util' import { promisify } from 'util'
import { mainWindow } from '..' import { mainWindow } from '..'
import path from 'path' import path from 'path'
import os from 'os'
import { createWriteStream, existsSync } from 'fs' import { createWriteStream, existsSync } from 'fs'
import { uploadRuntimeConfig } from '../resolve/gistApi' import { uploadRuntimeConfig } from '../resolve/gistApi'
import { startMonitor } from '../resolve/trafficMonitor' import { startMonitor } from '../resolve/trafficMonitor'
@ -57,7 +58,12 @@ let child: ChildProcess
let retry = 10 let retry = 10
export async function startCore(detached = false): Promise<Promise<void>[]> { export async function startCore(detached = false): Promise<Promise<void>[]> {
const { core = 'mihomo', autoSetDNS = true, diffWorkDir = false } = await getAppConfig() const {
core = 'mihomo',
autoSetDNS = true,
diffWorkDir = false,
mihomoCpuPriority = 'PRIORITY_HIGHEST'
} = await getAppConfig()
const { 'log-level': logLevel } = await getControledMihomoConfig() const { 'log-level': logLevel } = await getControledMihomoConfig()
if (existsSync(path.join(dataDir(), 'core.pid'))) { if (existsSync(path.join(dataDir(), 'core.pid'))) {
const pid = parseInt(await readFile(path.join(dataDir(), 'core.pid'), 'utf-8')) const pid = parseInt(await readFile(path.join(dataDir(), 'core.pid'), 'utf-8'))
@ -94,6 +100,9 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
stdio: detached ? 'ignore' : undefined stdio: detached ? 'ignore' : undefined
} }
) )
if (child.pid) {
os.setPriority(child.pid, os.constants.priority[mihomoCpuPriority])
}
if (detached) { if (detached) {
child.unref() child.unref()
return new Promise((resolve) => { return new Promise((resolve) => {

View File

@ -38,7 +38,7 @@ const taskXml = `<?xml version="1.0" encoding="UTF-16"?>
<RunOnlyIfIdle>false</RunOnlyIfIdle> <RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun> <WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit> <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>0</Priority> <Priority>3</Priority>
</Settings> </Settings>
<Actions Context="Author"> <Actions Context="Author">
<Exec> <Exec>

View File

@ -90,7 +90,7 @@ const elevateTaskXml = `<?xml version="1.0" encoding="UTF-16"?>
<RunOnlyIfIdle>false</RunOnlyIfIdle> <RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun> <WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit> <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>0</Priority> <Priority>3</Priority>
</Settings> </Settings>
<Actions Context="Author"> <Actions Context="Author">
<Exec> <Exec>

View File

@ -22,6 +22,7 @@ const MihomoConfig: React.FC = () => {
pauseSSID = [], pauseSSID = [],
delayTestUrl, delayTestUrl,
userAgent, userAgent,
mihomoCpuPriority = 'PRIORITY_HIGHEST',
proxyCols = 'auto' proxyCols = 'auto'
} = appConfig || {} } = appConfig || {}
const [url, setUrl] = useState(delayTestUrl) const [url, setUrl] = useState(delayTestUrl)
@ -135,6 +136,26 @@ const MihomoConfig: React.FC = () => {
<SelectItem key="4"></SelectItem> <SelectItem key="4"></SelectItem>
</Select> </Select>
</SettingItem> </SettingItem>
<SettingItem title="内核进程优先级" divider>
<Select
classNames={{ trigger: 'data-[hover=true]:bg-default-200' }}
className="w-[150px]"
size="sm"
selectedKeys={new Set([mihomoCpuPriority])}
onSelectionChange={async (v) => {
await patchAppConfig({
mihomoCpuPriority: v.currentKey as Priority
})
}}
>
<SelectItem key="PRIORITY_HIGHEST"></SelectItem>
<SelectItem key="PRIORITY_HIGH"></SelectItem>
<SelectItem key="PRIORITY_ABOVE_NORMAL"></SelectItem>
<SelectItem key="PRIORITY_NORMAL"></SelectItem>
<SelectItem key="PRIORITY_BELOW_NORMAL"></SelectItem>
<SelectItem key="PRIORITY_LOW"></SelectItem>
</Select>
</SettingItem>
<SettingItem <SettingItem
title="为不同订阅分别指定工作目录" title="为不同订阅分别指定工作目录"
actions={ actions={

View File

@ -4,6 +4,13 @@ type SysProxyMode = 'auto' | 'manual'
type CardStatus = 'col-span-2' | 'col-span-1' | 'hidden' type CardStatus = 'col-span-2' | 'col-span-1' | 'hidden'
type AppTheme = 'system' | 'light' | 'dark' type AppTheme = 'system' | 'light' | 'dark'
type MihomoGroupType = 'Selector' | 'URLTest' | 'LoadBalance' | 'Relay' type MihomoGroupType = 'Selector' | 'URLTest' | 'LoadBalance' | 'Relay'
type Priority =
| 'PRIORITY_LOW'
| 'PRIORITY_BELOW_NORMAL'
| 'PRIORITY_NORMAL'
| 'PRIORITY_ABOVE_NORMAL'
| 'PRIORITY_HIGH'
| 'PRIORITY_HIGHEST'
type MihomoProxyType = type MihomoProxyType =
| 'Direct' | 'Direct'
| 'Reject' | 'Reject'
@ -240,6 +247,7 @@ interface IAppConfig {
autoQuitWithoutCoreDelay?: number autoQuitWithoutCoreDelay?: number
useCustomSubStore?: boolean useCustomSubStore?: boolean
useProxyInSubStore?: boolean useProxyInSubStore?: boolean
mihomoCpuPriority?: Priority
customSubStoreUrl?: string customSubStoreUrl?: string
diffWorkDir?: boolean diffWorkDir?: boolean
autoSetDNS?: boolean autoSetDNS?: boolean