fix MacOS tray icon

This commit is contained in:
pompurin404 2024-08-14 19:00:03 +08:00
parent fc6b86fabc
commit ae37550845
No known key found for this signature in database
4 changed files with 19 additions and 32 deletions

BIN
resources/iconTemplate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -43,11 +43,7 @@ export const getAxios = async (force: boolean = false): Promise<AxiosInstance> =
export async function mihomoVersion(): Promise<IMihomoVersion> {
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<IMihomoConfig>): Promise<void> => {
@ -67,29 +63,18 @@ export const mihomoCloseAllConnections = async (): Promise<void> => {
export const mihomoRules = async (): Promise<IMihomoRulesInfo> => {
const instance = await getAxios()
try {
return await instance.get('/rules')
} catch (e) {
return { rules: [] }
}
return await instance.get('/rules')
}
export const mihomoProxies = async (): Promise<IMihomoProxies> => {
const instance = await getAxios()
try {
return await instance.get('/proxies')
} catch (e) {
return { proxies: {} }
}
return await instance.get('/proxies')
}
export const mihomoProxyProviders = async (): Promise<IMihomoProxyProviders> => {
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<void> => {
@ -99,11 +84,7 @@ export const mihomoUpdateProxyProviders = async (name: string): Promise<void> =>
export const mihomoRuleProviders = async (): Promise<IMihomoRuleProviders> => {
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<void> => {

View File

@ -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<Menu> => {
export async function createTray(): Promise<void> {
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<void> {
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 {