From 6cf4eeb47d46104f0648c4c3fb216a46c7e1f00b Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 3 Feb 2020 13:40:27 -0800 Subject: [PATCH] chore: no need to hold on to mainWindow reference (#357) --- main.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/main.js b/main.js index 3508c8e..e366d5b 100644 --- a/main.js +++ b/main.js @@ -2,13 +2,9 @@ const {app, BrowserWindow} = require('electron') const path = require('path') -// Keep a global reference of the window object, if you don't, the window will -// be closed automatically when the JavaScript object is garbage collected. -let mainWindow - function createWindow () { // Create the browser window. - mainWindow = new BrowserWindow({ + const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { @@ -21,14 +17,6 @@ function createWindow () { // Open the DevTools. // mainWindow.webContents.openDevTools() - - // Emitted when the window is closed. - mainWindow.on('closed', function () { - // Dereference the window object, usually you would store windows - // in an array if your app supports multi windows, this is the time - // when you should delete the corresponding element. - mainWindow = null - }) } // This method will be called when Electron has finished @@ -46,7 +34,7 @@ app.on('window-all-closed', function () { app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. - if (mainWindow === null) createWindow() + if (BrowserWindow.getAllWindows().length === 0) createWindow() }) // In this file you can include the rest of your app's specific main process