Show notfications after app is ready

This commit is contained in:
Tom Panning 2020-11-06 12:47:09 -05:00 committed by Benjamin Staneck
parent 83836f42b8
commit a8803eca6d
2 changed files with 13 additions and 3 deletions

View file

@ -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});
}
};

View file

@ -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();
};