Skip to content

Commit

Permalink
Fix tray icon bug on MacOS (staniel359#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
staniel359 committed Dec 30, 2021
1 parent 8ea96f6 commit fd848c7
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
BrowserWindow,
ipcMain,
Menu,
nativeImage,
session,
Tray
} = require('electron')
Expand All @@ -23,28 +24,20 @@ const isDevelopment =
const isMac =
process.platform === 'darwin'

const getIconPath = () => {
const publicPath =
isDevelopment ? 'public' : ''
const publicPath =
isDevelopment ? 'public' : ''

const osIcons = {
win32: 'icon.ico',
darwin: 'icon.icns',
linux: 'icon.png'
}

const iconName = osIcons[
process.platform
]

return path.join(
const iconPath =
path.join(
__dirname,
publicPath,
iconName
'icon.png'
)
}

const iconPath = getIconPath()
const icon =
nativeImage.createFromPath(
iconPath
)

const getBaseUrl = () => {
if (isDevelopment) {
Expand Down Expand Up @@ -116,7 +109,7 @@ const createWindow = () => {
mainWindow = new BrowserWindow({
width,
height,
icon: iconPath,
icon: icon,
autoHideMenuBar: true,
show: false,
webPreferences: {
Expand Down Expand Up @@ -161,7 +154,7 @@ const hide = () => {
}

const createTray = () => {
tray = new Tray(iconPath)
tray = new Tray(icon)

setTrayMenu()

Expand Down

0 comments on commit fd848c7

Please sign in to comment.