Skip to content

Commit

Permalink
refactor: icon path fn (#1559)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <adam.setch@outlook.com>
  • Loading branch information
setchy authored Sep 27, 2024
1 parent c3d2617 commit 8797b08
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,14 @@ const { autoUpdater } = require('electron-updater');
const { updateElectronApp } = require('update-electron-app');

log.initialize();

// Tray Icons
const idleIcon = path.resolve(
`${__dirname}/../../assets/images/tray-idleTemplate.png`,
);
const idleUpdateAvailableIcon = path.resolve(
`${__dirname}/../../assets/images/tray-idle-update.png`,
);
const idleAlternateIcon = path.resolve(
`${__dirname}/../../assets/images/tray-idle-white.png`,
);
const idleAlternateUpdateAvailableIcon = path.resolve(
`${__dirname}/../../assets/images/tray-idle-white-update.png`,
);
const activeIcon = path.resolve(
`${__dirname}/../../assets/images/tray-active.png`,
);
const activeUpdateAvailableIcon = path.resolve(
`${__dirname}/../../assets/images/tray-active-update.png`,
);
const idleIcon = getIconPath('tray-idleTemplate.png');
const idleUpdateIcon = getIconPath('tray-idle-update.png');
const idleAlternateIcon = getIconPath('tray-idle-white.png');
const idleAlternateUpdateIcon = getIconPath('tray-idle-white-update.png');
const activeIcon = getIconPath('tray-active.png');
const activeUpdateIcon = getIconPath('tray-active-update.png');

const browserWindowOpts = {
width: 500,
Expand Down Expand Up @@ -192,9 +181,7 @@ app.whenReady().then(async () => {
ipc.on('gitify:icon-active', () => {
if (!mb.tray.isDestroyed()) {
mb.tray.setImage(
updateAvailableMenuItem.visible
? activeUpdateAvailableIcon
: activeIcon,
updateAvailableMenuItem.visible ? activeUpdateIcon : activeIcon,
);
}
});
Expand All @@ -204,12 +191,12 @@ app.whenReady().then(async () => {
if (shouldUseAlternateIdleIcon) {
mb.tray.setImage(
updateAvailableMenuItem.visible
? idleAlternateUpdateAvailableIcon
? idleAlternateUpdateIcon
: idleAlternateIcon,
);
} else {
mb.tray.setImage(
updateAvailableMenuItem.visible ? idleUpdateAvailableIcon : idleIcon,
updateAvailableMenuItem.visible ? idleUpdateIcon : idleIcon,
);
}
}
Expand Down Expand Up @@ -308,3 +295,7 @@ function resetApp() {
mb.app.quit();
}
}

function getIconPath(iconName) {
return path.resolve(__dirname, '../../assets/images', iconName);
}

0 comments on commit 8797b08

Please sign in to comment.