diff --git a/__tests__/__main__/notification.js b/__tests__/__main__/notification.js index dd233e37e..000dadc5c 100644 --- a/__tests__/__main__/notification.js +++ b/__tests__/__main__/notification.js @@ -25,8 +25,17 @@ describe('Notifications', function() { process.env.NODE_ENV = 'test'; const notification = createNotification('test'); - expect(notification.body).toBe('test'); - expect(notification.title).toBe('Time to Leave'); + // On Win32 the notification uses a different specification, with toastXml + if (process.platform === 'win32') + { + expect(notification.toastXml).toMatch('test'); + expect(notification.toastXml).toMatch('Time to Leave'); + } + else + { + expect(notification.body).toBe('test'); + expect(notification.title).toBe('Time to Leave'); + } notification.on('show', (event) => { expect(event).toBeTruthy(); @@ -56,8 +65,17 @@ describe('Notifications', function() { process.env.NODE_ENV = 'production'; const notification = createNotification('production'); - expect(notification.body).toBe('production'); - expect(notification.title).toBe('Time to Leave'); + // On Win32 the notification uses a different specification, with toastXml + if (process.platform === 'win32') + { + expect(notification.toastXml).toMatch('production'); + expect(notification.toastXml).toMatch('Time to Leave'); + } + else + { + expect(notification.body).toBe('production'); + expect(notification.title).toBe('Time to Leave'); + } notification.on('show', (event) => { expect(event).toBeTruthy(); diff --git a/js/notification.js b/js/notification.js index dbc64c93f..355874500 100644 --- a/js/notification.js +++ b/js/notification.js @@ -27,33 +27,21 @@ function createNotification(msg, actions = []) let notification; if (process.platform === 'win32') { - // TODO Change to the toastXml to allow buttons when Electron version is at least 12.0.0 - // https://github.com/electron/electron/pull/25401 was released on - // https://github.com/electron/electron/releases/tag/v12.0.0 - // Actions are not supported on electron windows notifications in current version - // XML specification: https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=xml - /* notification = new ElectronNotification({ toastXml: ` - + - - This is the first text - this is the second text + + Time to Leave + ${msg} - ${actions.map(action => ``)} - - ` - }); - */ - notification = new ElectronNotification({ - title: 'Time to Leave', - body: msg, - icon: path.join(appPath, 'assets/ttl.png'), - sound: true + ${actions.map(action => ``)} + + ` }); + } else { @@ -101,8 +89,8 @@ function createLeaveNotification(timeToLeave) const isRepeatingInterval = curTime > timeToLeave && (minutesDiff % notificationInterval === 0); if (curTime === timeToLeave || (isRepeatingInterval && repetitionIsEnabled())) { - - const dismissBtn = {type: 'button', text: getCurrentTranslation('$Notification.dismiss-for-today'), action: 'dismiss', title: 'dismiss'}; + const dismissForTodayText = getCurrentTranslation('$Notification.dismiss-for-today'); + const dismissBtn = {type: 'button', text: dismissForTodayText, action: 'dismiss', title: 'dismiss'}; return createNotification(getCurrentTranslation('$Notification.time-to-leave'), [dismissBtn]) .addListener('action', (response) => {