hyper/app/notify.ts

21 lines
590 B
TypeScript
Raw Normal View History

2020-11-06 08:47:09 -09:00
import {app, Notification} from 'electron';
2020-03-04 02:31:19 -09:00
import {icon} from './config/paths';
2016-07-07 12:48:43 -08:00
2020-06-19 04:51:34 -08:00
export default function notify(title: string, body = '', details: {error?: any} = {}) {
2020-01-02 05:44:11 -09:00
console.log(`[Notification] ${title}: ${body}`);
if (details.error) {
console.error(details.error);
}
2020-11-06 08:47:09 -09:00
if (app.isReady()) {
_createNotification(title, body);
} else {
app.on('ready', () => {
_createNotification(title, body);
});
}
2020-01-02 05:44:11 -09:00
}
2020-11-06 08:47:09 -09:00
const _createNotification = (title: string, body: string) => {
new Notification({title, body, ...(process.platform === 'linux' && {icon})}).show();
};