Add option for native notifications
This commit is contained in:
parent
b294184518
commit
a579bf48f4
1 changed files with 12 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
// ElectronJS
|
// ElectronJS
|
||||||
const {app, BrowserWindow, Menu} = require('electron')
|
const {app, BrowserWindow, Menu, Notification} = require('electron')
|
||||||
|
|
||||||
// Dependenies by Korbs Studio
|
// Dependenies by Korbs Studio
|
||||||
const glasstron = require('glasstron-clarity')
|
const glasstron = require('glasstron-clarity')
|
||||||
|
@ -22,9 +22,9 @@ log.transports.console.format = '\x1b[34m[electron]:\x1b[37m'
|
||||||
console.log = log.log
|
console.log = log.log
|
||||||
|
|
||||||
// Use the correct icon depending on the operating system
|
// Use the correct icon depending on the operating system
|
||||||
if /* If macOS */ (process.platform == 'darwin') {global.AppIcon = 'public/images/icons/app/macOS.icns' }
|
if /* If macOS */ (process.platform == 'darwin') {global.AppIcon = 'public/images/icons/app/macOS.icns' }
|
||||||
else if /* If Windows */ (process.platform == 'win32') {global.AppIcon = 'public/images/icons/app/Windows.png' }
|
else if /* If Windows */ (process.platform == 'win32') {global.AppIcon = 'public/images/icons/app/Windows.png' }
|
||||||
else /* If Linux */ {global.AppIcon = 'public/images/icons/app/Linux.png' }
|
else /* If Linux */ {global.AppIcon = 'public/images/icons/app/Linux.png' }
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow () {
|
||||||
mainWindow = new glasstron.BrowserWindow({
|
mainWindow = new glasstron.BrowserWindow({
|
||||||
|
@ -60,11 +60,16 @@ function createWindow () {
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Pushy.setNotificationListener((data) => {
|
Pushy.setNotificationListener((data) => {
|
||||||
mainWindow.webContents.executeJavaScript(`
|
if(process.env.NotificationType === 'Native') {
|
||||||
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>')
|
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)})}
|
if (Pushy.isRegistered()) {Pushy.subscribe('AppName').then(() => {}).catch((error) => {console.error(error)})}
|
||||||
|
|
||||||
|
|
Reference in a new issue