// ElectronJS const {app, BrowserWindow, Menu, Notification} = require('electron') // Dependenies by Korbs Studio const glasstron = require('glasstron-clarity') const TitlebarRespect = require('electron-titlebar-respect') // Other dependenies const isDev = require('electron-is-dev') const log = require('electron-log') const Pushy = require('pushy-electron') // Needed for other stuff const path = require('path') let mainWindow // Grab .env options require('dotenv').config() // Override the console.log function with Electron Log log.transports.console.format = '\x1b[34m[electron]:\x1b[37m' console.log = log.log // Use the correct icon depending on the operating system if /* If macOS */ (process.platform == 'darwin') {global.AppIcon = 'public/images/icons/app/macOS.icns' } else if /* If Windows */ (process.platform == 'win32') {global.AppIcon = 'public/images/icons/app/Windows.png' } else /* If Linux */ {global.AppIcon = 'public/images/icons/app/Linux.png' } function createWindow () { mainWindow = new glasstron.BrowserWindow({ title: process.env.Name, minWidth: 400, minHeight: 400, width: 1200, height: 800, autoHideMenuBar: true, show: false, blur: true, frame: global.frame, titleBarStyle: global.titleBarStyle, icon: path.join(global.AppIcon), trafficLightPosition: { x: 25, y: 25 }, // Position of Traffic Light buttons on macOS titleBarOverlay: { // Background and Height of Windows titlebar buttons color: '#232323', // Background symbolColor: 'white', // Icon height: 44, }, webPreferences: { 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()}) // 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) => { 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}

  • ') `) } }) }, 10000) // If this is triggered too soon, the notifications won't work. 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 = [ ...(isMac ? [{ label: app.name, submenu: [ { role: 'about' }, { type: 'separator' }, { role: 'hide' }, { role: 'hideOthers' }, { role: 'unhide' }, { type: 'separator' }, { role: 'quit' } ] }] : []), { label: 'File', submenu: [ isMac ? { role: 'close' } : { role: 'quit' } ] }, { label: 'Edit', submenu: [ { role: 'undo' }, { role: 'redo' }, { type: 'separator' }, { role: 'cut' }, { role: 'copy' }, { role: 'paste' }, ...(isMac ? [ { role: 'pasteAndMatchStyle' }, { role: 'delete' }, { role: 'selectAll' }, { type: 'separator' }, { label: 'Speech', submenu: [ { role: 'startSpeaking' }, { role: 'stopSpeaking' } ] } ] : [ { role: 'delete' }, { type: 'separator' }, { role: 'selectAll' } ]) ] }, { label: 'View', submenu: [ { role: 'reload' }, { role: 'forceReload' }, { role: 'toggleDevTools' }, { label: 'Open WebView Developer Tools', accelerator: 'CmdOrCtrl+Shift+W', click: async () => {if (isDev) {mainWindow.webContents.executeJavaScript(`document.querySelector('.active webview').openDevTools()`)}else {console.log('Not available in production mode.')}} }, { type: 'separator' }, { role: 'resetZoom' }, { role: 'zoomIn' }, { role: 'zoomOut' }, { type: 'separator' }, { role: 'togglefullscreen' } ] }, { label: 'Window', submenu: [ { role: 'minimize' }, { role: 'zoom' }, ...(isMac ? [ { type: 'separator' }, { role: 'front' }, { type: 'separator' }, { role: 'window' } ] : [ { role: 'close' } ]) ] }, { role: 'help', submenu: [ { label: 'Website', click: async () => { const { shell } = require('electron') await shell.openExternal(process.env.Website) } }, { label: 'Support', click: async () => { const { shell } = require('electron') await shell.openExternal(process.env.Support) } }, { label: 'Source Code', click: async () => { const { shell } = require('electron') await shell.openExternal(process.env.SourceCode) } } ] } ] const menu = Menu.buildFromTemplate(template) Menu.setApplicationMenu(menu) } // App app.whenReady().then(() => { createWindow() // DNS // Docs: https://www.electronjs.org/docs/latest/api/app#appconfigurehostresolveroptions app.configureHostResolver({ secureDnsMode: 'secure', secureDnsServers: [ 'https://cloudflare-dns.com/dns-query' ] }) }) // app.disableHardwareAcceleration() app.on('window-all-closed', () => { app.quit() })