set main.js to initialize the window, load index.htm and close appropriately when app is quit

This commit is contained in:
Queen Bee 2018-01-05 12:02:02 -08:00
parent 0706f8331b
commit d672f134ef

32
main.js
View File

@ -2,8 +2,38 @@ const { app, BrowserWindow } = require('electron');
const path = require('path'); const path = require('path');
const url = require('url'); const url = require('url');
// init win
let win; let win;
function createWindow() { function createWindow() {
win = new BrowserWindow({ width: 800, height: 600 }); // 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();
}
});