import _debug from 'debug' ; import { BrowserWindow , ipcMain , powerMonitor , session } from 'electron' ; import IPreferences from '../../shared/interface/IPreferences' ; const debug = _debug ( 'dev:preference' ) ; let mainWindow ; function setProxy ( proxyRules ) { debug ( 'Apply proxy: %s' , proxyRules ) ; session . defaultSession . setProxy ( { proxyRules , pacScript : '' , proxyBypassRules : '' , } ) ; } function setProxyFromStore ( ) { const preferences = storage . get ( 'preferences' ) ; if ( preferences ) { const { proxy , disableProxy } = preferences ; if ( ! disableProxy ) { setProxy ( proxy ) ; } } } export default ( win ) => { mainWindow = win ; powerMonitor . on ( 'suspend' , ( ) => { mainWindow . webContents . send ( 'player-pause' ) ; } ) ; ipcMain . on ( 'setProxy' , ( _event , args ) => { setProxy ( args ) ; } ) ; ipcMain . on ( 'update-preferences' , ( _event , args = { } ) => { const { disableProxy , proxy , alwaysOnTop } = args ; if ( disableProxy ) { setProxy ( '' ) ; } else { setProxy ( proxy ) ; } win . setAlwaysOnTop ( ! ! alwaysOnTop ) ; } ) ; } ;