From e212f9a9bab4f7568a61197beb4b169a8816f59b Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Fri, 28 Nov 2025 18:14:53 +0100 Subject: [PATCH] fix: refactor tray handling to use shared state for task and countdown visibility --- electron/indicator.ts | 61 ++++++++++++++++++---------------------- electron/ipc-handler.ts | 9 +++++- electron/shared-state.ts | 14 +++++++++ 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/electron/indicator.ts b/electron/indicator.ts index a308b73b9..bb249db8a 100644 --- a/electron/indicator.ts +++ b/electron/indicator.ts @@ -1,8 +1,6 @@ import { App, ipcMain, Menu, nativeTheme, Tray } from 'electron'; import { IPC } from './shared-with-frontend/ipc-events.const'; -import { getSettings } from './get-settings'; -import { getWin } from './main-window'; -import { GlobalConfigState } from '../src/app/features/config/global-config.model'; +import { getIsTrayShowCurrentTask, getIsTrayShowCurrentCountdown } from './shared-state'; import { TaskCopy } from '../src/app/features/tasks/task.model'; import { release } from 'os'; import { @@ -112,40 +110,37 @@ function initListeners(): void { currentFocusSessionTime || 0, ); - const mainWin = getWin(); - getSettings(mainWin, (settings: GlobalConfigState) => { - const isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask; - const isTrayShowCurrentCountdown = settings.misc.isTrayShowCurrentCountdown; + const isTrayShowCurrentTask = getIsTrayShowCurrentTask(); + const isTrayShowCurrentCountdown = getIsTrayShowCurrentCountdown(); - const msg = - isTrayShowCurrentTask && currentTask - ? createIndicatorMessage( - currentTask, - isPomodoroEnabled, - currentPomodoroSessionTime, - isTrayShowCurrentCountdown, - ) - : ''; + const msg = + isTrayShowCurrentTask && currentTask + ? createIndicatorMessage( + currentTask, + isPomodoroEnabled, + currentPomodoroSessionTime, + isTrayShowCurrentCountdown, + ) + : ''; - if (tray) { - // tray handling - if (currentTask && currentTask.title) { - tray.setTitle(msg); - if (!IS_MAC) { - // NOTE apparently this has no effect for gnome - tray.setToolTip(msg); - } - } else { - tray.setTitle(''); - if (!IS_MAC) { - // NOTE apparently this has no effect for gnome - tray.setToolTip(msg); - } - const suf = shouldUseDarkColors ? '-d.png' : '-l.png'; - setTrayIcon(tray, DIR + `stopped${suf}`); + if (tray) { + // tray handling + if (currentTask && currentTask.title) { + tray.setTitle(msg); + if (!IS_MAC) { + // NOTE apparently this has no effect for gnome + tray.setToolTip(msg); } + } else { + tray.setTitle(''); + if (!IS_MAC) { + // NOTE apparently this has no effect for gnome + tray.setToolTip(msg); + } + const suf = shouldUseDarkColors ? '-d.png' : '-l.png'; + setTrayIcon(tray, DIR + `stopped${suf}`); } - }); + } }, ); diff --git a/electron/ipc-handler.ts b/electron/ipc-handler.ts index bdee02f17..a7b856909 100644 --- a/electron/ipc-handler.ts +++ b/electron/ipc-handler.ts @@ -20,7 +20,12 @@ import { exec } from 'child_process'; import { getWin } from './main-window'; import { quitApp, showOrFocus } from './various-shared'; import { loadSimpleStoreAll, saveSimpleStore } from './simple-store'; -import { getIsLocked, setIsMinimizeToTray } from './shared-state'; +import { + getIsLocked, + setIsMinimizeToTray, + setIsTrayShowCurrentTask, + setIsTrayShowCurrentCountdown, +} from './shared-state'; import { BACKUP_DIR, BACKUP_DIR_WINSTORE } from './backup'; import { pluginNodeExecutor } from './plugin-node-executor'; import { GlobalConfigState } from '../src/app/features/config/global-config.model'; @@ -65,6 +70,8 @@ export const initIpcInterfaces = (): void => { ipcMain.on(IPC.OPEN_EXTERNAL, (ev, url: string) => shell.openExternal(url)); ipcMain.on(IPC.TRANSFER_SETTINGS_TO_ELECTRON, (ev, cfg: GlobalConfigState) => { setIsMinimizeToTray(cfg.misc.isMinimizeToTray); + setIsTrayShowCurrentTask(cfg.misc.isTrayShowCurrentTask); + setIsTrayShowCurrentCountdown(cfg.misc.isTrayShowCurrentCountdown); }); ipcMain.handle(IPC.SAVE_FILE_DIALOG, async (ev, { filename, data }) => { diff --git a/electron/shared-state.ts b/electron/shared-state.ts index 19f72f4be..12d8427ac 100644 --- a/electron/shared-state.ts +++ b/electron/shared-state.ts @@ -6,6 +6,8 @@ let isQuiting = false; let isLocked = false; let isMinimizeToTray = false; +let isTrayShowCurrentTask = false; +let isTrayShowCurrentCountdown = false; export const getIsQuiting = (): boolean => isQuiting; @@ -24,3 +26,15 @@ export const getIsMinimizeToTray = (): boolean => isMinimizeToTray; export const setIsMinimizeToTray = (value: boolean): void => { isMinimizeToTray = value; }; + +export const getIsTrayShowCurrentTask = (): boolean => isTrayShowCurrentTask; + +export const setIsTrayShowCurrentTask = (value: boolean): void => { + isTrayShowCurrentTask = value; +}; + +export const getIsTrayShowCurrentCountdown = (): boolean => isTrayShowCurrentCountdown; + +export const setIsTrayShowCurrentCountdown = (value: boolean): void => { + isTrayShowCurrentCountdown = value; +};