Skip to content

Commit 2fac257

Browse files
authored
refactor: tray icons (#1633)
1 parent d6e2d62 commit 2fac257

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

src/main/icons.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { TrayIcons } from './icons';
2+
3+
describe('main/icons.ts', () => {
4+
it('should return icon images', () => {
5+
expect(TrayIcons.active).toContain('assets/images/tray-active.png');
6+
7+
expect(TrayIcons.activeUpdateIcon).toContain(
8+
'assets/images/tray-active-update.png',
9+
);
10+
11+
expect(TrayIcons.idle).toContain('assets/images/tray-idleTemplate.png');
12+
13+
expect(TrayIcons.idleUpdateIcon).toContain(
14+
'assets/images/tray-idle-update.png',
15+
);
16+
17+
expect(TrayIcons.idleAlternate).toContain(
18+
'assets/images/tray-idle-white.png',
19+
);
20+
21+
expect(TrayIcons.idleAlternateUpdateIcon).toContain(
22+
'assets/images/tray-idle-white-update.png',
23+
);
24+
});
25+
});

src/main/icons.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import path from 'node:path';
22

3-
// Tray Icons
4-
export const idleIcon = getIconPath('tray-idleTemplate.png');
5-
export const idleUpdateIcon = getIconPath('tray-idle-update.png');
6-
export const idleAlternateIcon = getIconPath('tray-idle-white.png');
7-
export const idleAlternateUpdateIcon = getIconPath(
8-
'tray-idle-white-update.png',
9-
);
10-
export const activeIcon = getIconPath('tray-active.png');
11-
export const activeUpdateIcon = getIconPath('tray-active-update.png');
3+
export const TrayIcons = {
4+
active: getIconPath('tray-active.png'),
5+
activeUpdateIcon: getIconPath('tray-active-update.png'),
6+
idle: getIconPath('tray-idleTemplate.png'),
7+
idleUpdateIcon: getIconPath('tray-idle-update.png'),
8+
idleAlternate: getIconPath('tray-idle-white.png'),
9+
idleAlternateUpdateIcon: getIconPath('tray-idle-white-update.png'),
10+
};
1211

1312
function getIconPath(iconName: string) {
1413
return path.join(__dirname, '..', 'assets', 'images', iconName);

src/main/main.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import { app, globalShortcut, ipcMain as ipc, nativeTheme } from 'electron';
22
import log from 'electron-log';
33
import { menubar } from 'menubar';
4+
45
import { onFirstRunMaybe } from './first-run';
5-
import {
6-
activeIcon,
7-
activeUpdateIcon,
8-
idleAlternateIcon,
9-
idleAlternateUpdateIcon,
10-
idleIcon,
11-
idleUpdateIcon,
12-
} from './icons';
6+
import { TrayIcons } from './icons';
137
import MenuBuilder from './menu';
148
import Updater from './updater';
159

@@ -30,7 +24,7 @@ const browserWindowOpts = {
3024
};
3125

3226
const mb = menubar({
33-
icon: idleIcon,
27+
icon: TrayIcons.idle,
3428
index: `file://${__dirname}/index.html`,
3529
browserWindow: browserWindowOpts,
3630
preloadWindow: true,
@@ -115,8 +109,8 @@ app.whenReady().then(async () => {
115109
if (!mb.tray.isDestroyed()) {
116110
mb.tray.setImage(
117111
menuBuilder.isUpdateAvailableMenuVisible()
118-
? activeUpdateIcon
119-
: activeIcon,
112+
? TrayIcons.activeUpdateIcon
113+
: TrayIcons.active,
120114
);
121115
}
122116
});
@@ -126,14 +120,14 @@ app.whenReady().then(async () => {
126120
if (shouldUseAlternateIdleIcon) {
127121
mb.tray.setImage(
128122
menuBuilder.isUpdateAvailableMenuVisible()
129-
? idleAlternateUpdateIcon
130-
: idleAlternateIcon,
123+
? TrayIcons.idleAlternateUpdateIcon
124+
: TrayIcons.idleAlternate,
131125
);
132126
} else {
133127
mb.tray.setImage(
134128
menuBuilder.isUpdateAvailableMenuVisible()
135-
? idleUpdateIcon
136-
: idleIcon,
129+
? TrayIcons.idleUpdateIcon
130+
: TrayIcons.idle,
137131
);
138132
}
139133
}

0 commit comments

Comments
 (0)