import { NuclearMeta , IpcEvents } from '@nuclear/core' ; import { IpcMessageEvent } from 'electron' ; import { inject } from 'inversify' ; import NuclearApi from '../interfaces/nuclear-api' ; import SystemApi from '../services/system-api' ; import Window from '../services/window' ; import { ipcEvent , ipcController } from '../utils/decorators' ; import Discord from '../services/discord' ; import TrayMenu from '../services/trayMenu' ; @ ipcController ( ) class IpcPlayer { constructor ( @ inject ( Discord ) private discord , @ inject ( TrayMenu ) private trayMenu , @ inject ( SystemApi ) private systemApi , @ inject ( Window ) private window ) { } @ ipcEvent ( IpcEvents . PLAY ) onPlay ( ) { this . systemApi . play ( ) ; this . trayMenu . update ( { isPlaying : true } ) ; return this . discord . play ( ) ; } @ ipcEvent ( IpcEvents . PAUSE ) onPause ( ) { this . systemApi . pause ( ) ; this . trayMenu . update ( { isPlaying : false } ) ; return this . discord . pause ( ) ; } @ ipcEvent ( IpcEvents . VOLUME ) onVolume ( evt , data ) { this . systemApi . setVolume && this . systemApi . setVolume ( data ) ; } @ ipcEvent ( IpcEvents . LOOP ) onLoop ( evt , data ) { this . systemApi . setLoopStatus && this . systemApi . setLoopStatus ( data ) ; } @ ipcEvent ( IpcEvents . SHUFFLE ) onShuffle ( evt , data ) { this . systemApi . shuffle = data ; } @ ipcEvent ( IpcEvents . TRACK_ADD ) onAddTrack ( evt , track ) { this . systemApi . addTrack && this . systemApi . addTrack ( track ) ; } @ ipcEvent ( IpcEvents . TRACK_REMOVE ) onRemoveTrack ( evt , { uuid } ) { this . systemApi . removeTrack && this . systemApi . removeTrack ( uuid ) ; } @ ipcEvent ( IpcEvents . QUEUE_CLEAR ) onClearTrackList ( ) { this . systemApi . clearTrackList && this . systemApi . clearTrackList ( ) ; this . discord . clear ( ) ; this . trayMenu . update ( { isPlaying : false , track : null } ) ; } @ ipcEvent ( IpcEvents . SONG_CHANGE ) onSongChange ( evt , arg ) { if ( arg === null ) { return ; } this . window . setTitle ( `${ arg . artist } - ${ arg . name } - Nuclear Music Player` ) ; this . systemApi . sendMetadata && this . systemApi . sendMetadata ( arg ) ; this . discord . trackChange ( arg ) ; this . trayMenu . update ( { track : arg } ) ; } } export default IpcPlayer ;