Skip to content

Commit

Permalink
support set core priority
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Nov 14, 2024
1 parent 9f6aac7 commit 5bafb7c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
11 changes: 5 additions & 6 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

### Features

- 支持设置 `direct-nameserver`
- 支持设置 `route-exclude-address`
- 内置 Sub-Store 不使用缓存
- 允许控制是否为 Sub-Store 使用代理
- 允许设置内核进程优先级
- 提高进程优先级

### Bug Fixes

- 不使用pac模式时不再启动pac服务器
- 修复对话框上层可调整侧栏大小的问题
- 修复Windows系统路径错误
- 修复内核panic没有日志的问题
- 修复寻找可用端口失败的问题
11 changes: 10 additions & 1 deletion src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'))
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main/sys/autoRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/main/sys/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/src/components/settings/mihomo-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const MihomoConfig: React.FC = () => {
pauseSSID = [],
delayTestUrl,
userAgent,
mihomoCpuPriority = 'PRIORITY_HIGHEST',
proxyCols = 'auto'
} = appConfig || {}
const [url, setUrl] = useState(delayTestUrl)
Expand Down Expand Up @@ -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={
Expand Down
8 changes: 8 additions & 0 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -240,6 +247,7 @@ interface IAppConfig {
autoQuitWithoutCoreDelay?: number
useCustomSubStore?: boolean
useProxyInSubStore?: boolean
mihomoCpuPriority?: Priority
customSubStoreUrl?: string
diffWorkDir?: boolean
autoSetDNS?: boolean
Expand Down

0 comments on commit 5bafb7c

Please sign in to comment.