Skip to content

Instantly share code, notes, and snippets.

@harryi3t
Created October 10, 2019 20:02
Show Gist options
  • Save harryi3t/102945f83f559e7944797175d8fd8af4 to your computer and use it in GitHub Desktop.
Save harryi3t/102945f83f559e7944797175d8fd8af4 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<h3>Basic notification</h3>
<i>Supports: Win 7+, macOS, Linux (that supports libnotify)<span>|</span> Process: Renderer</i>
<div>
<div>
<button id="basic-noti">View demo</button>
</div>
<p>This demo demonstrates a basic notification. Text only.</p>
</div>
</div>
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>
const { BrowserWindow, app } = require('electron')
let mainWindow = null
function createWindow () {
const windowOptions = {
width: 600,
height: 300,
title: 'Basic Notification',
webPreferences: {
nodeIntegration: true
}
}
mainWindow = new BrowserWindow(windowOptions)
mainWindow.loadFile('index.html')
mainWindow.on('closed', () => {
mainWindow = null
})
}
app.on('ready', () => {
createWindow()
})
const notification = {
title: 'Basic Notification',
body: 'Short message part'
}
const notificationButton = document.getElementById('basic-noti')
notificationButton.addEventListener('click', () => {
const myNotification = new window.Notification(notification.title, notification)
myNotification.onclick = () => {
console.log('Notification clicked')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment