From a579bf48f4ce8ffb31c24af426e40b28eef5e31f Mon Sep 17 00:00:00 2001 From: KorbsStudio Date: Tue, 14 Feb 2023 14:46:39 -0500 Subject: [PATCH] Add option for native notifications --- electron/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/electron/index.js b/electron/index.js index ab90388..19b6d5c 100644 --- a/electron/index.js +++ b/electron/index.js @@ -1,5 +1,5 @@ // ElectronJS -const {app, BrowserWindow, Menu} = require('electron') +const {app, BrowserWindow, Menu, Notification} = require('electron') // Dependenies by Korbs Studio const glasstron = require('glasstron-clarity') @@ -22,9 +22,9 @@ 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' } +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' } +else /* If Linux */ {global.AppIcon = 'public/images/icons/app/Linux.png' } function createWindow () { mainWindow = new glasstron.BrowserWindow({ @@ -60,11 +60,16 @@ function createWindow () { setTimeout(() => { Pushy.setNotificationListener((data) => { - mainWindow.webContents.executeJavaScript(` - document.querySelector("body > div > div.sidebar > div.sidebar-bottom").insertAdjacentHTML("afterBegin",'
  • ${data.title}

    ${data.message}

  • ') - `) + 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) + }, 10000) // If this is triggered too soon, the notifications won't work. if (Pushy.isRegistered()) {Pushy.subscribe('AppName').then(() => {}).catch((error) => {console.error(error)})}