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

View File

@ -34,6 +34,7 @@ import { readFile, rm, writeFile } from 'fs/promises'
import { promisify } from 'util'
import { mainWindow } from '..'
import path from 'path'
import os from 'os'
import { createWriteStream, existsSync } from 'fs'
import { uploadRuntimeConfig } from '../resolve/gistApi'
import { startMonitor } from '../resolve/trafficMonitor'
@ -57,7 +58,12 @@ let child: ChildProcess
let retry = 10
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()
if (existsSync(path.join(dataDir(), 'core.pid'))) {
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
}
)
if (child.pid) {
os.setPriority(child.pid, os.constants.priority[mihomoCpuPriority])
}
if (detached) {
child.unref()
return new Promise((resolve) => {

View File

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

View File

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

View File

@ -22,6 +22,7 @@ const MihomoConfig: React.FC = () => {
pauseSSID = [],
delayTestUrl,
userAgent,
mihomoCpuPriority = 'PRIORITY_HIGHEST',
proxyCols = 'auto'
} = appConfig || {}
const [url, setUrl] = useState(delayTestUrl)
@ -135,6 +136,26 @@ const MihomoConfig: React.FC = () => {
<SelectItem key="4"></SelectItem>
</Select>
</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
title="为不同订阅分别指定工作目录"
actions={

View File

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