mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
add notification
This commit is contained in:
parent
cce305e9bc
commit
6592a7a278
@ -1,4 +1,4 @@
|
|||||||
import { app, globalShortcut, ipcMain } from 'electron'
|
import { app, globalShortcut, ipcMain, Notification } from 'electron'
|
||||||
import { mainWindow, showMainWindow } from '..'
|
import { mainWindow, showMainWindow } from '..'
|
||||||
import {
|
import {
|
||||||
getAppConfig,
|
getAppConfig,
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
} from '../config'
|
} from '../config'
|
||||||
import { triggerSysProxy } from '../sys/sysproxy'
|
import { triggerSysProxy } from '../sys/sysproxy'
|
||||||
import { patchMihomoConfig } from '../core/mihomoApi'
|
import { patchMihomoConfig } from '../core/mihomoApi'
|
||||||
import { quitWithoutCore } from '../core/manager'
|
import { quitWithoutCore, restartCore } from '../core/manager'
|
||||||
|
|
||||||
export async function registerShortcut(
|
export async function registerShortcut(
|
||||||
oldShortcut: string,
|
oldShortcut: string,
|
||||||
@ -39,6 +39,9 @@ export async function registerShortcut(
|
|||||||
try {
|
try {
|
||||||
await triggerSysProxy(!enable)
|
await triggerSysProxy(!enable)
|
||||||
await patchAppConfig({ sysProxy: { enable: !enable } })
|
await patchAppConfig({ sysProxy: { enable: !enable } })
|
||||||
|
new Notification({
|
||||||
|
title: `系统代理已${!enable ? '开启' : '关闭'}`
|
||||||
|
}).show()
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
} finally {
|
} finally {
|
||||||
@ -51,16 +54,31 @@ export async function registerShortcut(
|
|||||||
return globalShortcut.register(newShortcut, async () => {
|
return globalShortcut.register(newShortcut, async () => {
|
||||||
const { tun } = await getControledMihomoConfig()
|
const { tun } = await getControledMihomoConfig()
|
||||||
const enable = tun?.enable ?? false
|
const enable = tun?.enable ?? false
|
||||||
await patchControledMihomoConfig({ tun: { enable: !enable } })
|
try {
|
||||||
await patchMihomoConfig({ tun: { enable: !enable } })
|
if (!enable) {
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
await patchControledMihomoConfig({ tun: { enable: !enable }, dns: { enable: true } })
|
||||||
ipcMain.emit('updateTrayMenu')
|
} else {
|
||||||
|
await patchControledMihomoConfig({ tun: { enable: !enable } })
|
||||||
|
}
|
||||||
|
await restartCore()
|
||||||
|
new Notification({
|
||||||
|
title: `虚拟网卡已${!enable ? '开启' : '关闭'}`
|
||||||
|
}).show()
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
} finally {
|
||||||
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
|
ipcMain.emit('updateTrayMenu')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case 'ruleModeShortcut': {
|
case 'ruleModeShortcut': {
|
||||||
return globalShortcut.register(newShortcut, async () => {
|
return globalShortcut.register(newShortcut, async () => {
|
||||||
await patchControledMihomoConfig({ mode: 'rule' })
|
await patchControledMihomoConfig({ mode: 'rule' })
|
||||||
await patchMihomoConfig({ mode: 'rule' })
|
await patchMihomoConfig({ mode: 'rule' })
|
||||||
|
new Notification({
|
||||||
|
title: '已切换至规则模式'
|
||||||
|
}).show()
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
ipcMain.emit('updateTrayMenu')
|
ipcMain.emit('updateTrayMenu')
|
||||||
})
|
})
|
||||||
@ -69,6 +87,9 @@ export async function registerShortcut(
|
|||||||
return globalShortcut.register(newShortcut, async () => {
|
return globalShortcut.register(newShortcut, async () => {
|
||||||
await patchControledMihomoConfig({ mode: 'global' })
|
await patchControledMihomoConfig({ mode: 'global' })
|
||||||
await patchMihomoConfig({ mode: 'global' })
|
await patchMihomoConfig({ mode: 'global' })
|
||||||
|
new Notification({
|
||||||
|
title: '已切换至全局模式'
|
||||||
|
}).show()
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
ipcMain.emit('updateTrayMenu')
|
ipcMain.emit('updateTrayMenu')
|
||||||
})
|
})
|
||||||
@ -77,6 +98,9 @@ export async function registerShortcut(
|
|||||||
return globalShortcut.register(newShortcut, async () => {
|
return globalShortcut.register(newShortcut, async () => {
|
||||||
await patchControledMihomoConfig({ mode: 'direct' })
|
await patchControledMihomoConfig({ mode: 'direct' })
|
||||||
await patchMihomoConfig({ mode: 'direct' })
|
await patchMihomoConfig({ mode: 'direct' })
|
||||||
|
new Notification({
|
||||||
|
title: '已切换至直连模式'
|
||||||
|
}).show()
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
ipcMain.emit('updateTrayMenu')
|
ipcMain.emit('updateTrayMenu')
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user