const { app, BrowserWindow, shell, } = require('electron'); const autoUpdater = require('electron-updater').autoUpdater; const { machineIdSync } = require('node-machine-id'); const windowStateKeeper = require('electron-window-state'); let win; function createWindow() { let mainWindowState = windowStateKeeper({ defaultWidth: 1200, defaultHeight: 800, }); // Check for updates autoUpdater.checkForUpdatesAndNotify(); // Base URL const baseUrl = process.env.NODE_ENV === 'local' ? 'http://localhost:8080/portfolio' : 'https://web.getdelta.io/portfolio'; // Get unique device ID const deviceId = machineIdSync({ original: true }); // App URL const appUrl = `${baseUrl}?deviceId=${deviceId}&t=${new Date().getTime()}`; // Create the browser window win = new BrowserWindow({ minWidth: 792, minHeight: 610, width: mainWindowState.width, height: mainWindowState.height, title: '∆ Delta', titleBarStyle: 'hiddenInset', }); // Keep window state mainWindowState.manage(win); // Load the app win.loadURL(appUrl); // Emitted when the window is closed. win.on('closed', () => { win = null; }); // Open URL's in the default browser const webContents = win.webContents; const handleRedirect = (e, url) => { if (url != webContents.getURL()) { e.preventDefault(); shell.openExternal(url); } }; webContents.on('will-navigate', handleRedirect); webContents.on('new-window', handleRedirect); // Don't overwrite default menu (with debug tools) in local mode if (process.env.NODE_ENV !== 'local') { // Include menu require('./menu'); } } app.on('ready', createWindow); app.on('activate', () => { if (win === null) { createWindow(); } }); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); return; } win = null; });