From f32b92271757b655a1bbad2e5dbc696b58bfab86 Mon Sep 17 00:00:00 2001 From: Philip Wintersteiner Date: Sat, 2 Nov 2024 11:56:38 +0100 Subject: [PATCH] Fix the time displayed in the tray icon - Take the break notification time into account - Move the timeToNextBreak logic into a separate getter that is used everywhere this time is displayed - Use rounded time for the tray icon (to align with the tooltip) --- CHANGELOG.md | 1 + app/breaksPlanner.js | 17 +++++++++++++++++ app/main.js | 2 +- app/utils/appIcon.js | 2 +- app/utils/statusMessages.js | 31 +++++-------------------------- app/utils/utils.js | 4 +--- test/utils.js | 11 +++++++---- 7 files changed, 33 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82704adf8..24bca00b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - error when end break shortcut is not set +- time in tray shows the correct number (and matches the tooltip value) ### Changed - improved break window loading diff --git a/app/breaksPlanner.js b/app/breaksPlanner.js index 5aba77a24..2514cdae0 100644 --- a/app/breaksPlanner.js +++ b/app/breaksPlanner.js @@ -270,6 +270,23 @@ class BreaksPlanner extends EventEmitter { } } } + + get timeToNextBreak () { + if (this.scheduler.reference === 'startMicrobreak' || this.scheduler.reference === 'startBreak') { + return this.scheduler.timeLeft + } + if (this.scheduler.reference === 'startBreakNotification') { + return this.scheduler.timeLeft + (this.settings.get('breakNotification') + ? this.settings.get('breakNotificationInterval') + : 0) + } + if (this.scheduler.reference === 'startMicrobreakNotification') { + return this.scheduler.timeLeft + (this.settings.get('microbreakNotification') + ? this.settings.get('microbreakNotificationInterval') + : 0) + } + return null + } } module.exports = BreaksPlanner diff --git a/app/main.js b/app/main.js index 11ea31d82..5ac4c41cd 100644 --- a/app/main.js +++ b/app/main.js @@ -479,7 +479,7 @@ function trayIconPath () { darkMode: nativeTheme.shouldUseDarkColors, platform: process.platform, timeToBreakInTray: settings.get('timeToBreakInTray'), - timeToBreak: Utils.minutesRemaining(breakPlanner.scheduler.timeLeft), + timeToBreak: Utils.minutesRemaining(breakPlanner.timeToNextBreak), reference: breakPlanner.scheduler.reference } const trayIconFileName = new AppIcon(params).trayIconFileName diff --git a/app/utils/appIcon.js b/app/utils/appIcon.js index fd2d41321..1918ca157 100644 --- a/app/utils/appIcon.js +++ b/app/utils/appIcon.js @@ -26,7 +26,7 @@ class AppIcon { const invertedMonochromeString = this.inverted ? 'Inverted' : '' const darkModeString = this.darkMode ? 'Dark' : '' const timeToBreakInTrayString = (this.paused || this.reference === 'finishMicrobreak' || - this.reference === 'finishBreak' || !this.timeToBreakInTray) + this.reference === 'finishBreak' || !this.timeToBreakInTray || !Number.isInteger(this.timeToBreak)) ? '' : `Number${this.timeToBreak}` diff --git a/app/utils/statusMessages.js b/app/utils/statusMessages.js index 587840bb0..31e32d6f2 100644 --- a/app/utils/statusMessages.js +++ b/app/utils/statusMessages.js @@ -7,6 +7,7 @@ class StatusMessages { this.doNotDisturb = breakPlanner.dndManager.isOnDnd this.appExclusionPause = breakPlanner.appExclusionsManager.isSchedulerCleared this.timeLeft = breakPlanner.scheduler.timeLeft + this.timeToNextBreak = breakPlanner.timeToNextBreak this.isPaused = breakPlanner.isPaused this.breakNumber = breakPlanner.breakNumber this.settings = settings @@ -43,38 +44,16 @@ class StatusMessages { const breakInterval = this.settings.get('breakInterval') + 1 const breakNumber = this.breakNumber % breakInterval - const breakNotificationInterval = this.settings.get('breakNotification') - ? this.settings.get('breakNotificationInterval') - : 0 - const microbreakNotificationInterval = this.settings.get('microbreakNotification') - ? this.settings.get('microbreakNotificationInterval') - : 0 - if (this.reference === 'startBreak') { + if (this.reference === 'startBreak' || this.reference === 'startBreakNotification') { message += i18next.t('statusMessages.nextLongBreak') + ' ' + - Utils.formatTimeIn(this.timeLeft, this.settings.get('language')) + Utils.formatTimeIn(this.timeToNextBreak, this.settings.get('language')) return message } - if (this.reference === 'startMicrobreak') { + if (this.reference === 'startMicrobreak' || this.reference === 'startMicrobreakNotification') { message += i18next.t('statusMessages.nextMiniBreak') + ' ' + - Utils.formatTimeIn(this.timeLeft, this.settings.get('language')) - if (this.settings.get('break')) { - message += '\n' + i18next.t('statusMessages.nextLongBreak') + ' ' + - i18next.t('statusMessages.afterMiniBreak', { count: breakInterval - breakNumber }) - } - return message - } - - if (this.reference === 'startBreakNotification') { - message += i18next.t('statusMessages.nextLongBreak') + ' ' + - Utils.formatTimeIn(this.timeLeft + breakNotificationInterval, this.settings.get('language')) - return message - } - - if (this.reference === 'startMicrobreakNotification') { - message += i18next.t('statusMessages.nextMiniBreak') + ' ' + - Utils.formatTimeIn(this.timeLeft + microbreakNotificationInterval, this.settings.get('language')) + Utils.formatTimeIn(this.timeToNextBreak, this.settings.get('language')) if (this.settings.get('break')) { message += '\n' + i18next.t('statusMessages.nextLongBreak') + ' ' + i18next.t('statusMessages.afterMiniBreak', { count: breakInterval - breakNumber }) diff --git a/app/utils/utils.js b/app/utils/utils.js index 765a6de5c..7f0f81e8a 100644 --- a/app/utils/utils.js +++ b/app/utils/utils.js @@ -37,9 +37,7 @@ function formatKeyboardShortcut (keyboardShortcut) { } function minutesRemaining (milliseconds) { - const seconds = Math.ceil(milliseconds / 1000.0) - const minutes = Math.ceil(seconds / 60.0) - return minutes + return Math.round(milliseconds / 60000.0) } function shouldShowNotificationTitle (platform, systemVersion) { diff --git a/test/utils.js b/test/utils.js index 7d06bd670..fc35c4eae 100644 --- a/test/utils.js +++ b/test/utils.js @@ -118,13 +118,16 @@ describe('canSkip and canPostpone', () => { describe('minutesRemaining', () => { it('one minute remaining', () => { - minutesRemaining(60000).should.equal(1) + minutesRemaining(60 * 1000).should.equal(1) }) - it('less then one minute remaining', () => { - minutesRemaining(1).should.equal(1) + it('twenty seconds remaining', () => { + minutesRemaining(20 * 1000).should.equal(0) + }) + it('forty seconds remaining', () => { + minutesRemaining(40 * 1000).should.equal(1) }) it('ten minutes remaining', () => { - minutesRemaining(600000).should.equal(10) + minutesRemaining(600 * 1000).should.equal(10) }) })