|
| 1 | +// Modules to control application life and create native browser window |
| 2 | +const { app, BrowserWindow } = require("electron"); |
| 3 | +const path = require("path"); |
| 4 | + |
| 5 | +// Keep a global reference of the window object, if you don't, the window will |
| 6 | +// be closed automatically when the JavaScript object is garbage collected. |
| 7 | +let mainWindow; |
| 8 | + |
| 9 | +function createWindow() { |
| 10 | + // Create the browser window. |
| 11 | + mainWindow = new BrowserWindow({ |
| 12 | + width: 800, |
| 13 | + height: 600, |
| 14 | + webPreferences: { |
| 15 | + preload: path.join(__dirname, "preload.js"), |
| 16 | + }, |
| 17 | + }); |
| 18 | + |
| 19 | + // and load the index.html of the app. |
| 20 | + mainWindow.loadFile(path.join(__dirname, "index.html")); |
| 21 | + |
| 22 | + // Open the DevTools. |
| 23 | + // mainWindow.webContents.openDevTools() |
| 24 | + |
| 25 | + // Emitted when the window is closed. |
| 26 | + mainWindow.on("closed", function() { |
| 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. |
| 37 | +app.on("ready", createWindow); |
| 38 | + |
| 39 | +// Quit when all windows are closed. |
| 40 | +app.on("window-all-closed", function() { |
| 41 | + // On macOS 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") app.quit(); |
| 44 | +}); |
| 45 | + |
| 46 | +app.on("activate", function() { |
| 47 | + // On macOS it's common to re-create a window in the app when the |
| 48 | + // dock icon is clicked and there are no other windows open. |
| 49 | + if (mainWindow === null) createWindow(); |
| 50 | +}); |
| 51 | + |
| 52 | +// In this file you can include the rest of your app's specific main process |
| 53 | +// code. You can also put them in separate files and require them here. |
0 commit comments