From a8803eca6d64bd5ff31dfb3b0cf7eb57277b2443 Mon Sep 17 00:00:00 2001 From: Tom Panning Date: Fri, 6 Nov 2020 12:47:09 -0500 Subject: [PATCH] Show notfications after app is ready --- app/config/init.ts | 2 +- app/notify.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/config/init.ts b/app/config/init.ts index db28f151..1a80fcf7 100644 --- a/app/config/init.ts +++ b/app/config/init.ts @@ -16,7 +16,7 @@ const _syntaxValidation = (cfg: string) => { try { return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true}); } catch (err) { - notify('Error loading config:', `${err.name}, see DevTools for more info`, {error: err}); + notify(`Error loading config: ${err.name}`, `${err}`, {error: err}); } }; diff --git a/app/notify.ts b/app/notify.ts index 0d1eaa52..a31f0305 100644 --- a/app/notify.ts +++ b/app/notify.ts @@ -1,4 +1,4 @@ -import {Notification} from 'electron'; +import {app, Notification} from 'electron'; import {icon} from './config/paths'; export default function notify(title: string, body = '', details: {error?: any} = {}) { @@ -6,5 +6,15 @@ export default function notify(title: string, body = '', details: {error?: any} if (details.error) { console.error(details.error); } - new Notification({title, body, ...(process.platform === 'linux' && {icon})}).show(); + if (app.isReady()) { + _createNotification(title, body); + } else { + app.on('ready', () => { + _createNotification(title, body); + }); + } } + +const _createNotification = (title: string, body: string) => { + new Notification({title, body, ...(process.platform === 'linux' && {icon})}).show(); +};