diff --git a/electron/indicator.ts b/electron/indicator.ts index b64a744f26d..c6f82f21cb9 100644 --- a/electron/indicator.ts +++ b/electron/indicator.ts @@ -7,7 +7,6 @@ import { getWin } from './main-window'; let tray; let isIndicatorRunning = false; let DIR: string; -let isTrayShowCurrentTask: boolean; const isGnomeShellExtensionRunning = false; @@ -58,55 +57,54 @@ function initAppListeners(app) { } function initListeners() { + ipcMain.on(IPC.SET_PROGRESS_BAR, (ev, {progress}) => { + const suf = nativeTheme.shouldUseDarkColors + ? '-d' + : '-l'; + if (typeof progress === 'number' && progress > 0 && isFinite(progress)) { + const f = Math.min(Math.round(progress * 15), 15); + const t = DIR + `running-anim${suf}/${f || 0}.png`; + tray.setImage(t); + } else { + const t = DIR + `running${suf}.png`; + tray.setImage(t); + } + }); + ipcMain.on(IPC.CURRENT_TASK_UPDATED, (ev, params) => { const currentTask = params.current; - // const lastActiveTaskTask = params.lastActiveTask; - const mainWin = getWin(); getSettings(mainWin, (settings) => { - isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask; - }); + const isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask; - let msg = ''; - if (isTrayShowCurrentTask && currentTask) { - msg = createIndicatorStr(currentTask); - } + let msg = ''; + if (isTrayShowCurrentTask && currentTask) { + msg = createIndicatorStr(currentTask); + } - if (tray) { - // tray handling - if (currentTask && currentTask.title) { - const suf = nativeTheme.shouldUseDarkColors - ? '-d' - : '-l'; - tray.setTitle(msg); - if (typeof currentTask.timeEstimate === 'number' && currentTask.timeEstimate > 0) { - const progress = currentTask.timeSpent / currentTask.timeEstimate; - const f = Math.min(Math.round(progress * 15), 15); - const t = DIR + `running-anim${suf}/${f || 0}.png`; - tray.setImage(t); + if (tray) { + // tray handling + if (currentTask && currentTask.title) { + tray.setTitle(msg); } else { - const t = DIR + `running${suf}.png`; - tray.setImage(t); + tray.setTitle(''); + const suf = nativeTheme.shouldUseDarkColors + ? '-d.png' + : '-l.png'; + tray.setImage(DIR + `stopped${suf}`); } - } else { - tray.setTitle(''); - const suf = nativeTheme.shouldUseDarkColors - ? '-d.png' - : '-l.png'; - tray.setImage(DIR + `stopped${suf}`); } - } + }); }); - ipcMain.on(IPC.POMODORO_UPDATE, (ev, params) => { - // const isOnBreak = params.isOnBreak; - // const currentSessionTime = params.currentSessionTime; - // const currentSessionInitialTime = params.currentSessionInitialTime; - - // if (isGnomeShellExtInstalled) { - // dbus.updatePomodoro(isOnBreak, currentSessionTime, currentSessionInitialTime); - // } - }); + // ipcMain.on(IPC.POMODORO_UPDATE, (ev, params) => { + // const isOnBreak = params.isOnBreak; + // const currentSessionTime = params.currentSessionTime; + // const currentSessionInitialTime = params.currentSessionInitialTime; + // if (isGnomeShellExtInstalled) { + // dbus.updatePomodoro(isOnBreak, currentSessionTime, currentSessionInitialTime); + // } + // }); } function createIndicatorStr(task) {