Skip to content

Commit

Permalink
Sending an Electron notification
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Aug 31, 2017
1 parent 73d3f71 commit 128ddd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow, ipcMain, Notification } = require('electron')

let mainWindow

Expand All @@ -17,4 +17,14 @@ app.on('ready', () => {
})

mainWindow.loadURL(`file://${__dirname}/../renderer/index.html`)

ipcMain.on('send-notification', (event, options) => {
const notification = new Notification(options)

notification.on('click', () => {
mainWindow.send('clicked-notification')
})

notification.show()
})
})
14 changes: 8 additions & 6 deletions src/renderer/renderer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const { ipcRenderer } = require('electron')
const loadMonaco = require('monaco-loader')

function sendNotification (editor) {
const notification = new window.Notification('Hello!', {
body: 'Hello from your notification system'
function sendNotificationFromMain (editor) {
// We're telling the main process to send the notification
ipcRenderer.send('send-notification', {
body: 'Hello from the main process!'
})

notification.onclick = () => {
ipcRenderer.once('clicked-notification', () => {
editor.setValue('Notification clicked!')
}
})
}

loadMonaco().then((monaco) => {
Expand All @@ -28,6 +30,6 @@ loadMonaco().then((monaco) => {
contextMenuOrder: 1,
precondition: null,
keybindingContext: null,
run: (editor) => sendNotification(editor)
run: (editor) => sendNotificationFromMain(editor)
})
})

0 comments on commit 128ddd8

Please sign in to comment.