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,
});
autoUpdater.checkForUpdatesAndNotify();
const baseUrl = process.env.NODE_ENV === 'local' ? 'http://localhost:8080/portfolio' : 'https://web.getdelta.io/portfolio';
const deviceId = machineIdSync({ original: true });
const appUrl = `${baseUrl}?deviceId=${deviceId}&t=${new Date().getTime()}`;
win = new BrowserWindow({
minWidth: 792,
minHeight: 610,
width: mainWindowState.width,
height: mainWindowState.height,
title: '∆ Delta',
titleBarStyle: 'hiddenInset',
});
mainWindowState.manage(win);
win.loadURL(appUrl);
win.on('closed', () => {
win = null;
});
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);
if (process.env.NODE_ENV !== 'local') {
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;
});