From 5bafb7ccc1fad40d79ef7593f359ebdbe1a1edfc Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Thu, 14 Nov 2024 21:06:14 +0800 Subject: [PATCH] support set core priority --- changelog.md | 11 +++++----- src/main/core/manager.ts | 11 +++++++++- src/main/sys/autoRun.ts | 2 +- src/main/sys/misc.ts | 2 +- .../src/components/settings/mihomo-config.tsx | 21 +++++++++++++++++++ src/shared/types.d.ts | 8 +++++++ 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index f5f36ce..d315a7f 100644 --- a/changelog.md +++ b/changelog.md @@ -7,12 +7,11 @@ ### Features -- 支持设置 `direct-nameserver` -- 支持设置 `route-exclude-address` +- 内置 Sub-Store 不使用缓存 +- 允许控制是否为 Sub-Store 使用代理 +- 允许设置内核进程优先级 +- 提高进程优先级 ### Bug Fixes -- 不使用pac模式时不再启动pac服务器 -- 修复对话框上层可调整侧栏大小的问题 -- 修复Windows系统路径错误 -- 修复内核panic没有日志的问题 +- 修复寻找可用端口失败的问题 diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 840abad..f161818 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -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[]> { - 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[]> { stdio: detached ? 'ignore' : undefined } ) + if (child.pid) { + os.setPriority(child.pid, os.constants.priority[mihomoCpuPriority]) + } if (detached) { child.unref() return new Promise((resolve) => { diff --git a/src/main/sys/autoRun.ts b/src/main/sys/autoRun.ts index 3c961ca..6415b1f 100644 --- a/src/main/sys/autoRun.ts +++ b/src/main/sys/autoRun.ts @@ -38,7 +38,7 @@ const taskXml = ` false false PT0S - 0 + 3 diff --git a/src/main/sys/misc.ts b/src/main/sys/misc.ts index 0ca1344..baa2a8e 100644 --- a/src/main/sys/misc.ts +++ b/src/main/sys/misc.ts @@ -90,7 +90,7 @@ const elevateTaskXml = ` false false PT0S - 0 + 3 diff --git a/src/renderer/src/components/settings/mihomo-config.tsx b/src/renderer/src/components/settings/mihomo-config.tsx index 3180953..12bca14 100644 --- a/src/renderer/src/components/settings/mihomo-config.tsx +++ b/src/renderer/src/components/settings/mihomo-config.tsx @@ -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 = () => { 四列 + + +