mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
fix ssid
This commit is contained in:
parent
59203d3855
commit
bbb0efd1cf
@ -264,7 +264,7 @@ export function isEncryptionAvailable(): boolean {
|
|||||||
return safeStorage.isEncryptionAvailable()
|
return safeStorage.isEncryptionAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDefaultService(password?: string): Promise<string> {
|
export async function getDefaultDevice(password?: string): Promise<string> {
|
||||||
const execPromise = promisify(exec)
|
const execPromise = promisify(exec)
|
||||||
let sudo = ''
|
let sudo = ''
|
||||||
if (password) sudo = `echo "${password}" | sudo -S `
|
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:'))
|
let device = deviceOut.split('\n').find((s) => s.includes('interface:'))
|
||||||
device = device?.trim().split(' ').slice(1).join(' ')
|
device = device?.trim().split(' ').slice(1).join(' ')
|
||||||
if (!device) throw new Error('Get device failed')
|
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 { stdout: order } = await execPromise(`${sudo}networksetup -listnetworkserviceorder`)
|
||||||
const block = order.split('\n\n').find((s) => s.includes(`Device: ${device}`))
|
const block = order.split('\n\n').find((s) => s.includes(`Device: ${device}`))
|
||||||
if (!block) throw new Error('Get networkservice failed')
|
if (!block) throw new Error('Get networkservice failed')
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { getAppConfig, patchControledMihomoConfig } from '../config'
|
|||||||
import { patchMihomoConfig } from '../core/mihomoApi'
|
import { patchMihomoConfig } from '../core/mihomoApi'
|
||||||
import { mainWindow } from '..'
|
import { mainWindow } from '..'
|
||||||
import { ipcMain, net } from 'electron'
|
import { ipcMain, net } from 'electron'
|
||||||
import { getDefaultService } from '../core/manager'
|
import { getDefaultDevice } from '../core/manager'
|
||||||
|
|
||||||
export async function getCurrentSSID(): Promise<string | undefined> {
|
export async function getCurrentSSID(): Promise<string | undefined> {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
@ -79,11 +79,9 @@ async function getSSIDByAirport(): Promise<string | undefined> {
|
|||||||
async function getSSIDByNetworksetup(): Promise<string | undefined> {
|
async function getSSIDByNetworksetup(): Promise<string | undefined> {
|
||||||
const execPromise = promisify(exec)
|
const execPromise = promisify(exec)
|
||||||
if (net.isOnline()) {
|
if (net.isOnline()) {
|
||||||
const service = await getDefaultService()
|
const service = await getDefaultDevice()
|
||||||
const { stdout } = await execPromise(`networksetup -listpreferredwirelessnetworks ${service}`)
|
const { stdout } = await execPromise(`networksetup -listpreferredwirelessnetworks ${service}`)
|
||||||
console.log(stdout)
|
|
||||||
if (stdout.trim().startsWith('Preferred networks on')) {
|
if (stdout.trim().startsWith('Preferred networks on')) {
|
||||||
console.log(stdout.split('\n'))
|
|
||||||
if (stdout.split('\n').length > 1) {
|
if (stdout.split('\n').length > 1) {
|
||||||
return stdout.split('\n')[1].trim()
|
return stdout.split('\n')[1].trim()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user