Skip to content

Commit

Permalink
Make most of the notifications silent.
Browse files Browse the repository at this point in the history
  • Loading branch information
MayGo committed Feb 8, 2020
1 parent 689cb83 commit d177929
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
20 changes: 11 additions & 9 deletions electron/app/app-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions electron/app/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 11 additions & 10 deletions electron/app/task-analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d177929

Please sign in to comment.