From d672f134ef923611602d0362e1ff5f896966e650 Mon Sep 17 00:00:00 2001 From: Queen Bee Date: Fri, 5 Jan 2018 12:02:02 -0800 Subject: [PATCH] set main.js to initialize the window, load index.htm and close appropriately when app is quit --- main.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 8039a7b..1fe4bf0 100644 --- a/main.js +++ b/main.js @@ -2,8 +2,38 @@ const { app, BrowserWindow } = require('electron'); const path = require('path'); const url = require('url'); +// init win let win; function createWindow() { - win = new BrowserWindow({ width: 800, height: 600 }); -} \ No newline at end of file + // Create browser window + win = new BrowserWindow({ width: 800, height: 600, icon: }); + + // Load index.html + win.loadURL(url.format({ + pathname: path.join(__dirname, 'index.html'), + protocol: 'file:', + slashes: true + })); + + // Open devtools + win.webContents().openDevTools(); + + win.on('closed', () => { + win = null; + }); +} + +// Run create window function +app.on('ready', createWindow); + +// Quit when all windows are closed +app.on('window-all-closed', () => { + + // Check if user is on a Mac + if (process.platform !== 'darwin') { + app.quit(); + + } + +}); \ No newline at end of file