From d137b372ea07c782bb7fa04ebbf1e227eeeb0fdf Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Mon, 2 Sep 2024 15:13:12 +0800 Subject: [PATCH] try to fix macos dns --- src/main/core/manager.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 7070816..3c10b19 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -192,14 +192,12 @@ async function getDefaultService(password?: string): Promise { let device = deviceOut.split('\n').find((s) => s.includes('interface:')) device = device?.trim().split(' ').slice(1).join(' ') if (!device) throw new Error('Get device failed') - const { stdout: hardwareOut } = await execPromise(`${sudo}networksetup -listallhardwareports`) - const hardware = hardwareOut - .split('Ethernet Address:') - .find((s) => s.includes(`Device: ${device}`)) - if (!hardware) throw new Error('Get hardware failed') - for (const line of hardware.split('\n')) { - if (line.startsWith('Hardware Port:')) { - return line.trim().split(' ').slice(2).join(' ') + const { stdout: order } = await execPromise(`${sudo}networksetup -listnetworkserviceorder`) + const block = order.split('\n\n').find((s) => s.includes(`Device: ${device}`)) + if (!block) throw new Error('Get networkservice failed') + for (const line of block.split('\n')) { + if (line.match(/^\(\d+\).*/)) { + return line.trim().split(' ').slice(1).join(' ') } } throw new Error('Get service failed')