import { BrowserWindow , screen , app , ipcMain , protocol } from 'electron' ; import * as path from 'path' ; import * as url from 'url' ; import setUpMenu from './appMenu' ; import installDevtools from './devtools' ; import { ROOT_DIRECTORY } from './root' ; import { getStartUrl , WINDOW_START_DIMENSIONS } from './window' ; import { handleMessages } from '../src/messages' ; require ( 'electron-store' ) . initRenderer ( ) ; const { isPackaged } = app ; const Sentry = require ( '@sentry/electron' ) ; Sentry . init ( { dsn : 'https://bbdc0ddd503c41eea9ad656b5481202c@sentry.io/1881735' , } ) ; const INTEGRATION_DEV = JSON . parse ( process . env . INTEGRATION_DEV || 'false' ) ; const useDevtools = process . env . NODE_ENV === 'test' ? INTEGRATION_DEV : true ; const context = { mainWindow : null } ; const ffmpegStaticBasePath = require ( 'ffmpeg-static' ) ; const ffprobeStaticBasePath = require ( 'ffprobe-static' ) . path ; const getFfmpegStaticPath = ( basePath ) => basePath . replace ( 'app.asar' , 'app.asar.unpacked' ) ; global . ffmpegpath = getFfmpegStaticPath ( ffmpegStaticBasePath ) ; global . ffprobepath = getFfmpegStaticPath ( ffprobeStaticBasePath ) ; async function createWindow ( ) { const { width , height } = screen . getPrimaryDisplay ( ) . workAreaSize ; const mainWindow = new BrowserWindow ( { show : false , width : Math . min ( WINDOW_START_DIMENSIONS . width , width ) , height : Math . min ( WINDOW_START_DIMENSIONS . height , height ) , minWidth : 740 , minHeight : 570 , webPreferences : { webSecurity : isPackaged , nodeIntegration : true , contextIsolation : false , devTools : useDevtools , } , } ) ; const splash = process . env . NODE_ENV !== 'test' ? new BrowserWindow ( { show : false , width : 512 , height : 512 , frame : false , backgroundColor : '#DDDDDD' , } ) : null ; if ( splash ) { splash . loadURL ( url . format ( { pathname : path . join ( ROOT_DIRECTORY , 'icons' , 'icon.png' ) , protocol : 'file' , slashes : 'true' as unknown as boolean , } ) ) ; splash . once ( 'ready-to-show' , ( ) => { splash . show ( ) ; } ) ; } context . mainWindow = mainWindow ; mainWindow . once ( 'ready-to-show' , ( ) => { mainWindow . show ( ) ; if ( splash ) splash . close ( ) ; } ) ; mainWindow . loadURL ( isPackaged || ( process . env . NODE_ENV === 'test' && ! INTEGRATION_DEV ) ? getStartUrl ( ) : 'http://localhost:3000' ) ; if ( useDevtools ) await installDevtools ( ) ; mainWindow . on ( 'close' , e => { if ( context . mainWindow ) { e . preventDefault ( ) ; mainWindow . webContents . send ( 'app-close' ) ; } } ) ; mainWindow . on ( 'closed' , function ( ) { context . mainWindow = null ; } ) ; } app . whenReady ( ) . then ( ( ) => { protocol . registerFileProtocol ( 'file' , ( request , callback ) => { const pathname = decodeURI ( request . url . replace ( 'file:///' , '' ) ) ; callback ( pathname ) ; } ) ; } ) ; app . on ( 'ready' , ( ) => { createWindow ( ) ; setUpMenu ( context . mainWindow as BrowserWindow , true ) ; handleMessages ( context . mainWindow as BrowserWindow ) ; } ) ; app . on ( 'will-quit' , ( ) => { } ) ; app . on ( 'window-all-closed' , function ( ) { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , function ( ) { if ( context . mainWindow === null ) { createWindow ( ) ; } } ) ; ipcMain . on ( 'closed' , function ( ) { context . mainWindow = null ; app . quit ( ) ; } ) ;