Skip to content

Instantly share code, notes, and snippets.

@Araxeus
Last active February 26, 2022 20:54
Show Gist options
  • Save Araxeus/a1c1ac4c057370540be18e0b5aeefb89 to your computer and use it in GitHub Desktop.
Save Araxeus/a1c1ac4c057370540be18e0b5aeefb89 to your computer and use it in GitHub Desktop.
Electron 12^ notification bug - gist for https://github.com/electron/electron/issues/29557
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<h1>Notifications Example</h1>
</p>
<button>Send Notification</button>
<script>
require('./renderer.js')
</script>
</body>
</html>
// Create OS desktop notifications
//
// For more info, see:
// https://electronjs.org/docs/api/notification
// https://electronjs.org/docs/tutorial/notifications
const { app, BrowserWindow, Notification, ipcMain } = require('electron')
app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
height: 600,
width: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
mainWindow.loadFile('index.html')
ipcMain.on('notification', showNotification)
})
let oldNotification;
function showNotification() {
oldNotification?.close();
oldNotification = new Notification({
title: 'Notification Test',
subtitle: 'Teesting win10 notification center',
body: 'Random Number = '+Math.random().toFixed(3),
})
oldNotification.on('show', () => console.log('Notification shown'))
oldNotification.on('click', () => console.log('Notification clicked'))
oldNotification.on('close', () => console.log('Notification closed'))
oldNotification.show()
}
const { ipcRenderer } = require('electron')
document.querySelector('button').onclick = () =>
ipcRenderer.send('notification')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment