/**
 * This module executes inside of electron's main process. You can start
 * electron renderer process from here and communicate with the other processes
 * through IPC.
 *
 * When running `yarn build` or `yarn build-main`, this file is compiled to
 * `./app/main.prod.js` using webpack. This gives us some performance wins.
 */ import 'core-js/stable' ; import 'regenerator-runtime/runtime' ; import { app , BrowserWindow , session } from 'electron' ; import log from 'electron-log' ; import path from 'path' ; import { isDarwin } from './helpers/env' ; import AutoUpdater from './main/AutoUpdater' ; import AutoLaunch from './main/AutoLaunch' ; import NotificationCenter from './main/NotificationCenter' ; import Tray from './main/Tray' ; import MenuBuilder from './main/menu' ; import Migrate from './modules/settings/Migrate' ; log . debug ( 'App starting...' ) ; let mainWindow = null ; let isQuitting = false ; function setQuitState ( state ) { isQuitting = state ; } if ( process . env . NODE_ENV === 'production' ) { const sourceMapSupport = require ( 'source-map-support' ) ; sourceMapSupport . install ( ) ; } if ( process . env . NODE_ENV === 'development' || process . env . DEBUG_PROD === 'true' ) { require ( 'electron-debug' ) ( ) ; } const installExtensions = async ( ) => { const installer = require ( 'electron-devtools-installer' ) ; const forceDownload = ! ! process . env . UPGRADE_EXTENSIONS ; const extensions = [ 'REACT_DEVELOPER_TOOLS' , 'REDUX_DEVTOOLS' ] ; return installer . default ( extensions . map ( ( name ) => installer [ name ] ) , forceDownload ) . catch ( console . log ) ; } ; const createWindow = async ( ) => { await new Migrate ( ) ; if ( process . env . NODE_ENV === 'development' || process . env . DEBUG_PROD === 'true' ) { await installExtensions ( ) ; } const RESOURCES_PATH = app . isPackaged ? path . join ( process . resourcesPath , 'resources' ) : path . join ( __dirname , '../resources' ) ; const getAssetPath = ( ... paths ) : string => { return path . join ( RESOURCES_PATH , ... paths ) ; } ; mainWindow = new BrowserWindow ( { show : true , center : true , width : 550 , height : 600 , minHeight : 550 , minWidth : 600 , fullscreenable : false , icon : getAssetPath ( 'icon.png' ) , webPreferences : { nodeIntegration : true , enableRemoteModule : true } } ) ; mainWindow . loadURL ( `file://${ __dirname }/app.html` ) ; mainWindow . webContents . on ( 'did-finish-load' , ( ) => { if ( ! mainWindow ) { throw new Error ( '"mainWindow" is not defined' ) ; } if ( process . env . START_MINIMIZED ) { mainWindow . minimize ( ) ; } else { mainWindow . show ( ) ; mainWindow . focus ( ) ; } } ) ; mainWindow . on ( 'closed' , ( ) => { mainWindow = null ; } ) ; mainWindow . on ( 'close' , ( event ) => { if ( ! isQuitting ) { event . preventDefault ( ) ; mainWindow . hide ( ) ; } } ) ; const notificationCenter = new NotificationCenter ( ) ; new AutoLaunch ( ) ; new AutoUpdater ( setQuitState ) ; const menuBuilder = new MenuBuilder ( mainWindow ) ; menuBuilder . buildMenu ( ) ; new Tray ( mainWindow , notificationCenter ) ; } ; /**
 * Add event listeners...
 */ app . on ( 'window-all-closed' , ( ) => { if ( ! isDarwin ) { app . quit ( ) ; } } ) ; app . on ( 'before-quit' , ( ) => { console . log ( 'CALLED beforequit' ) ; setQuitState ( true ) ; } ) ; app . on ( 'ready' , createWindow ) ; app . on ( 'activate' , ( ) => { if ( mainWindow === null ) createWindow ( ) ; } ) ;