feat(tray): add Windows tray icon support and update icon selection logic
This commit is contained in:
@@ -2,7 +2,7 @@ import { nativeImage } from 'electron/common'
|
||||
import type { Tray as ElectronTray } from 'electron/main'
|
||||
import { Menu, Tray, app } from 'electron/main'
|
||||
|
||||
import { TRAY_DANGER_ICON_BASE64, TRAY_ICON_BASE64 } from './brand-icons'
|
||||
import { TRAY_DANGER_ICON_BASE64, TRAY_ICON_BASE64, TRAY_WINDOWS_ICON_BASE64 } from './brand-icons'
|
||||
|
||||
type TrayIconImage = ReturnType<typeof nativeImage.createFromBuffer>
|
||||
|
||||
@@ -32,12 +32,15 @@ function createTrayIcon(tone: 'normal' | 'danger'): TrayIconImage {
|
||||
return normalTrayIcon
|
||||
}
|
||||
|
||||
const buffer = Buffer.from(TRAY_ICON_BASE64, 'base64')
|
||||
const buffer = Buffer.from(
|
||||
process.platform === 'win32' ? TRAY_WINDOWS_ICON_BASE64 : TRAY_ICON_BASE64,
|
||||
'base64',
|
||||
)
|
||||
const icon = nativeImage.createFromBuffer(buffer, { scaleFactor: TRAY_ICON_SCALE_FACTOR })
|
||||
if (icon.isEmpty()) {
|
||||
return nativeImage.createEmpty()
|
||||
}
|
||||
icon.setTemplateImage(true)
|
||||
icon.setTemplateImage(process.platform === 'darwin')
|
||||
normalTrayIcon = icon
|
||||
return icon
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user