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

Commit

Permalink
fix ssid on new system
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 23, 2024
1 parent 00ee111 commit 1d103ec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### Bug Fixes

- 修复macOS应用内更新后权限丢失的问题
- 修复高版本macOS SSID获取失败的问题
36 changes: 20 additions & 16 deletions src/main/resolve/autoUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'
import yaml from 'yaml'
import { app } from 'electron'
import { app, shell } from 'electron'
import { getControledMihomoConfig } from '../config'
import { dataDir, exeDir, exePath, isPortable, resourcesFilesDir } from '../utils/dirs'
import { rm, writeFile } from 'fs/promises'
Expand Down Expand Up @@ -85,23 +85,27 @@ export async function downloadAndInstallUpdate(version: string): Promise<void> {
app.quit()
}
if (file.endsWith('.dmg')) {
const execPromise = promisify(exec)
const name = exePath().split('.app')[0].replace('/Applications/', '')
await execPromise(
`hdiutil attach "${path.join(dataDir(), file)}" -mountpoint "/Volumes/mihomo-party" -nobrowse`
)
try {
await execPromise(`mv /Applications/${name}.app /tmp`)
await execPromise('cp -R "/Volumes/mihomo-party/mihomo-party.app" /Applications/')
await execPromise(`rm -rf /tmp/${name}.app`)
} catch (e) {
await execPromise(`mv /tmp/${name}.app /Applications`)
throw e
} finally {
await execPromise('hdiutil detach "/Volumes/mihomo-party"')
const execPromise = promisify(exec)
const name = exePath().split('.app')[0].replace('/Applications/', '')
await execPromise(
`hdiutil attach "${path.join(dataDir(), file)}" -mountpoint "/Volumes/mihomo-party" -nobrowse`
)
try {
await execPromise(`mv /Applications/${name}.app /tmp`)
await execPromise('cp -R "/Volumes/mihomo-party/mihomo-party.app" /Applications/')
await execPromise(`rm -rf /tmp/${name}.app`)
} catch (e) {
await execPromise(`mv /tmp/${name}.app /Applications`)
throw e
} finally {
await execPromise('hdiutil detach "/Volumes/mihomo-party"')
}
app.relaunch()
app.quit()
} catch {
shell.openPath(path.join(dataDir(), file))
}
app.relaunch()
app.quit()
}
} catch (e) {
rm(path.join(dataDir(), file))
Expand Down
16 changes: 11 additions & 5 deletions src/main/sys/ssid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promisify } from 'util'
import { getAppConfig, patchControledMihomoConfig } from '../config'
import { patchMihomoConfig } from '../core/mihomoApi'
import { mainWindow } from '..'
import { ipcMain } from 'electron'
import { ipcMain, net } from 'electron'
import { getDefaultService } from '../core/manager'

export async function getCurrentSSID(): Promise<string | undefined> {
Expand Down Expand Up @@ -36,10 +36,16 @@ export async function getCurrentSSID(): Promise<string | undefined> {
}
}
} catch {
const service = await getDefaultService()
const { stdout } = await execPromise(`networksetup -getairportnetwork ${service}`)
if (stdout.split(': ').length > 1) {
return stdout.split(': ')[1].trim()
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()
}
}
}
}
}
Expand Down

0 comments on commit 1d103ec

Please sign in to comment.