mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-26 20:50:30 +08:00
fix gist
This commit is contained in:
parent
256fffae0b
commit
59203d3855
@ -2,6 +2,11 @@
|
||||
|
||||
- 为了修复macOS应用内更新问题,此版本需要手动下载dmg进行安装
|
||||
|
||||
### Features
|
||||
|
||||
- 支持自定义延迟测试并发数量
|
||||
- 完善Sub-Store环境变量
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- 修复macOS应用内更新后权限丢失的问题
|
||||
|
||||
@ -80,7 +80,13 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +94,6 @@ 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) {
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user