import { BrowserWindow , Menu , shell } from 'electron' ; import * as windowState from 'electron-window-state' ; import { join as pathJoin } from 'path' ; import { argv } from 'process' ; import { parseProtocolArgs } from './custom-protocol' ; import { createMenu } from './menu' ; import { createSplashScreen } from './splashscreen' ; declare const isTesting ; declare const isDev ; let openUrlArgs ; const showMainWindow = ( mainWindowState , mainWindow ) => { mainWindowState . manage ( mainWindow ) ; mainWindow . show ( ) ; parseProtocolArgs ( openUrlArgs || argv , mainWindow ) ; } ; export const saveOpenUrlArgs = ( url ) => { openUrlArgs = url ; } ; export const initMainWindow = ( ) => { let splashScreen ; if ( ! isTesting ) { splashScreen = createSplashScreen ( ) ; } const mainWindowState = windowState ( { defaultWidth : 1024 , defaultHeight : 768 } ) ; const mainWindow = new BrowserWindow ( { x : mainWindowState . x , y : mainWindowState . y , minWidth : 1024 , minHeight : 768 , resizable : true , maximizable : true , minimizable : true , width : mainWindowState . width , height : mainWindowState . height , title : 'Mockoon' , backgroundColor : '#252830' , icon : pathJoin ( __dirname , '/build-res/icon_512x512x32.png' ) , show : false , webPreferences : { nodeIntegration : false , contextIsolation : true , sandbox : true , devTools : isDev ? true : false , spellcheck : false , preload : pathJoin ( __dirname , '/preload.js' ) } } ) ; mainWindow . webContents . on ( 'dom-ready' , ( ) => { setTimeout ( ( ) => { if ( splashScreen && ! splashScreen . isDestroyed ( ) ) { splashScreen . close ( ) ; } setTimeout ( ( ) => { showMainWindow ( mainWindowState , mainWindow ) ; if ( isDev ) { mainWindow . webContents . openDevTools ( ) ; } } , 100 ) ; } , 500 ) ; } ) ; mainWindow . loadURL ( `file://${ __dirname }/renderer/index.html` ) ; mainWindow . webContents . on ( 'new-window' , ( event , targetUrl ) => { event . preventDefault ( ) ; if ( targetUrl . includes ( 'openexternal::' ) ) { shell . openExternal ( targetUrl . split ( '::' ) [ 1 ] ) ; } } ) ; Menu . setApplicationMenu ( createMenu ( mainWindow ) ) ; return mainWindow ; } ;