import { app , BrowserWindow , ipcMain , screen } from 'electron' ; import * as path from 'path' ; import * as url from 'url' ; let serve ; const args = process . argv . slice ( 1 ) ; serve = args . some ( val => val === '--serve' ) ; let win = null ; const getFromEnv = parseInt ( process . env . ELECTRON_IS_DEV , 10 ) === 1 ; const isEnvSet = 'ELECTRON_IS_DEV' in process . env ; const debugMode = isEnvSet ? getFromEnv : process . defaultApp || /node_modules[\\/]electron[\\/]/ . test ( process . execPath ) ; /**
 * Electron window settings
 */ const mainWindowSettings = { frame : true , resizable : true , focusable : true , fullscreenable : true , kiosk : false , webPreferences : { devTools : debugMode , nodeIntegration : true } } ; /**
 * Hooks for electron main process
 */ function initMainListener ( ) { ipcMain . on ( 'ELECTRON_BRIDGE_HOST' , ( event , msg ) => { console . log ( 'msg received' , msg ) ; if ( msg === 'ping' ) { event . sender . send ( 'ELECTRON_BRIDGE_CLIENT' , 'pong' ) ; } } ) ; } /**
 * Create main window presentation
 */ function createWindow ( ) { const sizes = screen . getPrimaryDisplay ( ) . workAreaSize ; if ( debugMode ) { process . env [ 'ELECTRON_DISABLE_SECURITY_WARNINGS' ] = 'true' ; mainWindowSettings . width = 800 ; mainWindowSettings . height = 600 ; } else { mainWindowSettings . width = sizes . width ; mainWindowSettings . height = sizes . height ; mainWindowSettings . x = 0 ; mainWindowSettings . y = 0 ; } win = new BrowserWindow ( mainWindowSettings ) ; let launchPath ; if ( serve ) { require ( 'electron-reload' ) ( __dirname , { electron : require ( `${ __dirname }/../../../node_modules/electron` ) } ) ; launchPath = 'http://localhost:4200' ; win . loadURL ( launchPath ) ; } else { launchPath = url . format ( { pathname : path . join ( __dirname , 'index.html' ) , protocol : 'file:' , slashes : true } ) ; win . loadURL ( launchPath ) ; } console . log ( 'launched electron with:' , launchPath ) ; win . on ( 'closed' , ( ) => { win = null ; } ) ; initMainListener ( ) ; if ( debugMode ) { win . webContents . openDevTools ( ) ; } } try { app . on ( 'ready' , createWindow ) ; app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , ( ) => { if ( win === null ) { createWindow ( ) ; } } ) ; } catch ( err ) { }