From b6fc38365430da443d718e5f69b915b46c1a041b Mon Sep 17 00:00:00 2001 From: Ghost <31184695+GHOSCHT@users.noreply.github.com> Date: Fri, 7 Aug 2020 16:09:15 +0200 Subject: [PATCH] Comments + minor changes --- Dashboard/app/main/index.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Dashboard/app/main/index.js b/Dashboard/app/main/index.js index 1e26abe..b7a85aa 100644 --- a/Dashboard/app/main/index.js +++ b/Dashboard/app/main/index.js @@ -1,18 +1,20 @@ import path from 'path'; import { app, BrowserWindow, Menu, Tray } from 'electron'; -const screenz = require('screenz'); - -let mainWindow = null; - -const isDevelopment = process.env.NODE_ENV === 'development'; -const gotTheLock = app.requestSingleInstanceLock(); -app.allowRendererProcessReuse = false; +import screenz from 'screenz'; +//App preferences const windowSize = { width: 620, height: 320 }; const windowOffset = 40; const appIconPath = '../../dist-assets/icon2.ico'; const trayIconPath = '../../dist-assets/tray.ico'; +let mainWindow = null; +let mainWindowHidden = true; +const isDevelopment = process.env.NODE_ENV === 'development'; +const gotTheLock = app.requestSingleInstanceLock(); +app.allowRendererProcessReuse = false; + +//Install chrome devtools extensions const installExtensions = async () => { const installer = require('electron-devtools-installer'); const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS']; @@ -26,18 +28,15 @@ const installExtensions = async () => { } }; +//Force single app instance if (!gotTheLock) { app.quit(); } else { app.on('second-instance', () => { - // Someone tried to run a second instance, we should focus our window. - if (mainWindow) { - mainWindow.show(); - mainWindow.focus(); - } + mainWindow.show(); + mainWindow.focus(); }); - // Create mainWindow, load the rest of the app, etc... app.on('ready', async () => { if (isDevelopment) { await installExtensions(); @@ -63,13 +62,13 @@ if (!gotTheLock) { mainWindow.setMenu(null); mainWindow.loadFile(path.resolve(path.join(__dirname, '../renderer/index.html'))); + createTray(); + mainWindow.webContents.on('did-finish-load', () => { - createTray(); + mainWindow.webContents.openDevTools(); }); if (isDevelopment) { - mainWindow.webContents.openDevTools(); - mainWindow.webContents.on('context-menu', (e, props) => { Menu.buildFromTemplate([ { @@ -84,6 +83,7 @@ if (!gotTheLock) { }); } +//Create tray icon with context menu function createTray() { const trayIcon = new Tray(path.join(__dirname, trayIconPath)); const contextMenu = Menu.buildFromTemplate([ @@ -112,6 +112,7 @@ function createTray() { return trayIcon; } +//Hide window when out of focus app.on('browser-window-blur', () => { mainWindow.hide(); });