diff --git a/electron/index.js b/electron/index.js index ba033a9..0267447 100644 --- a/electron/index.js +++ b/electron/index.js @@ -1,9 +1,10 @@ const {app, BrowserWindow, Menu} = require('electron') -const isDev = require('electron-is-dev') -const {TitlebarRespect} = require('electron-titlebar-respect') +const TitlebarRespect = require('electron-titlebar-respect') +const Pushy = require('pushy-electron') const glasstron = require('glasstron-clarity') +const isDev = require('electron-is-dev') const path = require('path') - +let mainWindow // Use the correct icon depending on the operating system if /* If macOS */ (process.platform == 'darwin') {global.AppIcon = 'public/images/icons/app/macOS.icns' } @@ -12,7 +13,7 @@ else /* If Linux */ {global.AppIcon = 'p function createWindow () { - const mainWindow = new glasstron.BrowserWindow({ + mainWindow = new glasstron.BrowserWindow({ title: 'App Name', minWidth: 400, minHeight: 400, @@ -34,17 +35,32 @@ function createWindow () { webviewTag: true } }) + // Showing the window gracefuly // Doc: https://www.electronjs.org/docs/latest/api/browser-window#showing-the-window-gracefully - mainWindow.once('ready-to-show', () => { - mainWindow.show() - }) + mainWindow.once('ready-to-show', () => {mainWindow.show()}) + + // Pushy - Pushy Notification System (PNS) + mainWindow.webContents.on('did-finish-load', () => {Pushy.listen()}) + Pushy.register({ appId: 'YourAppIdHere' }).then((deviceToken) => {}).catch((error) => {console.log('Pushy registration error: ' + error.message)}) + + setTimeout(() => { + Pushy.setNotificationListener((data) => { + mainWindow.webContents.executeJavaScript(` + document.querySelector("body > div > div.sidebar > div.sidebar-bottom").insertAdjacentHTML("afterBegin",'
  • ${data.title}

    ${data.message}

  • ') + `) + }) + }, 10000); + + if (Pushy.isRegistered()) {Pushy.subscribe('AppName').then(() => {}).catch((error) => {console.error(error)})} + // Load Content if (isDev) { mainWindow.loadURL('http://localhost:3000') // Use a URL in development mode } else { mainWindow.loadFile('app/index.html') // Do NOT use a URL in production mode, as that can create a security risk for your customers who will use this app } + // Menu const isMac = process.platform === 'darwin' const template = [