Electron
Basics
Usage
Simplest App
const {app, BrowserWindow} = require('electron')
const path = require('path')
// Keep global b/c will be closed when garbage collected
let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html')
// mainWindow.webContents.openDevTools()
mainWindow.on('closed', function () {
// Usually store windows in array and delete those
mainWindow = null
})
}
// Ready to createWindows and use other APIS
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS, common to keep open
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
// On macOS, common to recreate app
if (mainWindow === null) createWindow()
})Local File
Last updated