import { IpcEvents } from '@nuclear/core' ; import { IpcMessageEvent } from 'electron' ; import { inject } from 'inversify' ; import Config from '../services/config' ; import HttpApi from '../services/http' ; import NuclearApi from '../interfaces/nuclear-api' ; import Store from '../services/store' ; import SystemApi from '../services/system-api' ; import Window from '../services/window' ; import { ipcEvent , ipcController } from '../utils/decorators' ; @ ipcController ( ) class SettingsIpcCtrl { constructor ( @ inject ( Config ) private config , @ inject ( HttpApi ) private httpApi , @ inject ( SystemApi ) private systemApi , @ inject ( Store ) private store , @ inject ( Window ) private window ) { } @ ipcEvent ( IpcEvents . STARTED , { once : true } ) onStart ( ) { this . store . getOption ( 'api.enabled' ) && this . httpApi . listen ( ) ; this . systemApi . listen ( ) ; } @ ipcEvent ( IpcEvents . WINDOW_CLOSE ) async onClose ( ) { this . window . close ( ) ; } @ ipcEvent ( IpcEvents . WINDOW_MINIMIZE ) onMinimize ( ) { this . window . minimize ( ) ; } @ ipcEvent ( IpcEvents . WINDOW_MAXIMIZE ) onMaximize ( ) { this . window . maximize ( ) ; } @ ipcEvent ( IpcEvents . WINDOW_OPEN_DEVTOOLS ) openDevtools ( ) { this . window . openDevTools ( ) ; } @ ipcEvent ( IpcEvents . API_RESTART ) async restartHttpApi ( ) { await this . httpApi . close ( ) ; this . httpApi . listen ( ) ; } @ ipcEvent ( IpcEvents . API_STOP ) closeHttpServer ( ) { return this . httpApi . close ( ) ; } @ ipcEvent ( IpcEvents . CONNECTIVITY ) toggleConnectivity ( event , isConnected ) { this . config . setConnectivity ( isConnected ) ; } } export default SettingsIpcCtrl ;