Setup Pushy

This commit is contained in:
KorbsStudio 2023-02-11 15:57:28 -05:00
parent f3641ddc2c
commit bd283bfa2e
No known key found for this signature in database

View file

@ -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 = [