diff --git a/resources/iconTemplate.png b/resources/iconTemplate.png new file mode 100644 index 0000000..6212d2a Binary files /dev/null and b/resources/iconTemplate.png differ diff --git a/resources/iconTemplate@2x.png b/resources/iconTemplate@2x.png new file mode 100644 index 0000000..47da2ff Binary files /dev/null and b/resources/iconTemplate@2x.png differ diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 197d157..4fba039 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -43,11 +43,7 @@ export const getAxios = async (force: boolean = false): Promise = export async function mihomoVersion(): Promise { const instance = await getAxios() - try { - return await instance.get('/version') - } catch (error) { - return { version: '-', meta: true } - } + return await instance.get('/version') } export const patchMihomoConfig = async (patch: Partial): Promise => { @@ -67,29 +63,18 @@ export const mihomoCloseAllConnections = async (): Promise => { export const mihomoRules = async (): Promise => { const instance = await getAxios() - try { - return await instance.get('/rules') - } catch (e) { - return { rules: [] } - } + return await instance.get('/rules') } export const mihomoProxies = async (): Promise => { const instance = await getAxios() - try { - return await instance.get('/proxies') - } catch (e) { - return { proxies: {} } - } + + return await instance.get('/proxies') } export const mihomoProxyProviders = async (): Promise => { const instance = await getAxios() - try { - return await instance.get('/providers/proxies') - } catch (e) { - return { providers: {} } - } + return await instance.get('/providers/proxies') } export const mihomoUpdateProxyProviders = async (name: string): Promise => { @@ -99,11 +84,7 @@ export const mihomoUpdateProxyProviders = async (name: string): Promise => export const mihomoRuleProviders = async (): Promise => { const instance = await getAxios() - try { - return await instance.get('/providers/rules') - } catch (e) { - return { providers: {} } - } + return await instance.get('/providers/rules') } export const mihomoUpdateRuleProviders = async (name: string): Promise => { diff --git a/src/main/core/tray.ts b/src/main/core/tray.ts index 741f238..aafee78 100644 --- a/src/main/core/tray.ts +++ b/src/main/core/tray.ts @@ -6,9 +6,10 @@ import { } from '../config' import icoIcon from '../../../resources/icon.ico?asset' import pngIcon from '../../../resources/icon.png?asset' +import templateIcon from '../../../resources/iconTemplate.png?asset' import { patchMihomoConfig } from './mihomoApi' import { mainWindow, showMainWindow } from '..' -import { app, ipcMain, Menu, shell, Tray } from 'electron' +import { app, ipcMain, Menu, nativeImage, shell, Tray } from 'electron' import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs' import { triggerSysProxy } from '../resolve/sysproxy' @@ -141,7 +142,13 @@ const buildContextMenu = async (): Promise => { export async function createTray(): Promise { if (process.platform === 'linux') { tray = new Tray(pngIcon) - } else { + } + if (process.platform === 'darwin') { + const icon = nativeImage.createFromPath(templateIcon) + icon.setTemplateImage(true) + tray = new Tray(icon) + } + if (process.platform === 'win32') { tray = new Tray(icoIcon) } const menu = await buildContextMenu() @@ -153,11 +160,10 @@ export async function createTray(): Promise { await updateTrayMenu() }) - tray.setContextMenu(menu) - tray.setIgnoreDoubleClickEvents(true) - tray.setToolTip('Another Mihomo GUI.') - tray.setTitle('Mihomo Party') - tray.addListener('click', () => { + tray?.setContextMenu(menu) + tray?.setIgnoreDoubleClickEvents(true) + tray?.setToolTip('Mihomo Party') + tray?.addListener('click', () => { if (mainWindow?.isVisible()) { mainWindow?.close() } else {