/* eslint global-require: off, no-console: off */ /** * This module executes inside of electron's main process. You can start * electron renderer process from here and communicate with the other processes * through IPC. * * When running `yarn build` or `yarn build-main`, this file is compiled to * `./app/main.prod.js` using webpack. This gives us some performance wins. */ import * as path from "path"; import { app, BrowserWindow } from "electron"; import MenuBuilder from "./menu"; let mainWindow: BrowserWindow | null = null; const installExtensions = async () => { const installer = require("electron-devtools-installer"); const forceDownload = !!process.env.UPGRADE_EXTENSIONS; const extensions = ["REACT_DEVELOPER_TOOLS"]; return Promise.all( extensions.map((name) => installer.default(installer[name], forceDownload)) ).catch(console.log); }; const createWindow = async () => { if (process.env.DEBUG_APP === "true") { await installExtensions(); } let windowOpts = { show: false, width: 1024, height: 728, webPreferences: { nodeIntegration: true, contextIsolation: false, }, icon: "", }; if (process.env.APPDIR) { windowOpts.icon = path.join( process.env.APPDIR, "usr/share/icons/hicolor/256x256/apps/fiftyone.png" ); } mainWindow = new BrowserWindow(windowOpts); mainWindow.loadURL(`file://${__dirname}/index.html`); // @TODO: Use 'ready-to-show' event // https://github.com/electron/electron/blob/master/docs/api/browser-window.md#using-ready-to-show-event mainWindow.webContents.on("did-finish-load", () => { if (!mainWindow) { throw new Error('"mainWindow" is not defined'); } if (process.env.START_MINIMIZED) { mainWindow.minimize(); } else { mainWindow.show(); mainWindow.focus(); } }); mainWindow.on("closed", () => { mainWindow = null; }); const menuBuilder = new MenuBuilder(mainWindow); menuBuilder.buildMenu(); }; /** * Add event listeners... */ app.on("window-all-closed", () => { app.quit(); }); app.on("ready", createWindow); app.on("activate", () => { // On macOS 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) createWindow(); });