From 6a65face46759b98cf1db12679c2516a0cebdbb5 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 11 Nov 2024 08:26:37 -0500 Subject: [PATCH] refactor: tray icons Signed-off-by: Adam Setch --- src/main/icons.test.ts | 25 +++++++++++++++++++++++++ src/main/icons.ts | 17 ++++++++--------- src/main/main.ts | 24 +++++++++--------------- 3 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 src/main/icons.test.ts diff --git a/src/main/icons.test.ts b/src/main/icons.test.ts new file mode 100644 index 000000000..58222cb2a --- /dev/null +++ b/src/main/icons.test.ts @@ -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', + ); + }); +}); diff --git a/src/main/icons.ts b/src/main/icons.ts index 05ff9bb59..fd86d8b7e 100644 --- a/src/main/icons.ts +++ b/src/main/icons.ts @@ -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); diff --git a/src/main/main.ts b/src/main/main.ts index 02df655ba..88fcabeac 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -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'; @@ -30,7 +24,7 @@ const browserWindowOpts = { }; const mb = menubar({ - icon: idleIcon, + icon: TrayIcons.idle, index: `file://${__dirname}/index.html`, browserWindow: browserWindowOpts, preloadWindow: true, @@ -115,8 +109,8 @@ app.whenReady().then(async () => { if (!mb.tray.isDestroyed()) { mb.tray.setImage( menuBuilder.isUpdateAvailableMenuVisible() - ? activeUpdateIcon - : activeIcon, + ? TrayIcons.activeUpdateIcon + : TrayIcons.active, ); } }); @@ -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, ); } }