Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
fix gist
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 23, 2024
1 parent 09847fe commit 4507593
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 43 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

- 为了修复macOS应用内更新问题,此版本需要手动下载dmg进行安装

### Features

- 支持自定义延迟测试并发数量
- 完善Sub-Store环境变量

### Bug Fixes

- 修复macOS应用内更新后权限丢失的问题
Expand Down
9 changes: 7 additions & 2 deletions src/main/resolve/gistApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,20 @@ export async function getGistUrl(): Promise<string> {
if (gist) {
return gist.html_url
} else {
throw new Error('Gist not found')
await uploadRuntimeConfig()
const gists = await listGists(githubToken)
const gist = gists.find(
(gist) => gist.description === 'Auto Synced Mihomo Party Runtime Config'
)
if (!gist) throw new Error('Gist not found')
return gist.html_url
}
}

export async function uploadRuntimeConfig(): Promise<void> {
const { githubToken } = await getAppConfig()
if (!githubToken) return
const gists = await listGists(githubToken)
console.log(gists)
const gist = gists.find((gist) => gist.description === 'Auto Synced Mihomo Party Runtime Config')
const config = await getRuntimeConfigStr()
if (gist) {
Expand Down
112 changes: 71 additions & 41 deletions src/main/sys/ssid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,26 @@ import { ipcMain, net } from 'electron'
import { getDefaultService } from '../core/manager'

export async function getCurrentSSID(): Promise<string | undefined> {
const execPromise = promisify(exec)
try {
if (process.platform === 'win32') {
const { stdout } = await execPromise('netsh wlan show interfaces')
for (const line of stdout.split('\n')) {
if (line.trim().startsWith('SSID')) {
return line.split(': ')[1].trim()
}
}
if (process.platform === 'win32') {
try {
return await getSSIDByNetsh()
} catch {
return undefined
}
if (process.platform === 'linux') {
const { stdout } = await execPromise(
`iwconfig 2>/dev/null | grep 'ESSID' | awk -F'"' '{print $2}'`
)
if (stdout.trim() !== '') {
return stdout.trim()
}
}
if (process.platform === 'linux') {
try {
return await getSSIDByIwconfig()
} catch {
return undefined
}
if (process.platform === 'darwin') {
const { stdout } = await execPromise(
'/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I'
)
if (stdout.trim().startsWith('WARNING')) {
if (net.isOnline()) {
const service = await getDefaultService()
const { stdout } = await execPromise(
`networksetup -listpreferredwirelessnetworks ${service}`
)
if (stdout.trim().startsWith('Preferred networks on')) {
if (stdout.split('\n').length > 1) {
return stdout.split('\n')[1].trim()
}
}
}
} else {
for (const line of stdout.split('\n')) {
if (line.trim().startsWith('SSID')) {
return line.split(': ')[1].trim()
}
}
}
}
if (process.platform === 'darwin') {
try {
return await getSSIDByAirport()
} catch {
return await getSSIDByNetworksetup()
}
} catch {
// ignore
}
return undefined
}
Expand Down Expand Up @@ -83,3 +59,57 @@ export async function startSSIDCheck(): Promise<void> {
await checkSSID()
setInterval(checkSSID, 30000)
}

async function getSSIDByAirport(): Promise<string | undefined> {
const execPromise = promisify(exec)
const { stdout } = await execPromise(
'/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I'
)
if (stdout.trim().startsWith('WARNING')) {
throw new Error('airport cannot be used')
}
for (const line of stdout.split('\n')) {
if (line.trim().startsWith('SSID')) {
return line.split(': ')[1].trim()
}
}
return undefined
}

async function getSSIDByNetworksetup(): Promise<string | undefined> {
const execPromise = promisify(exec)
if (net.isOnline()) {
const service = await getDefaultService()
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()
}
}
}
return undefined
}

async function getSSIDByNetsh(): Promise<string | undefined> {
const execPromise = promisify(exec)
const { stdout } = await execPromise('netsh wlan show interfaces')
for (const line of stdout.split('\n')) {
if (line.trim().startsWith('SSID')) {
return line.split(': ')[1].trim()
}
}
return undefined
}

async function getSSIDByIwconfig(): Promise<string | undefined> {
const execPromise = promisify(exec)
const { stdout } = await execPromise(
`iwconfig 2>/dev/null | grep 'ESSID' | awk -F'"' '{print $2}'`
)
if (stdout.trim() !== '') {
return stdout.trim()
}
return undefined
}

0 comments on commit 4507593

Please sign in to comment.