|
| 1 | +import { app, BrowserWindow } from "electron"; |
| 2 | +import * as path from "path"; |
| 3 | +import pkgDir from 'pkg-dir'; |
| 4 | + |
| 5 | +let mainWindow: Electron.BrowserWindow | null; |
| 6 | + |
| 7 | +function createWindow() { |
| 8 | + // Create the browser window. |
| 9 | + mainWindow = new BrowserWindow({ |
| 10 | + height: 600, |
| 11 | + width: 800, |
| 12 | + }); |
| 13 | + |
| 14 | + // and load the index.html of the app. |
| 15 | + mainWindow.loadFile(path.join(pkgDir.sync()!, "output", "dev", "index.html")); |
| 16 | + |
| 17 | + // Open the DevTools. |
| 18 | + mainWindow.webContents.openDevTools(); |
| 19 | + |
| 20 | + // Emitted when the window is closed. |
| 21 | + mainWindow.on("closed", () => { |
| 22 | + // Dereference the window object, usually you would store windows |
| 23 | + // in an array if your app supports multi windows, this is the time |
| 24 | + // when you should delete the corresponding element. |
| 25 | + mainWindow = null; |
| 26 | + }); |
| 27 | +} |
| 28 | + |
| 29 | +// This method will be called when Electron has finished |
| 30 | +// initialization and is ready to create browser windows. |
| 31 | +// Some APIs can only be used after this event occurs. |
| 32 | +app.on("ready", createWindow); |
| 33 | + |
| 34 | +// Quit when all windows are closed. |
| 35 | +app.on("window-all-closed", () => { |
| 36 | + // On OS X it is common for applications and their menu bar |
| 37 | + // to stay active until the user quits explicitly with Cmd + Q |
| 38 | + if (process.platform !== "darwin") { |
| 39 | + app.quit(); |
| 40 | + } |
| 41 | +}); |
| 42 | + |
| 43 | +app.on("activate", () => { |
| 44 | + // On OS X it"s common to re-create a window in the app when the |
| 45 | + // dock icon is clicked and there are no other windows open. |
| 46 | + if (mainWindow === null) { |
| 47 | + createWindow(); |
| 48 | + } |
| 49 | +}); |
| 50 | + |
| 51 | +// In this file you can include the rest of your app"s specific main process |
| 52 | +// code. You can also put them in separate files and require them here. |
0 commit comments