diff --git a/README.md b/README.md index bc28e0d..9aba67c 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,39 @@ | 蓝色 | ![](./images/dark-blue.png) | ![](./images/gray-blue.png) | ![](./images/light-blue.png) | | 粉色 | ![](./images/dark-pink.png) | ![](./images/gray-pink.png) | ![](./images/light-pink.png) | | 绿色 | ![](./images/dark-green.png) | ![](./images/gray-green.png) | ![](./images/light-green.png) | + +### 特性 + +- [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) 安装 diff --git a/scripts/prepare.mjs b/scripts/prepare.mjs index 1eb9091..a2a123e 100644 --- a/scripts/prepare.mjs +++ b/scripts/prepare.mjs @@ -278,12 +278,12 @@ const resolveFont = async () => { const tasks = [ { - name: 'verge-mihomo-alpha', + name: 'mihomo-alpha', func: () => getLatestAlphaVersion().then(() => resolveSidecar(MihomoAlpha())), retry: 5 }, { - name: 'verge-mihomo', + name: 'mihomo', func: () => getLatestReleaseVersion().then(() => resolveSidecar(mihomo())), retry: 5 }, diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 4fba039..29ea7ff 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -2,6 +2,8 @@ import axios, { AxiosInstance } from 'axios' import { getAppConfig, getControledMihomoConfig } from '../config' import { mainWindow } from '..' import WebSocket from 'ws' +import { tray } from './tray' +import { calcTraffic } from '../utils/calc' let axiosIns: AxiosInstance = null! let mihomoTrafficWs: WebSocket | null = null @@ -151,8 +153,21 @@ const mihomoTraffic = async (): Promise => { mihomoTrafficWs.onmessage = (e): void => { 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 - mainWindow?.webContents.send('mihomoTraffic', JSON.parse(data) as IMihomoTrafficInfo) + mainWindow?.webContents.send('mihomoTraffic', json) } mihomoTrafficWs.onclose = (): void => { @@ -308,10 +323,9 @@ const mihomoConnections = async (): Promise => { export const pauseWebsockets = () => { const recoverList: (() => void)[] = [] - if (mihomoTrafficWs) { - stopMihomoTraffic() - recoverList.push(startMihomoTraffic) - } + // Traffic 始终开启 + stopMihomoTraffic() + recoverList.push(startMihomoTraffic) if (mihomoMemoryWs) { stopMihomoMemory() recoverList.push(startMihomoMemory) diff --git a/src/main/core/tray.ts b/src/main/core/tray.ts index aafee78..8d19faf 100644 --- a/src/main/core/tray.ts +++ b/src/main/core/tray.ts @@ -13,7 +13,7 @@ import { app, ipcMain, Menu, nativeImage, shell, Tray } from 'electron' import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs' import { triggerSysProxy } from '../resolve/sysproxy' -let tray: Tray | null = null +export let tray: Tray | null = null const buildContextMenu = async (): Promise => { const { mode, tun } = await getControledMihomoConfig() @@ -159,20 +159,33 @@ export async function createTray(): Promise { ipcMain.on('appConfigUpdated', async () => { await updateTrayMenu() }) - + tray?.setToolTip('Mihomo Party') tray?.setContextMenu(menu) tray?.setIgnoreDoubleClickEvents(true) - tray?.setToolTip('Mihomo Party') - tray?.addListener('click', () => { - if (mainWindow?.isVisible()) { - mainWindow?.close() - } else { - showMainWindow() - } - }) + if (process.platform === 'darwin') { + app.dock.setMenu(menu) + tray?.addListener('right-click', () => { + if (mainWindow?.isVisible()) { + mainWindow?.close() + } else { + showMainWindow() + } + }) + } else { + tray?.addListener('click', () => { + if (mainWindow?.isVisible()) { + mainWindow?.close() + } else { + showMainWindow() + } + }) + } } async function updateTrayMenu(): Promise { const menu = await buildContextMenu() + if (process.platform === 'darwin') { + app.dock.setMenu(menu) // 更新dock菜单 + } tray?.setContextMenu(menu) // 更新菜单 } diff --git a/src/main/index.ts b/src/main/index.ts index 0a3673c..41c1ff3 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -9,12 +9,7 @@ import { createTray } from './core/tray' import { init } from './resolve/init' import { addProfileItem, getAppConfig } from './config' import { join } from 'path' -import { - startMihomoMemory, - startMihomoTraffic, - stopMihomoMemory, - stopMihomoTraffic -} from './core/mihomoApi' +import { startMihomoMemory, stopMihomoMemory } from './core/mihomoApi' export let mainWindow: BrowserWindow | null = null export let destroyTimer: NodeJS.Timeout | null = null @@ -159,12 +154,10 @@ export function createWindow(show = false): void { }) mainWindow.on('show', () => { - startMihomoTraffic() startMihomoMemory() }) mainWindow.on('close', (event) => { - stopMihomoTraffic() stopMihomoMemory() event.preventDefault() mainWindow?.hide() diff --git a/src/main/resolve/init.ts b/src/main/resolve/init.ts index 598eae0..546606c 100644 --- a/src/main/resolve/init.ts +++ b/src/main/resolve/init.ts @@ -29,6 +29,7 @@ import { getAppConfig } from '../config' import { app } from 'electron' import { startCore } from '../core/manager' import { initProfileUpdater } from '../core/profileUpdater' +import { startMihomoTraffic } from '../core/mihomoApi' async function initDirs(): Promise { if (!existsSync(dataDir)) { @@ -109,6 +110,7 @@ export async function init(): Promise { const { sysProxy } = await getAppConfig() await triggerSysProxy(sysProxy.enable) startCore().then(() => { + startMihomoTraffic() setTimeout(async () => { await initProfileUpdater() }, 60000) diff --git a/src/main/utils/calc.ts b/src/main/utils/calc.ts new file mode 100644 index 0000000..9a1a92a --- /dev/null +++ b/src/main/utils/calc.ts @@ -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` +} diff --git a/src/renderer/src/components/sider/outbound-mode-switcher.tsx b/src/renderer/src/components/sider/outbound-mode-switcher.tsx index 42b4ac7..4c7c8c3 100644 --- a/src/renderer/src/components/sider/outbound-mode-switcher.tsx +++ b/src/renderer/src/components/sider/outbound-mode-switcher.tsx @@ -17,7 +17,7 @@ const OutboundModeSwitcher: React.FC = () => { await mihomoCloseAllConnections() } } - + if (!mode) return null return (