mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
display traffic info in tray
This commit is contained in:
parent
0394548f91
commit
18718eb697
36
README.md
36
README.md
@ -19,3 +19,39 @@
|
|||||||
| 蓝色 |  |  |  |
|
| 蓝色 |  |  |  |
|
||||||
| 粉色 |  |  |  |
|
| 粉色 |  |  |  |
|
||||||
| 绿色 |  |  |  |
|
| 绿色 |  |  |  |
|
||||||
|
|
||||||
|
### 特性
|
||||||
|
|
||||||
|
- [x] 开箱即用,无需服务模式的Tun
|
||||||
|
- [x] 多种配色主题可选,UI焕然一新
|
||||||
|
- [x] 支持大部分Mihomo常用配置修改
|
||||||
|
- [x] 内置稳定版和预览版Mihomo内核
|
||||||
|
- [x] 一键更新geo数据库
|
||||||
|
|
||||||
|
### 安装
|
||||||
|
|
||||||
|
在 [Releases](https://github.com/pompurin404/mihomo-party/releases/latest) 页面下载对应平台的安装包,安装后即可使用。
|
||||||
|
|
||||||
|
#### Windows
|
||||||
|
|
||||||
|
下载exe安装包,双击安装
|
||||||
|
|
||||||
|
或者下载便携版压缩包,解压后运行mihomo-party.exe文件
|
||||||
|
|
||||||
|
#### MacOS
|
||||||
|
|
||||||
|
下载dmg包,打开后将mihomo-party图标拖入Applications文件夹安装
|
||||||
|
|
||||||
|
#### Linux
|
||||||
|
|
||||||
|
##### Debian/Ubuntu
|
||||||
|
|
||||||
|
下载deb包,使用apt安装
|
||||||
|
|
||||||
|
##### Fedora
|
||||||
|
|
||||||
|
下载rpm包,使用dnf安装
|
||||||
|
|
||||||
|
##### Arch/Manjaro
|
||||||
|
|
||||||
|
通过 [AUR](https://aur.archlinux.org/packages?O=0&K=mihomo-party) 安装
|
||||||
|
|||||||
@ -278,12 +278,12 @@ const resolveFont = async () => {
|
|||||||
|
|
||||||
const tasks = [
|
const tasks = [
|
||||||
{
|
{
|
||||||
name: 'verge-mihomo-alpha',
|
name: 'mihomo-alpha',
|
||||||
func: () => getLatestAlphaVersion().then(() => resolveSidecar(MihomoAlpha())),
|
func: () => getLatestAlphaVersion().then(() => resolveSidecar(MihomoAlpha())),
|
||||||
retry: 5
|
retry: 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'verge-mihomo',
|
name: 'mihomo',
|
||||||
func: () => getLatestReleaseVersion().then(() => resolveSidecar(mihomo())),
|
func: () => getLatestReleaseVersion().then(() => resolveSidecar(mihomo())),
|
||||||
retry: 5
|
retry: 5
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,6 +2,8 @@ import axios, { AxiosInstance } from 'axios'
|
|||||||
import { getAppConfig, getControledMihomoConfig } from '../config'
|
import { getAppConfig, getControledMihomoConfig } from '../config'
|
||||||
import { mainWindow } from '..'
|
import { mainWindow } from '..'
|
||||||
import WebSocket from 'ws'
|
import WebSocket from 'ws'
|
||||||
|
import { tray } from './tray'
|
||||||
|
import { calcTraffic } from '../utils/calc'
|
||||||
|
|
||||||
let axiosIns: AxiosInstance = null!
|
let axiosIns: AxiosInstance = null!
|
||||||
let mihomoTrafficWs: WebSocket | null = null
|
let mihomoTrafficWs: WebSocket | null = null
|
||||||
@ -151,8 +153,21 @@ const mihomoTraffic = async (): Promise<void> => {
|
|||||||
|
|
||||||
mihomoTrafficWs.onmessage = (e): void => {
|
mihomoTrafficWs.onmessage = (e): void => {
|
||||||
const data = e.data as string
|
const data = e.data as string
|
||||||
|
const json = JSON.parse(data) as IMihomoTrafficInfo
|
||||||
|
tray?.setTitle(
|
||||||
|
'↑' +
|
||||||
|
`${calcTraffic(json.up)}/s`.padStart(16) +
|
||||||
|
'\n↓' +
|
||||||
|
`${calcTraffic(json.down)}/s`.padStart(16)
|
||||||
|
)
|
||||||
|
tray?.setToolTip(
|
||||||
|
'↑' +
|
||||||
|
`${calcTraffic(json.up)}/s`.padStart(16) +
|
||||||
|
'\n↓' +
|
||||||
|
`${calcTraffic(json.down)}/s`.padStart(16)
|
||||||
|
)
|
||||||
trafficRetry = 10
|
trafficRetry = 10
|
||||||
mainWindow?.webContents.send('mihomoTraffic', JSON.parse(data) as IMihomoTrafficInfo)
|
mainWindow?.webContents.send('mihomoTraffic', json)
|
||||||
}
|
}
|
||||||
|
|
||||||
mihomoTrafficWs.onclose = (): void => {
|
mihomoTrafficWs.onclose = (): void => {
|
||||||
@ -308,10 +323,9 @@ const mihomoConnections = async (): Promise<void> => {
|
|||||||
|
|
||||||
export const pauseWebsockets = () => {
|
export const pauseWebsockets = () => {
|
||||||
const recoverList: (() => void)[] = []
|
const recoverList: (() => void)[] = []
|
||||||
if (mihomoTrafficWs) {
|
// Traffic 始终开启
|
||||||
stopMihomoTraffic()
|
stopMihomoTraffic()
|
||||||
recoverList.push(startMihomoTraffic)
|
recoverList.push(startMihomoTraffic)
|
||||||
}
|
|
||||||
if (mihomoMemoryWs) {
|
if (mihomoMemoryWs) {
|
||||||
stopMihomoMemory()
|
stopMihomoMemory()
|
||||||
recoverList.push(startMihomoMemory)
|
recoverList.push(startMihomoMemory)
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import { app, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
|
|||||||
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
||||||
import { triggerSysProxy } from '../resolve/sysproxy'
|
import { triggerSysProxy } from '../resolve/sysproxy'
|
||||||
|
|
||||||
let tray: Tray | null = null
|
export let tray: Tray | null = null
|
||||||
|
|
||||||
const buildContextMenu = async (): Promise<Menu> => {
|
const buildContextMenu = async (): Promise<Menu> => {
|
||||||
const { mode, tun } = await getControledMihomoConfig()
|
const { mode, tun } = await getControledMihomoConfig()
|
||||||
@ -159,20 +159,33 @@ export async function createTray(): Promise<void> {
|
|||||||
ipcMain.on('appConfigUpdated', async () => {
|
ipcMain.on('appConfigUpdated', async () => {
|
||||||
await updateTrayMenu()
|
await updateTrayMenu()
|
||||||
})
|
})
|
||||||
|
tray?.setToolTip('Mihomo Party')
|
||||||
tray?.setContextMenu(menu)
|
tray?.setContextMenu(menu)
|
||||||
tray?.setIgnoreDoubleClickEvents(true)
|
tray?.setIgnoreDoubleClickEvents(true)
|
||||||
tray?.setToolTip('Mihomo Party')
|
if (process.platform === 'darwin') {
|
||||||
tray?.addListener('click', () => {
|
app.dock.setMenu(menu)
|
||||||
if (mainWindow?.isVisible()) {
|
tray?.addListener('right-click', () => {
|
||||||
mainWindow?.close()
|
if (mainWindow?.isVisible()) {
|
||||||
} else {
|
mainWindow?.close()
|
||||||
showMainWindow()
|
} else {
|
||||||
}
|
showMainWindow()
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
tray?.addListener('click', () => {
|
||||||
|
if (mainWindow?.isVisible()) {
|
||||||
|
mainWindow?.close()
|
||||||
|
} else {
|
||||||
|
showMainWindow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateTrayMenu(): Promise<void> {
|
async function updateTrayMenu(): Promise<void> {
|
||||||
const menu = await buildContextMenu()
|
const menu = await buildContextMenu()
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
app.dock.setMenu(menu) // 更新dock菜单
|
||||||
|
}
|
||||||
tray?.setContextMenu(menu) // 更新菜单
|
tray?.setContextMenu(menu) // 更新菜单
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,12 +9,7 @@ import { createTray } from './core/tray'
|
|||||||
import { init } from './resolve/init'
|
import { init } from './resolve/init'
|
||||||
import { addProfileItem, getAppConfig } from './config'
|
import { addProfileItem, getAppConfig } from './config'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import {
|
import { startMihomoMemory, stopMihomoMemory } from './core/mihomoApi'
|
||||||
startMihomoMemory,
|
|
||||||
startMihomoTraffic,
|
|
||||||
stopMihomoMemory,
|
|
||||||
stopMihomoTraffic
|
|
||||||
} from './core/mihomoApi'
|
|
||||||
|
|
||||||
export let mainWindow: BrowserWindow | null = null
|
export let mainWindow: BrowserWindow | null = null
|
||||||
export let destroyTimer: NodeJS.Timeout | null = null
|
export let destroyTimer: NodeJS.Timeout | null = null
|
||||||
@ -159,12 +154,10 @@ export function createWindow(show = false): void {
|
|||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.on('show', () => {
|
mainWindow.on('show', () => {
|
||||||
startMihomoTraffic()
|
|
||||||
startMihomoMemory()
|
startMihomoMemory()
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', (event) => {
|
||||||
stopMihomoTraffic()
|
|
||||||
stopMihomoMemory()
|
stopMihomoMemory()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
mainWindow?.hide()
|
mainWindow?.hide()
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import { getAppConfig } from '../config'
|
|||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import { startCore } from '../core/manager'
|
import { startCore } from '../core/manager'
|
||||||
import { initProfileUpdater } from '../core/profileUpdater'
|
import { initProfileUpdater } from '../core/profileUpdater'
|
||||||
|
import { startMihomoTraffic } from '../core/mihomoApi'
|
||||||
|
|
||||||
async function initDirs(): Promise<void> {
|
async function initDirs(): Promise<void> {
|
||||||
if (!existsSync(dataDir)) {
|
if (!existsSync(dataDir)) {
|
||||||
@ -109,6 +110,7 @@ export async function init(): Promise<void> {
|
|||||||
const { sysProxy } = await getAppConfig()
|
const { sysProxy } = await getAppConfig()
|
||||||
await triggerSysProxy(sysProxy.enable)
|
await triggerSysProxy(sysProxy.enable)
|
||||||
startCore().then(() => {
|
startCore().then(() => {
|
||||||
|
startMihomoTraffic()
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await initProfileUpdater()
|
await initProfileUpdater()
|
||||||
}, 60000)
|
}, 60000)
|
||||||
|
|||||||
19
src/main/utils/calc.ts
Normal file
19
src/main/utils/calc.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export function calcTraffic(byte: number): string {
|
||||||
|
if (byte < 1024) return `${byte} B`
|
||||||
|
byte /= 1024
|
||||||
|
if (byte < 1024) return `${byte.toFixed(2)} KB`
|
||||||
|
byte /= 1024
|
||||||
|
if (byte < 1024) return `${byte.toFixed(2)} MB`
|
||||||
|
byte /= 1024
|
||||||
|
if (byte < 1024) return `${byte.toFixed(2)} GB`
|
||||||
|
byte /= 1024
|
||||||
|
if (byte < 1024) return `${byte.toFixed(2)} TB`
|
||||||
|
byte /= 1024
|
||||||
|
if (byte < 1024) return `${byte.toFixed(2)} PB`
|
||||||
|
byte /= 1024
|
||||||
|
if (byte < 1024) return `${byte.toFixed(2)} EB`
|
||||||
|
byte /= 1024
|
||||||
|
if (byte < 1024) return `${byte.toFixed(2)} ZB`
|
||||||
|
byte /= 1024
|
||||||
|
return `${byte.toFixed(2)} YB`
|
||||||
|
}
|
||||||
@ -17,7 +17,7 @@ const OutboundModeSwitcher: React.FC = () => {
|
|||||||
await mihomoCloseAllConnections()
|
await mihomoCloseAllConnections()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!mode) return null
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
fullWidth
|
fullWidth
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user