mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 19:56:10 +08:00
fix ssid
This commit is contained in:
parent
4507593b4b
commit
683b334c10
|
@ -264,7 +264,7 @@ export function isEncryptionAvailable(): boolean {
|
|||
return safeStorage.isEncryptionAvailable()
|
||||
}
|
||||
|
||||
export async function getDefaultService(password?: string): Promise<string> {
|
||||
export async function getDefaultDevice(password?: string): Promise<string> {
|
||||
const execPromise = promisify(exec)
|
||||
let sudo = ''
|
||||
if (password) sudo = `echo "${password}" | sudo -S `
|
||||
|
@ -272,6 +272,14 @@ export async function getDefaultService(password?: string): Promise<string> {
|
|||
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')
|
||||
return device
|
||||
}
|
||||
|
||||
async function getDefaultService(password?: string): Promise<string> {
|
||||
const execPromise = promisify(exec)
|
||||
let sudo = ''
|
||||
if (password) sudo = `echo "${password}" | sudo -S `
|
||||
const device = await getDefaultDevice(password)
|
||||
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')
|
||||
|
|
|
@ -4,7 +4,7 @@ import { getAppConfig, patchControledMihomoConfig } from '../config'
|
|||
import { patchMihomoConfig } from '../core/mihomoApi'
|
||||
import { mainWindow } from '..'
|
||||
import { ipcMain, net } from 'electron'
|
||||
import { getDefaultService } from '../core/manager'
|
||||
import { getDefaultDevice } from '../core/manager'
|
||||
|
||||
export async function getCurrentSSID(): Promise<string | undefined> {
|
||||
if (process.platform === 'win32') {
|
||||
|
@ -79,11 +79,9 @@ async function getSSIDByAirport(): Promise<string | undefined> {
|
|||
async function getSSIDByNetworksetup(): Promise<string | undefined> {
|
||||
const execPromise = promisify(exec)
|
||||
if (net.isOnline()) {
|
||||
const service = await getDefaultService()
|
||||
const service = await getDefaultDevice()
|
||||
const { stdout } = await execPromise(`networksetup -listpreferredwirelessnetworks ${service}`)
|
||||
console.log(stdout)
|
||||
if (stdout.trim().startsWith('Preferred networks on')) {
|
||||
console.log(stdout.split('\n'))
|
||||
if (stdout.split('\n').length > 1) {
|
||||
return stdout.split('\n')[1].trim()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user