import * as log from 'electron-log' ; import * as path from 'path' ; import ConfigStorage from '../backend/src/ConfigStorage' ; import { app , BrowserWindow , Menu } from 'electron' ; import { autoUpdater } from 'electron-updater' ; import { ConnectionManager } from '../backend/src/index' ; import { electronTelemetryFactory } from 'electron-telemetry' ; import { menuTemplate } from './MenuTemplate' ; import buildOptions from './buildOptions' ; import { waitForDevServer , isDev , runningUiTestOnCi , loadDevTools } from './development' ; import { shouldAutoUpdate , handleAutoUpdate } from './autoUpdater' ; import { registerCrashReporter } from './registerCrashReporter' ; registerCrashReporter ( ) ; if ( ! isDev ( ) && ! runningUiTestOnCi ( ) ) { const electronTelemetry = electronTelemetryFactory ( '9b0c8ca04a361eb8160d98c5' , buildOptions ) ; } app . commandLine . appendSwitch ( '--no-sandbox' ) ; autoUpdater . logger = log ; log . info ( 'App starting...' ) ; const connectionManager = new ConnectionManager ( ) ; connectionManager . manageConnections ( ) ; const configStorage = new ConfigStorage ( path . join ( app . getPath ( 'appData' ) , app . name , 'settings.json' ) ) ; configStorage . init ( ) ; let mainWindow ; async function createWindow ( ) { if ( isDev ( ) ) { await waitForDevServer ( ) ; loadDevTools ( ) ; } const iconPath = path . join ( __dirname , '..' , '..' , 'icon.png' ) ; mainWindow = new BrowserWindow ( { width : 1024 , height : 720 , show : false , webPreferences : { nodeIntegration : true , devTools : true , sandbox : false } , icon : iconPath } ) ; mainWindow . once ( 'ready-to-show' , ( ) => { if ( mainWindow ) { runningUiTestOnCi ( ) && mainWindow . setFullScreen ( true ) ; mainWindow . show ( ) ; } } ) ; console . log ( 'icon path' , iconPath ) ; if ( isDev ( ) ) { mainWindow . loadURL ( 'http://localhost:8080' ) ; } else { mainWindow . loadFile ( 'app/build/index.html' ) ; } mainWindow . on ( 'close' , ( ) => { connectionManager . closeAllConnections ( ) ; } ) ; mainWindow . on ( 'closed' , ( ) => { mainWindow = undefined ; app . quit ( ) ; } ) ; } app . on ( 'ready' , ( ) => { Menu . setApplicationMenu ( menuTemplate ) ; createWindow ( ) ; if ( shouldAutoUpdate ( buildOptions ) ) { handleAutoUpdate ( ) ; } } ) ; app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , ( ) => { if ( mainWindow === null ) { createWindow ( ) ; } } ) ;