Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d98b534

Browse files
author
pompurin404
committedAug 14, 2024··
fix MacOS tray icon
1 parent fc6b86f commit d98b534

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed
 

‎resources/iconTemplate.png

3.3 KB
Loading

‎resources/iocnTemplate@2x.png

6.3 KB
Loading

‎src/main/core/tray.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
} from '../config'
77
import icoIcon from '../../../resources/icon.ico?asset'
88
import pngIcon from '../../../resources/icon.png?asset'
9+
import templateIcon from '../../../resources/iconTemplate.png?asset'
910
import { patchMihomoConfig } from './mihomoApi'
1011
import { mainWindow, showMainWindow } from '..'
11-
import { app, ipcMain, Menu, shell, Tray } from 'electron'
12+
import { app, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
1213
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
1314
import { triggerSysProxy } from '../resolve/sysproxy'
1415

@@ -141,7 +142,13 @@ const buildContextMenu = async (): Promise<Menu> => {
141142
export async function createTray(): Promise<void> {
142143
if (process.platform === 'linux') {
143144
tray = new Tray(pngIcon)
144-
} else {
145+
}
146+
if (process.platform === 'darwin') {
147+
const icon = nativeImage.createFromPath(templateIcon)
148+
icon.setTemplateImage(true)
149+
tray = new Tray(icon)
150+
}
151+
if (process.platform === 'win32') {
145152
tray = new Tray(icoIcon)
146153
}
147154
const menu = await buildContextMenu()
@@ -153,11 +160,11 @@ export async function createTray(): Promise<void> {
153160
await updateTrayMenu()
154161
})
155162

156-
tray.setContextMenu(menu)
157-
tray.setIgnoreDoubleClickEvents(true)
158-
tray.setToolTip('Another Mihomo GUI.')
159-
tray.setTitle('Mihomo Party')
160-
tray.addListener('click', () => {
163+
tray?.setContextMenu(menu)
164+
tray?.setIgnoreDoubleClickEvents(true)
165+
tray?.setToolTip('Another Mihomo GUI.')
166+
tray?.setTitle('Mihomo Party')
167+
tray?.addListener('click', () => {
161168
if (mainWindow?.isVisible()) {
162169
mainWindow?.close()
163170
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.