From 38ce7697dbcff4d8db40aecc7d9307cd32688702 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Wed, 9 Sep 2020 14:29:23 +0200 Subject: [PATCH] update: notify model & ipc --- main/index.js | 17 ++++++----------- package.json | 1 + 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/main/index.js b/main/index.js index 5ab57ea7..b28d2589 100644 --- a/main/index.js +++ b/main/index.js @@ -18,7 +18,7 @@ const log = require('electron-log'); const packagejson = require('../package.json') const is = require('electron-is') const waitOn = require('wait-on'); -const { title } = require('process'); +const { getDoNotDisturb } = require('electron-notification-state') let app_path = is.dev()? 'http://127.0.0.1:8000/' : `file://${path.join(__dirname, '..', 'renderer')}/index.html`; let mainWindow; @@ -33,6 +33,7 @@ app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') const gotTheLock = app.requestSingleInstanceLock() const notifySupport = Notification.isSupported() +const isNotDisturb = getDoNotDisturb() // Prevent multiple instances if (!gotTheLock) { @@ -41,7 +42,6 @@ if (!gotTheLock) { function notify(params) { if(!notifySupport || !params) return false - let options = { title: "", body: "", @@ -52,15 +52,10 @@ function notify(params) { const keys = Object.keys(params) const values = Object.values(params) - for (let index = 0; index < keys.length; index++) { - const element = array[index]; - + for (let i = 0; i < keys.length; i++) { + options[keys[i]] = values[i] } - params.forEach(element => { - options[element] = element - }) - new Notification(options).show() } @@ -251,6 +246,6 @@ ipcMain.handle('appRestart', () => { mainWindow.close(); }); -ipcMain.handle('app_notify', () => { - notify({ title: "Bruh" }) +ipcMain.handle('app_notify', (payload) => { + notify(payload) }) \ No newline at end of file diff --git a/package.json b/package.json index 365b8e8d..367f7855 100755 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "electron-config": "^2.0.0", "electron-is": "^3.0.0", "electron-log": "^4.2.4", + "electron-notification-state": "^1.0.4", "electron-updater": "^4.3.4", "enquire-js": "^0.2.1", "feather-reactjs": "^2.0.13",