/**
 * Module handles configurable splashscreen to show while app is loading.
 */ import { BrowserWindow } from "electron" ; ignore let splashScreenTimestamp = 0 ; ignore let splashScreenReady = false ; ignore let slowStartup = false ; ignore let done = false ; ignore const showSplash = ( ) => { if ( splashScreen && splashScreenReady && slowStartup ) { splashScreen . show ( ) ; splashScreenTimestamp = Date . now ( ) ; } } ; ignore const closeSplashScreen = ( main , min ) : void => { if ( splashScreen ) { const timeout = min - ( Date . now ( ) - splashScreenTimestamp ) ; setTimeout ( ( ) => { done = true ; if ( splashScreen ) { splashScreen . isDestroyed ( ) || splashScreen . close ( ) ; splashScreen = null ; } main . show ( ) ; } , timeout ) ; } } ; /** `electron-splashscreen` config object. */ export interface Config { /** Options for the window that is loading and having a splashscreen tied to. */ windowOpts : Electron . BrowserWindowConstructorOptions ; /**
     * URL to the splashscreen template. This is the path to an `HTML` or `SVG` file.
     * If you want to simply show a `PNG`, wrap it in an `HTML` file.
     */ templateUrl : string ; /**
     * Full set of browser window options for the splashscreen. We override key attributes to
     * make it look & feel like a splashscreen; the rest is up to you!
     */ splashScreenOpts : Electron . BrowserWindowConstructorOptions ; /** Number of ms the window will load before splashscreen appears (default: 500ms). */ delay ? : number ; /** Minimum ms the splashscreen will be visible (default: 500ms). */ minVisible ? : number ; /** Close window that is loading if splashscreen is closed by user (default: true). */ closeWindow ? : boolean ; } ignore let splashScreen ; param config returns { BrowserWindow } export const initSplashScreen = ( config ) : BrowserWindow => { const xConfig = { windowOpts : config . windowOpts , templateUrl : config . templateUrl , splashScreenOpts : config . splashScreenOpts , delay : config . delay ?? 500 , minVisible : config . minVisible ?? 500 , closeWindow : config . closeWindow ?? true , } ; xConfig . splashScreenOpts . frame = false ; xConfig . splashScreenOpts . center = true ; xConfig . splashScreenOpts . show = false ; xConfig . windowOpts . show = false ; const window = new BrowserWindow ( xConfig . windowOpts ) ; splashScreen = new BrowserWindow ( xConfig . splashScreenOpts ) ; splashScreen . loadURL ( `file://${ xConfig . templateUrl }` ) ; xConfig . closeWindow && splashScreen . on ( "close" , ( ) => { if ( window ) { done || window . isDestroyed ( ) || window . close ( ) ; } } ) ; splashScreen . webContents . on ( "did-finish-load" , ( ) => { splashScreenReady = true ; showSplash ( ) ; } ) ; setTimeout ( ( ) => { slowStartup = true ; showSplash ( ) ; } , xConfig . delay ) ; window . webContents . on ( "did-finish-load" , ( ) : void => { closeSplashScreen ( window , xConfig . minVisible ) ; } ) ; return window ; } ; /** Return object for `initDynamicSplashScreen()`. */ export interface DynamicSplashScreen { /** The main browser window ready for loading */ main : BrowserWindow ; /** The splashscreen browser window so you can communicate with splashscreen in more complex use cases. */ splashScreen : Electron . BrowserWindow ; } param config returns { DynamicSplashScreen } export const initDynamicSplashScreen = ( config ) : DynamicSplashScreen => { return { main : initSplashScreen ( config ) , splashScreen : splashScreen as Electron . BrowserWindow , } ; } ;