Created
October 10, 2019 20:03
-
-
Save harryi3t/2688bf4bfc27ce02f5d74224828eb928 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<div> | |
<h3>Notification with image</h3> | |
<i>Supports: Win 7+, macOS, Linux (that supports libnotify)<span>|</span> Process: Renderer</i> | |
<div> | |
<div> | |
<button id="advanced-noti">View demo</button> | |
</div> | |
<p>This demo demonstrates a advanced notification. Both text and image.</p> | |
</div> | |
</div> | |
<script> | |
// You can also require other files to run in this process | |
require('./renderer.js') | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { BrowserWindow, app } = require('electron') | |
let mainWindow = null | |
function createWindow () { | |
const windowOptions = { | |
width: 600, | |
height: 300, | |
title: 'Advanced Notification', | |
webPreferences: { | |
nodeIntegration: true | |
} | |
} | |
mainWindow = new BrowserWindow(windowOptions) | |
mainWindow.loadFile('index.html') | |
mainWindow.on('closed', () => { | |
mainWindow = null | |
}) | |
} | |
app.on('ready', () => { | |
createWindow() | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const notification = { | |
title: 'Notification with image', | |
body: 'Short message plus a custom image', | |
icon: 'https://raw.githubusercontent.com/electron/electron-api-demos/v2.0.2/assets/img/programming.png' | |
} | |
const notificationButton = document.getElementById('advanced-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