diff --git a/changelog.md b/changelog.md index dc15f977..4d3ed8fd 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,11 @@ - 为了修复macOS应用内更新问题,此版本需要手动下载dmg进行安装 +### Features + +- 支持自定义延迟测试并发数量 +- 完善Sub-Store环境变量 + ### Bug Fixes - 修复macOS应用内更新后权限丢失的问题 diff --git a/src/main/resolve/gistApi.ts b/src/main/resolve/gistApi.ts index c879afa0..2e30700e 100644 --- a/src/main/resolve/gistApi.ts +++ b/src/main/resolve/gistApi.ts @@ -80,7 +80,13 @@ export async function getGistUrl(): Promise { 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 { 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) { diff --git a/src/main/sys/ssid.ts b/src/main/sys/ssid.ts index fb223bf4..40132df0 100644 --- a/src/main/sys/ssid.ts +++ b/src/main/sys/ssid.ts @@ -7,50 +7,26 @@ import { ipcMain, net } from 'electron' import { getDefaultService } from '../core/manager' export async function getCurrentSSID(): Promise { - 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 { await checkSSID() setInterval(checkSSID, 30000) } + +async function getSSIDByAirport(): Promise { + 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 { + 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 { + 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 { + 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 +}