first-electron/main.js

47 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-11-24 10:16:42 +08:00
'use strict';
const electron = require('electron');
const app = electron.app; // Module to control application life.
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
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.
2015-11-24 10:16:42 +08:00
let mainWindow;
2015-10-17 08:04:57 +08:00
// Quit when all windows are closed.
2015-12-17 03:10:38 +08:00
app.on('window-all-closed', function () {
2015-10-17 08:04:57 +08:00
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
2015-12-17 03:11:29 +08:00
if (process.platform !== 'darwin') {
2015-10-17 08:04:57 +08:00
app.quit();
}
});
2015-12-17 03:10:38 +08:00
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
app.emit('ready');
}
});
2015-10-17 08:04:57 +08:00
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
2015-12-07 15:17:42 +08:00
mainWindow.loadURL('file://' + __dirname + '/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.
mainWindow.on('closed', function() {
// 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.
mainWindow = null;
});
});