Skip to content

Instantly share code, notes, and snippets.

@cjus
Created June 9, 2018 22:57
Show Gist options
  • Save cjus/57ed49f73bcbb8b268c00bcf0a20c8e2 to your computer and use it in GitHub Desktop.
Save cjus/57ed49f73bcbb8b268c00bcf0a20c8e2 to your computer and use it in GitHub Desktop.
Electron main.js file
const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = require('url');
// 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 win;
/**
* @name createWindow
* @return {undefined}
*/
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600
});
const startUrl = process.env.ELECTRON_START_URL || url.format({
pathname: path.join(__dirname, '/../build/index.html'),
protocol: 'file:',
slashes: true
});
win.loadURL(startUrl);
// Emitted when the window is closed.
win.on('closed', () => {
win = null;
});
}
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment