Skip to content

Commit

Permalink
chore: no need to hold on to mainWindow reference (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon authored Feb 3, 2020
1 parent e929197 commit 6cf4eeb
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6cf4eeb

Please sign in to comment.