From 0ea3b92887db46a0879ee44c2fb4896b272f6645 Mon Sep 17 00:00:00 2001 From: netharu methmitha Date: Mon, 7 Feb 2022 23:28:07 +0530 Subject: [PATCH] now it brings up the application to the focus when you click on the notification --- src/bell.js | 5 ++++- src/index.js | 9 ++++++++- src/main.js | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/bell.js b/src/bell.js index 9e24481..3a6dacf 100644 --- a/src/bell.js +++ b/src/bell.js @@ -1,4 +1,4 @@ -const { shell } = require("electron"); +const { shell, ipcRenderer } = require("electron"); const path = require("path"); const fs = require("fs"); const _ = require("lodash"); @@ -329,6 +329,9 @@ class bell { icon: path.resolve(__dirname, "../assets/icon.png"), } ); + this.bellNotification.addEventListener("click", () => { + ipcRenderer.send("focusWindow"); + }); clearTimeout(this.bellNotificationTimeOut); }, this.eta() - 60000); var { bell, dropDown } = this.createBellElement(); diff --git a/src/index.js b/src/index.js index 2683175..7e92dc1 100644 --- a/src/index.js +++ b/src/index.js @@ -81,7 +81,14 @@ const createWindow = () => { } }); } - + ipcMain.on("focusWindow", (event, arg) => { + if (mainWindow) { + if (mainWindow.isMinimized()) { + mainWindow.restore(); + } + mainWindow.show(); + } + }); // Create the browser window. const mainWindow = new BrowserWindow({ width: 1080, diff --git a/src/main.js b/src/main.js index cff9ba7..f99a4df 100644 --- a/src/main.js +++ b/src/main.js @@ -42,7 +42,11 @@ settingsHandler.onAudioBellOutChange = (e) => { bellHandler.setBellAudioOutput(e.target.value); }; -new Notification("auto-bell", { +let running = new Notification("auto-bell", { body: "auto-bell is running", icon: path.resolve(__dirname, "../assets/icon.png"), }); + +running.onclick = () => { + ipcRenderer.send("focusWindow"); +};