Setup Pushy
This commit is contained in:
parent
f3641ddc2c
commit
bd283bfa2e
1 changed files with 23 additions and 7 deletions
|
@ -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",'<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">${data.action}</button><button id="secondary" class="notification-action">Dismiss</button></div></li>')
|
||||
`)
|
||||
})
|
||||
}, 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 = [
|
||||
|
|
Reference in a new issue