fix dns for macos
Some checks are pending
Build / windows (arm64) (push) Waiting to run
Build / windows (ia32) (push) Waiting to run
Build / windows (x64) (push) Waiting to run
Build / linux (arm64) (push) Waiting to run
Build / linux (x64) (push) Waiting to run
Build / macos (arm64) (push) Waiting to run
Build / macos (x64) (push) Waiting to run
Build / updater (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-bin) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron-bin) (push) Blocked by required conditions
Build / aur-git-updater (push) Waiting to run

This commit is contained in:
pompurin404 2024-09-02 10:25:50 +08:00
parent 408f445c73
commit 52f9980295
No known key found for this signature in database
2 changed files with 13 additions and 7 deletions

View File

@ -10,5 +10,4 @@
### Bug Fixes ### Bug Fixes
- 修复更新内核后内核无法正常关闭的问题 - 修复某些MacOS DNS设置失败的问题
- 优化规则/代理页面性能

View File

@ -44,7 +44,13 @@ export async function startCore(): Promise<void> {
await checkProfile() await checkProfile()
await stopCore() await stopCore()
if (tun?.enable && autoSetDNS) { if (tun?.enable && autoSetDNS) {
await setPublicDNS() try {
await setPublicDNS()
} catch (error) {
await writeFile(logPath(), `[Manager]: set dns failed, ${error}`, {
flag: 'a'
})
}
} }
child = spawn(corePath, ['-d', mihomoWorkDir()]) child = spawn(corePath, ['-d', mihomoWorkDir()])
child.on('close', async (code, signal) => { child.on('close', async (code, signal) => {
@ -93,7 +99,9 @@ export async function stopCore(force = false): Promise<void> {
await recoverDNS() await recoverDNS()
} }
} catch (error) { } catch (error) {
// todo await writeFile(logPath(), `[Manager]: recover dns failed, ${error}`, {
flag: 'a'
})
} }
if (child) { if (child) {
@ -202,7 +210,7 @@ async function getOriginDNS(password?: string): Promise<void> {
let sudo = '' let sudo = ''
if (password) sudo = `echo "${password}" | sudo -S ` if (password) sudo = `echo "${password}" | sudo -S `
const service = await getDefaultService(password) const service = await getDefaultService(password)
const { stdout: dns } = await execPromise(`${sudo}networksetup -getdnsservers ${service}`) const { stdout: dns } = await execPromise(`${sudo}networksetup -getdnsservers "${service}"`)
if (dns.startsWith("There aren't any DNS Servers set on")) { if (dns.startsWith("There aren't any DNS Servers set on")) {
await patchAppConfig({ originDNS: 'Empty' }) await patchAppConfig({ originDNS: 'Empty' })
} else { } else {
@ -215,8 +223,7 @@ async function setDNS(dns: string, password?: string): Promise<void> {
let sudo = '' let sudo = ''
if (password) sudo = `echo "${password}" | sudo -S ` if (password) sudo = `echo "${password}" | sudo -S `
const execPromise = promisify(exec) const execPromise = promisify(exec)
await execPromise(`${sudo}networksetup -setdnsservers ${service} ${dns}`) await execPromise(`${sudo}networksetup -setdnsservers "${service}" ${dns}`)
// todo
} }
async function setPublicDNS(): Promise<void> { async function setPublicDNS(): Promise<void> {