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",'
  • ${data.title}

    ${data.message}

  • ') `) } }) }, 5000) // If this is triggered too soon, the notifications won't work. if (Pushy.isRegistered()) {Pushy.subscribe('AppName').then(() => {}).catch((error) => {console.error(error)})} } }