Last active
February 26, 2022 20:54
-
-
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
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 lang="en"> | |
<head> | |
<title>Document</title> | |
</head> | |
<body> | |
<h1>Notifications Example</h1> | |
</p> | |
<button>Send Notification</button> | |
<script> | |
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
// 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() | |
} |
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
// Empty |
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 { ipcRenderer } = require('electron') | |
document.querySelector('button').onclick = () => | |
ipcRenderer.send('notification') | |
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
/* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment