-
Notifications
You must be signed in to change notification settings - Fork 285
/
Copy pathapp-toast.js
33 lines (31 loc) · 1.14 KB
/
app-toast.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const {Notification, shell, dialog} = require('electron');
const logger = require('logger2x').createLogger(`${require('os').homedir()}/BlogHelper/toast.log`);
// 异步弹出提示消息
exports.toast = function toast(config) {
logger.log(JSON.stringify(config));
if (Notification.isSupported()) {
new Notification(config).show()
} else {
const title = config.title || '';
const body = config.body || '';
dialog.showMessageBox({message: title + '\n' + body}).then()
}
};
/**
* 文章发布提示消息
*/
exports.openPublishUrl = (url, title) => {
if (Notification.isSupported()) {
const notification = new Notification({title: '发布成功!', subtitle: title, body: '点击可在浏览器打开'});
notification.addListener('click', event => {
shell.openExternal(url).then()
});
notification.show()
} else {
const number = dialog.showMessageBoxSync(
{message: `发布成功!是否在浏览器打开:${title}`, buttons: ['取消', '打开']});
if (number === 1) {
shell.openExternal(url).then()
}
}
};