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 34 35
| const {app, BrowserWindow, Notification, ipcMain} = require('electron')
let win app.on('ready', () => { win = new BrowserWindow({ width: 300, height: 300, webPreferences: { nodeIntegration: true } }) win.loadFile('./index.html') handleIPC() })
function handleIPC(){ ipcMain.handle('work-notification', async function () { let res = await new Promise((resolve, reject) => { let notification = new Notification({ title: '任务结束', body: '是否开始休息', actions: [{text: '开始休息', type: 'button'}], closeButtonText: '继续工作' }) notification.show() notification.on('action', () => { resolve('rest') }) notification.on('close', () => { resolve('work') }) }) return res }) }
|