26 lines
No EOL
1.7 KiB
JavaScript
26 lines
No EOL
1.7 KiB
JavaScript
const {Notification} = require('electron')
|
|
const Pushy = require('pushy-electron')
|
|
let MainWindow = require('./mainwindow')
|
|
module.exports = {
|
|
Pushy: function() {
|
|
// Pushy - Pushy Notification System (PNS)
|
|
mainWindow.webContents.on('did-finish-load', () => {Pushy.listen()})
|
|
Pushy.register({ appId: process.env.PushyAppId }).then((deviceToken) => {}).catch((error) => {console.log('Pushy registration error: ' + error.message)})
|
|
|
|
setTimeout(() => {
|
|
Pushy.setNotificationListener((data) => {
|
|
new Notification({ title: data.title, body: data.message }).show()
|
|
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>')
|
|
`)
|
|
}
|
|
})
|
|
}, 5000) // If this is triggered too soon, the notifications won't work.
|
|
|
|
if (Pushy.isRegistered()) {Pushy.subscribe(process.env.Name).then(() => {}).catch((error) => {console.error(error)})}
|
|
}
|
|
} |