import execSync from './execSync' ; const networkTypes = [ 'Ethernet' , 'Thunderbolt Ethernet' , 'Wi-Fi' ] ; const getNetworkType = ( ) => { for ( let i = 0 ; i < networkTypes . length ; i ++ ) { const type = networkTypes [ i ] ; const result = execSync ( `networksetup -getwebproxy ${ type }` ) ; if ( result . status === 0 ) { return type ; } } throw new Error ( 'Unknown network type' ) ; } ; export const enableGlobalProxy = ( ip , port ) => { const networkType = getNetworkType ( ) ; execSync ( `networksetup -setwebproxy ${ networkType } ${ ip } ${ port }` ) ; execSync ( `networksetup -setsecurewebproxy ${ networkType } ${ ip } ${ port }` ) ; } ; export const disableGlobalProxy = ( ) => { const networkType = getNetworkType ( ) ; execSync ( `networksetup -setwebproxystate ${ networkType } off` ) ; execSync ( `networksetup -setsecurewebproxystate ${ networkType } off` ) ; } ;