Skip to content

Commit

Permalink
Add some core settings
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Jan 4, 2025
1 parent bc17f4a commit 86393d7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 14 deletions.
28 changes: 23 additions & 5 deletions src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
core = 'mihomo',
autoSetDNS = true,
diffWorkDir = false,
mihomoCpuPriority = 'PRIORITY_NORMAL'
mihomoCpuPriority = 'PRIORITY_NORMAL',
disableLoopbackDetector = false,
disableEmbedCA = false,
disableSystemCA = false,
skipSafePathCheck = false
} = await getAppConfig()
const { 'log-level': logLevel } = await getControledMihomoConfig()
if (existsSync(path.join(dataDir(), 'core.pid'))) {
Expand Down Expand Up @@ -92,12 +96,19 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
}
const stdout = createWriteStream(logPath(), { flags: 'a' })
const stderr = createWriteStream(logPath(), { flags: 'a' })
const env = {
DISABLE_LOOPBACK_DETECTOR: String(disableLoopbackDetector),
DISABLE_EMBED_CA: String(disableEmbedCA),
DISABLE_SYSTEM_CA: String(disableSystemCA),
SKIP_SAFE_PATH_CHECK: String(skipSafePathCheck)
}
child = spawn(
corePath,
['-d', diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), ctlParam, mihomoIpcPath],
{
detached: detached,
stdio: detached ? 'ignore' : undefined
stdio: detached ? 'ignore' : undefined,
env: env
}
)
if (process.platform === 'win32' && child.pid) {
Expand Down Expand Up @@ -130,7 +141,7 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
patchControledMihomoConfig({ tun: { enable: false } })
mainWindow?.webContents.send('controledMihomoConfigUpdated')
ipcMain.emit('updateTrayMenu')
reject('虚拟网卡启动失败, 请尝试手动授予内核权限')
reject('虚拟网卡启动失败请尝试手动授予内核权限')
}

if (
Expand Down Expand Up @@ -211,18 +222,25 @@ export async function quitWithoutCore(): Promise<void> {
}

async function checkProfile(): Promise<void> {
const { core = 'mihomo', diffWorkDir = false } = await getAppConfig()
const {
core = 'mihomo',
diffWorkDir = false,
skipSafePathCheck = false
} = await getAppConfig()
const { current } = await getProfileConfig()
const corePath = mihomoCorePath(core)
const execFilePromise = promisify(execFile)
const env = {
SKIP_SAFE_PATH_CHECK: String(skipSafePathCheck)
}
try {
await execFilePromise(corePath, [
'-t',
'-f',
diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work'),
'-d',
mihomoTestDir()
])
], { env })
} catch (error) {
if (error instanceof Error && 'stdout' in error) {
const { stdout } = error as { stdout: string }
Expand Down
65 changes: 56 additions & 9 deletions src/renderer/src/pages/mihomo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ const CoreMap = {

const Mihomo: React.FC = () => {
const { appConfig, patchAppConfig } = useAppConfig()
const { core = 'mihomo', maxLogDays = 7, sysProxy } = appConfig || {}
const {
core = 'mihomo',
maxLogDays = 7,
sysProxy,
disableLoopbackDetector,
disableEmbedCA,
disableSystemCA,
skipSafePathCheck } = appConfig || {}
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const {
ipv6,
Expand Down Expand Up @@ -68,6 +75,17 @@ const Mihomo: React.FC = () => {
await restartCore()
}

const handleConfigChangeWithRestart = async (key: string, value: any) => {
try {
await patchAppConfig({ [key]: value })
await restartCore()
} catch (e) {
alert(e)
} finally {
PubSub.publish('mihomo-core-changed')
}
}

return (
<>
{lanOpen && <InterfaceModal onClose={() => setLanOpen(false)} />}
Expand Down Expand Up @@ -116,14 +134,7 @@ const Mihomo: React.FC = () => {
size="sm"
selectedKeys={new Set([core])}
onSelectionChange={async (v) => {
try {
await patchAppConfig({ core: v.currentKey as 'mihomo' | 'mihomo-alpha' })
await restartCore()
} catch (e) {
alert(e)
} finally {
PubSub.publish('mihomo-core-changed')
}
handleConfigChangeWithRestart('core', v.currentKey as 'mihomo' | 'mihomo-alpha')
}}
>
<SelectItem key="mihomo">{CoreMap['mihomo']}</SelectItem>
Expand Down Expand Up @@ -634,6 +645,42 @@ const Mihomo: React.FC = () => {
}}
/>
</SettingItem>
<SettingItem title="禁用回环检测器" divider>
<Switch
size="sm"
isSelected={disableLoopbackDetector}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableLoopbackDetector', v)
}}
/>
</SettingItem>
<SettingItem title="禁用安全路径检查" divider>
<Switch
size="sm"
isSelected={skipSafePathCheck}
onValueChange={(v) => {
handleConfigChangeWithRestart('skipSafePathCheck', v)
}}
/>
</SettingItem>
<SettingItem title="不使用内置 CA 证书" divider>
<Switch
size="sm"
isSelected={disableEmbedCA}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableEmbedCA', v)
}}
/>
</SettingItem>
<SettingItem title="不使用系统 CA 证书" divider>
<Switch
size="sm"
isSelected={disableSystemCA}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableSystemCA', v)
}}
/>
</SettingItem>
<SettingItem title="日志保留天数" divider>
<Input
size="sm"
Expand Down
4 changes: 4 additions & 0 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ interface ISysProxyConfig {

interface IAppConfig {
core: 'mihomo' | 'mihomo-alpha'
disableLoopbackDetector: boolean
disableEmbedCA: boolean
disableSystemCA: boolean
skipSafePathCheck: boolean
proxyDisplayMode: 'simple' | 'full'
proxyDisplayOrder: 'default' | 'delay' | 'name'
profileDisplayDate?: 'expire' | 'update'
Expand Down

0 comments on commit 86393d7

Please sign in to comment.