UNPKG

1.83 kBJavaScriptView Raw
1import { app, BrowserWindow } from 'electron';
2
3// Handle creating/removing shortcuts on Windows when installing/uninstalling.
4if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
5 app.quit();
6}
7
8// Keep a global reference of the window object, if you don't, the window will
9// be closed automatically when the JavaScript object is garbage collected.
10let mainWindow;
11
12const createWindow = () => {
13 // Create the browser window.
14 mainWindow = new BrowserWindow({
15 width: 800,
16 height: 600,
17 });
18
19 // and load the index.html of the app.
20 mainWindow.loadURL(`file://${__dirname}/index.html`);
21
22 // Open the DevTools.
23 mainWindow.webContents.openDevTools();
24
25 // Emitted when the window is closed.
26 mainWindow.on('closed', () => {
27 // Dereference the window object, usually you would store windows
28 // in an array if your app supports multi windows, this is the time
29 // when you should delete the corresponding element.
30 mainWindow = null;
31 });
32};
33
34// This method will be called when Electron has finished
35// initialization and is ready to create browser windows.
36// Some APIs can only be used after this event occurs.
37app.on('ready', createWindow);
38
39// Quit when all windows are closed.
40app.on('window-all-closed', () => {
41 // On OS X it is common for applications and their menu bar
42 // to stay active until the user quits explicitly with Cmd + Q
43 if (process.platform !== 'darwin') {
44 app.quit();
45 }
46});
47
48app.on('activate', () => {
49 // On OS X it's common to re-create a window in the app when the
50 // dock icon is clicked and there are no other windows open.
51 if (mainWindow === null) {
52 createWindow();
53 }
54});
55
56// In this file you can include the rest of your app's specific main process
57// code. You can also put them in separate files and import them here.