From c2c951edc625b9f082a66259441284cc53bf5a98 Mon Sep 17 00:00:00 2001 From: Ghost <31184695+GHOSCHT@users.noreply.github.com> Date: Fri, 7 Aug 2020 16:25:09 +0200 Subject: [PATCH] take trayIcon oncklick event out of creation function --- Dashboard/app/main/index.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/Dashboard/app/main/index.js b/Dashboard/app/main/index.js index d5405c5..7fa6328 100644 --- a/Dashboard/app/main/index.js +++ b/Dashboard/app/main/index.js @@ -10,6 +10,7 @@ const trayIconPath = '../../dist-assets/tray.ico'; let mainWindow = null; let mainWindowHidden = true; +let trayIcon = null; const isDevelopment = process.env.NODE_ENV === 'development'; const gotTheLock = app.requestSingleInstanceLock(); app.allowRendererProcessReuse = false; @@ -62,24 +63,16 @@ if (!gotTheLock) { mainWindow.setMenu(null); mainWindow.loadFile(path.resolve(path.join(__dirname, '../renderer/index.html'))); - createTray(); + trayIcon = createTray(); + + trayIcon.on('click', () => { + mainWindow.show(); + mainWindow.focus(); + }); mainWindow.webContents.on('did-finish-load', () => { mainWindow.webContents.openDevTools(); }); - - if (isDevelopment) { - mainWindow.webContents.on('context-menu', (e, props) => { - Menu.buildFromTemplate([ - { - label: 'Inspect element', - click() { - mainWindow.inspectElement(props.x, props.y); - }, - }, - ]).popup(mainWindow); - }); - } }); } @@ -102,11 +95,6 @@ function createTray() { }, ]); - trayIcon.on('click', () => { - mainWindow.show(); - mainWindow.focus(); - }); - trayIcon.setToolTip('Light Control'); trayIcon.setContextMenu(contextMenu); return trayIcon;