Skip to content

Commit

Permalink
refactor: tray icons (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy authored Nov 11, 2024
1 parent d6e2d62 commit 2fac257
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
25 changes: 25 additions & 0 deletions src/main/icons.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { TrayIcons } from './icons';

describe('main/icons.ts', () => {
it('should return icon images', () => {
expect(TrayIcons.active).toContain('assets/images/tray-active.png');

expect(TrayIcons.activeUpdateIcon).toContain(
'assets/images/tray-active-update.png',
);

expect(TrayIcons.idle).toContain('assets/images/tray-idleTemplate.png');

expect(TrayIcons.idleUpdateIcon).toContain(
'assets/images/tray-idle-update.png',
);

expect(TrayIcons.idleAlternate).toContain(
'assets/images/tray-idle-white.png',
);

expect(TrayIcons.idleAlternateUpdateIcon).toContain(
'assets/images/tray-idle-white-update.png',
);
});
});
17 changes: 8 additions & 9 deletions src/main/icons.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import path from 'node:path';

// Tray Icons
export const idleIcon = getIconPath('tray-idleTemplate.png');
export const idleUpdateIcon = getIconPath('tray-idle-update.png');
export const idleAlternateIcon = getIconPath('tray-idle-white.png');
export const idleAlternateUpdateIcon = getIconPath(
'tray-idle-white-update.png',
);
export const activeIcon = getIconPath('tray-active.png');
export const activeUpdateIcon = getIconPath('tray-active-update.png');
export const TrayIcons = {
active: getIconPath('tray-active.png'),
activeUpdateIcon: getIconPath('tray-active-update.png'),
idle: getIconPath('tray-idleTemplate.png'),
idleUpdateIcon: getIconPath('tray-idle-update.png'),
idleAlternate: getIconPath('tray-idle-white.png'),
idleAlternateUpdateIcon: getIconPath('tray-idle-white-update.png'),
};

function getIconPath(iconName: string) {
return path.join(__dirname, '..', 'assets', 'images', iconName);
Expand Down
24 changes: 9 additions & 15 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { app, globalShortcut, ipcMain as ipc, nativeTheme } from 'electron';
import log from 'electron-log';
import { menubar } from 'menubar';

import { onFirstRunMaybe } from './first-run';
import {
activeIcon,
activeUpdateIcon,
idleAlternateIcon,
idleAlternateUpdateIcon,
idleIcon,
idleUpdateIcon,
} from './icons';
import { TrayIcons } from './icons';
import MenuBuilder from './menu';
import Updater from './updater';

Expand All @@ -30,7 +24,7 @@ const browserWindowOpts = {
};

const mb = menubar({
icon: idleIcon,
icon: TrayIcons.idle,
index: `file://${__dirname}/index.html`,
browserWindow: browserWindowOpts,
preloadWindow: true,
Expand Down Expand Up @@ -115,8 +109,8 @@ app.whenReady().then(async () => {
if (!mb.tray.isDestroyed()) {
mb.tray.setImage(
menuBuilder.isUpdateAvailableMenuVisible()
? activeUpdateIcon
: activeIcon,
? TrayIcons.activeUpdateIcon
: TrayIcons.active,
);
}
});
Expand All @@ -126,14 +120,14 @@ app.whenReady().then(async () => {
if (shouldUseAlternateIdleIcon) {
mb.tray.setImage(
menuBuilder.isUpdateAvailableMenuVisible()
? idleAlternateUpdateIcon
: idleAlternateIcon,
? TrayIcons.idleAlternateUpdateIcon
: TrayIcons.idleAlternate,
);
} else {
mb.tray.setImage(
menuBuilder.isUpdateAvailableMenuVisible()
? idleUpdateIcon
: idleIcon,
? TrayIcons.idleUpdateIcon
: TrayIcons.idle,
);
}
}
Expand Down

0 comments on commit 2fac257

Please sign in to comment.