Created
June 9, 2018 22:57
-
-
Save cjus/57ed49f73bcbb8b268c00bcf0a20c8e2 to your computer and use it in GitHub Desktop.
Electron main.js file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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