first-electron/main.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-05-26 04:09:14 +08:00
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
2015-10-17 08:04:57 +08:00
// 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.
2016-04-30 04:08:11 +08:00
let mainWindow
2015-10-17 08:04:57 +08:00
2015-12-17 03:19:56 +08:00
function createWindow () {
2015-10-17 08:04:57 +08:00
// Create the browser window.
2016-04-30 04:08:11 +08:00
mainWindow = new BrowserWindow({width: 800, height: 600})
2015-10-17 08:04:57 +08:00
// and load the index.html of the app.
2018-05-26 04:09:14 +08:00
mainWindow.loadFile('index.html')
2015-10-17 08:04:57 +08:00
// Open the DevTools.
// mainWindow.webContents.openDevTools()
2015-10-17 08:04:57 +08:00
// Emitted when the window is closed.
2016-04-30 04:08:11 +08:00
mainWindow.on('closed', function () {
2015-10-17 08:04:57 +08:00
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
2016-04-30 04:08:11 +08:00
mainWindow = null
})
2015-12-17 03:19:56 +08:00
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
2016-04-21 06:14:27 +08:00
// Some APIs can only be used after this event occurs.
2016-04-30 04:08:11 +08:00
app.on('ready', createWindow)
2015-12-17 03:19:56 +08:00
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
2015-12-17 03:19:56 +08:00
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
2016-04-30 04:08:11 +08:00
app.quit()
2015-12-17 03:19:56 +08:00
}
2016-04-30 04:08:11 +08:00
})
2015-12-17 03:19:56 +08:00
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
2015-12-17 03:19:56 +08:00
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
2016-04-30 04:08:11 +08:00
createWindow()
2015-12-17 03:19:56 +08:00
}
2016-04-30 04:08:11 +08:00
})
2016-04-21 06:14:27 +08:00
2016-04-29 08:32:24 +08:00
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.