This repository has been archived by the owner on Feb 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support direct connection under specific WiFi SSID
- Loading branch information
pompurin404
committed
Sep 22, 2024
1 parent
bdf53c6
commit d3887cc
Showing
5 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
### Features | ||
|
||
- 支持在特定WiFi SSID下直连 | ||
|
||
### Bug Fixes | ||
|
||
- 修复某些mac无法开启开机启动的问题 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { exec } from 'child_process' | ||
import { promisify } from 'util' | ||
import { getAppConfig, patchControledMihomoConfig } from '../config' | ||
import { patchMihomoConfig } from '../core/mihomoApi' | ||
import { mainWindow } from '..' | ||
import { ipcMain } from 'electron' | ||
|
||
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() | ||
} | ||
} | ||
} | ||
} catch { | ||
// ignore | ||
} | ||
return undefined | ||
} | ||
|
||
export async function checkSSID(): Promise<void> { | ||
try { | ||
const { pauseSSID = [] } = await getAppConfig() | ||
if (pauseSSID.length === 0) return | ||
const currentSSID = await getCurrentSSID() | ||
|
||
if (currentSSID && pauseSSID.includes(currentSSID)) { | ||
await patchControledMihomoConfig({ mode: 'direct' }) | ||
await patchMihomoConfig({ mode: 'direct' }) | ||
mainWindow?.webContents.send('controledMihomoConfigUpdated') | ||
ipcMain.emit('updateTrayMenu') | ||
} else { | ||
await patchControledMihomoConfig({ mode: 'rule' }) | ||
await patchMihomoConfig({ mode: 'rule' }) | ||
mainWindow?.webContents.send('controledMihomoConfigUpdated') | ||
ipcMain.emit('updateTrayMenu') | ||
} | ||
} catch { | ||
// ignore | ||
} | ||
} | ||
|
||
export async function startSSIDCheck(): Promise<void> { | ||
await checkSSID() | ||
setInterval(checkSSID, 30000) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters