mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-26 20:50:30 +08:00
supports manual grant core for macos
This commit is contained in:
parent
7e30114ef2
commit
a3c129f9e1
@ -19,7 +19,7 @@ let retry = 10
|
||||
export async function startCore(): Promise<void> {
|
||||
const { core = 'mihomo' } = await getAppConfig()
|
||||
const corePath = mihomoCorePath(core)
|
||||
await grantCorePermition(corePath)
|
||||
await autoGrantCorePermition(corePath)
|
||||
await generateProfile()
|
||||
await checkProfile()
|
||||
stopCore()
|
||||
@ -90,7 +90,7 @@ async function checkProfile(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function grantCorePermition(corePath: string): Promise<void> {
|
||||
export async function autoGrantCorePermition(corePath: string): Promise<void> {
|
||||
const { encryptedPassword } = await getAppConfig()
|
||||
const execPromise = promisify(exec)
|
||||
if (encryptedPassword && isEncryptionAvailable()) {
|
||||
@ -117,6 +117,17 @@ export async function grantCorePermition(corePath: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function manualGrantCorePermition(): Promise<void> {
|
||||
const { core = 'mihomo' } = await getAppConfig()
|
||||
const corePath = mihomoCorePath(core)
|
||||
const execPromise = promisify(exec)
|
||||
if (process.platform === 'darwin') {
|
||||
const shell = `chown root:admin ${corePath}\nchmod +sx ${corePath}`
|
||||
const command = `do shell script "${shell}" with administrator privileges`
|
||||
await execPromise(`osascript -e '${command}'`)
|
||||
}
|
||||
}
|
||||
|
||||
export function isEncryptionAvailable(): boolean {
|
||||
return safeStorage.isEncryptionAvailable()
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ import {
|
||||
setOverride,
|
||||
updateOverrideItem
|
||||
} from '../config'
|
||||
import { isEncryptionAvailable, restartCore } from '../core/manager'
|
||||
import { isEncryptionAvailable, manualGrantCorePermition, restartCore } from '../core/manager'
|
||||
import { triggerSysProxy } from '../resolve/sysproxy'
|
||||
import { checkUpdate } from '../resolve/autoUpdater'
|
||||
import { exePath, mihomoCorePath, mihomoWorkConfigPath, resourcesDir } from './dirs'
|
||||
@ -128,6 +128,7 @@ export function registerIpcMainHandlers(): void {
|
||||
ipcMain.handle('triggerSysProxy', (_e, enable) => ipcErrorWrapper(triggerSysProxy)(enable))
|
||||
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
|
||||
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))
|
||||
ipcMain.handle('manualGrantCorePermition', ipcErrorWrapper(manualGrantCorePermition))
|
||||
ipcMain.handle('getFilePath', (_e, ext) => getFilePath(ext))
|
||||
ipcMain.handle('readTextFile', (_e, filePath) => ipcErrorWrapper(readTextFile)(filePath))
|
||||
ipcMain.handle('getRuntimeConfigStr', ipcErrorWrapper(getRuntimeConfigStr))
|
||||
|
||||
@ -3,7 +3,7 @@ import BasePage from '@renderer/components/base/base-page'
|
||||
import SettingCard from '@renderer/components/base/base-setting-card'
|
||||
import SettingItem from '@renderer/components/base/base-setting-item'
|
||||
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
||||
import { restartCore, setupFirewall } from '@renderer/utils/ipc'
|
||||
import { manualGrantCorePermition, restartCore, setupFirewall } from '@renderer/utils/ipc'
|
||||
import { platform } from '@renderer/utils/init'
|
||||
import React, { Key, useState } from 'react'
|
||||
|
||||
@ -88,6 +88,29 @@ const Tun: React.FC = () => {
|
||||
</Button>
|
||||
</SettingItem>
|
||||
)}
|
||||
{platform === 'darwin' && (
|
||||
<SettingItem title="手动授权内核" divider>
|
||||
<Button
|
||||
size="sm"
|
||||
color="primary"
|
||||
isLoading={loading}
|
||||
onPress={async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
await manualGrantCorePermition()
|
||||
new Notification('内核授权成功')
|
||||
await restartCore()
|
||||
} catch (e) {
|
||||
alert(e)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
手动授权内核
|
||||
</Button>
|
||||
</SettingItem>
|
||||
)}
|
||||
<SettingItem title="Tun 模式堆栈" divider>
|
||||
<Tabs
|
||||
size="sm"
|
||||
|
||||
@ -205,6 +205,10 @@ export async function encryptString(str: string): Promise<Buffer> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('encryptString', str))
|
||||
}
|
||||
|
||||
export async function manualGrantCorePermition(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('manualGrantCorePermition'))
|
||||
}
|
||||
|
||||
export async function getFilePath(ext: string[]): Promise<string[] | undefined> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('getFilePath', ext))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user