From d177929efb86bdcd1ce6d7623decb716896285a7 Mon Sep 17 00:00:00 2001 From: d Date: Sat, 8 Feb 2020 19:22:12 +0200 Subject: [PATCH] Make most of the notifications silent. --- electron/app/app-updater.ts | 20 +++++++++++--------- electron/app/notification.ts | 6 +++--- electron/app/task-analyser.ts | 21 +++++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/electron/app/app-updater.ts b/electron/app/app-updater.ts index 63b832fa..f5ab0605 100644 --- a/electron/app/app-updater.ts +++ b/electron/app/app-updater.ts @@ -24,14 +24,15 @@ export default class AppUpdater { autoUpdater.logger = logger; autoUpdater.on('download-progress', progressInfo => { - showNotification( - `Downloaded: ${Math.round(progressInfo.percent)}% `, - 'Tockler update downloading', - ); + showNotification({ + body: `Downloaded: ${Math.round(progressInfo.percent)}% `, + title: 'Tockler update downloading', + silent: true, + }); }); autoUpdater.on('error', err => { - showNotification(err ? err.stack || err : 'unknown', 'Tockler error'); + showNotification({ title: 'Tockler error', body: err ? err.stack || err : 'unknown' }); }); AppUpdater.checkIfEnabled(); @@ -53,14 +54,15 @@ export default class AppUpdater { static updateNotAvailable = updateInfo => { const currentVersionString = app.getVersion(); - showNotification( - `Up to date! Current ${currentVersionString} (latest: ${updateInfo.version})`, - ); + showNotification({ + body: `Up to date! Current ${currentVersionString} (latest: ${updateInfo.version})`, + silent: true, + }); }; static async checkForUpdates() { logger.info('Checking for updates'); - showNotification(`Checking for updates...`); + showNotification({ body: `Checking for updates...`, silent: true }); autoUpdater.on('update-not-available', AppUpdater.updateNotAvailable); const result: UpdateCheckResult = await autoUpdater.checkForUpdatesAndNotify(); diff --git a/electron/app/notification.ts b/electron/app/notification.ts index 1a6a0005..be20621c 100644 --- a/electron/app/notification.ts +++ b/electron/app/notification.ts @@ -3,15 +3,15 @@ import { logManager } from './log-manager'; import config from './config'; const isDesktopNotificationSupported = Notification.isSupported(); -const logger = logManager.getLogger('TrackItemService'); +const logger = logManager.getLogger('Notification'); -export function showNotification(body, title = 'Tockler', onClick = null) { +export function showNotification({ body, title = 'Tockler', onClick = null, silent = false }) { if (isDesktopNotificationSupported) { logger.info('Showing notification:', body, title); const notification = new Notification({ title, body, - silent: false, + silent, icon: config.iconBig, }); if (onClick) { diff --git a/electron/app/task-analyser.ts b/electron/app/task-analyser.ts index 7e2a1616..569c4cdb 100644 --- a/electron/app/task-analyser.ts +++ b/electron/app/task-analyser.ts @@ -41,11 +41,12 @@ export class TaskAnalyser { appEmitter.emit('start-new-log-item', taskAnalyser.newItem); - showNotification( - `Task "${taskAnalyser.newItem.title}" running.`, - 'New task created!', - this.onNotificationClick, - ); + showNotification({ + title: 'New task created!', + body: `Task "${taskAnalyser.newItem.title}" running.`, + onClick: this.onNotificationClick, + silent: true, + }); taskAnalyser.newItem = null; } @@ -75,11 +76,11 @@ export class TaskAnalyser { beginDate: new Date(), endDate: new Date(), }; - showNotification( - `Click to create: "${app}"`, - 'Create new task?', - this.onNotificationClick, - ); + showNotification({ + body: `Click to create: "${app}"`, + title: 'Create new task?', + onClick: this.onNotificationClick, + }); } } catch (e) { this.logger.error('analyseAndNotify:', e);