import { app , LoginItemSettings } from 'electron' ; import { isMac } from '../common/env' ; import { logger } from '../common/logger' ; import { CloudConfigDataTypes , config , IConfig } from './config-handler' ; const { autoLaunchPath } = config . getConfigFields ( [ 'autoLaunchPath' ] ) ; const props = isMac ? { mac : { useLaunchAgent : true , } , name : 'Symphony' , path : process . execPath , } : { name : 'Symphony' , path : autoLaunchPath ? autoLaunchPath . replace ( /\//g , '\\' ) : null || process . execPath , } ; class AutoLaunchController { return { Promise < void > } public enableAutoLaunch ( ) { const { userDataPath } = config . getConfigFields ( [ 'userDataPath' ] ) ; if ( userDataPath === '' ) { app . setLoginItemSettings ( { openAtLogin : true , path : props . path } ) ; } else { app . setLoginItemSettings ( { openAtLogin : true , path : props . path , args : [ '--userDataPath="' + userDataPath + '"' ] , } ) ; } logger . info ( `auto-launch-controller: Enabled auto launch!` ) ; } return { Promise < void > } public disableAutoLaunch ( ) { app . setLoginItemSettings ( { openAtLogin : false , path : props . path } ) ; logger . info ( `auto-launch-controller: Disabled auto launch!` ) ; } return { Boolean } public isAutoLaunchEnabled ( ) { return app . getLoginItemSettings ( ) ; } /**
     * Validates the user config and enables auto launch
     */ public async handleAutoLaunch ( ) { const { launchOnStartup } = config . getConfigFields ( [ 'launchOnStartup' , ] ) ; const { openAtLogin : isAutoLaunchEnabled , } = this . isAutoLaunchEnabled ( ) ; if ( launchOnStartup === CloudConfigDataTypes . ENABLED ) { if ( ! isAutoLaunchEnabled ) { this . enableAutoLaunch ( ) ; } return ; } if ( isAutoLaunchEnabled ) { this . disableAutoLaunch ( ) ; } } } const autoLaunchInstance = new AutoLaunchController ( ) ; export { autoLaunchInstance } ;