Add option for native notifications

This commit is contained in:
KorbsStudio 2023-02-14 14:46:39 -05:00
parent b294184518
commit a579bf48f4
No known key found for this signature in database

View file

@ -1,5 +1,5 @@
// ElectronJS
const {app, BrowserWindow, Menu} = require('electron')
const {app, BrowserWindow, Menu, Notification} = require('electron')
// Dependenies by Korbs Studio
const glasstron = require('glasstron-clarity')
@ -60,11 +60,16 @@ function createWindow () {
setTimeout(() => {
Pushy.setNotificationListener((data) => {
if(process.env.NotificationType === 'Native') {
new Notification({ title: data.title, body: data.message }).show()
}
else if(process.env.NotificationType === 'Custom') {
mainWindow.webContents.executeJavaScript(`
document.querySelector("body > div > div.sidebar > div.sidebar-bottom").insertAdjacentHTML("afterBegin",'<li class="notification"><img class="notification-image" src="${data.image}"><i class="${data.icon}"></i><p class="notification-title">${data.title}</p><p class="notification-message">${data.message}</p><div class="notification-actions"><button id="primary" class="notification-action" onclick="shell.openExternal(${data.action})">Open</button><button id="secondary" class="notification-action">Dismiss</button></div></li>')
`)
}
})
}, 10000)
}, 10000) // If this is triggered too soon, the notifications won't work.
if (Pushy.isRegistered()) {Pushy.subscribe('AppName').then(() => {}).catch((error) => {console.error(error)})}