1- namespace v2rayN . Desktop . Handler
1+ using v2rayN . Desktop . Common ;
2+
3+ namespace v2rayN . Desktop . Handler
24{
35 public static class SysProxyHandler
46 {
@@ -14,48 +16,56 @@ public static async Task<bool> UpdateSysProxy(Config config, bool forceDisable)
1416 try
1517 {
1618 int port = LazyConfig . Instance . GetLocalPort ( EInboundProtocol . http ) ;
19+ int portSocks = LazyConfig . Instance . GetLocalPort ( EInboundProtocol . socks ) ;
20+ int portPac = LazyConfig . Instance . GetLocalPort ( EInboundProtocol . pac ) ;
1721 if ( port <= 0 )
1822 {
1923 return false ;
2024 }
2125 if ( type == ESysProxyType . ForcedChange )
2226 {
23- var strProxy = $ "{ Global . Loopback } :{ port } ";
24- await SetProxy ( strProxy ) ;
27+ if ( Utils . IsWindows ( ) )
28+ {
29+ //TODO
30+ }
31+ else if ( Utils . IsLinux ( ) )
32+ {
33+ await ProxySettingLinux . SetProxy ( Global . Loopback , port ) ;
34+ }
35+ else if ( Utils . IsOSX ( ) )
36+ {
37+ await ProxySettingOSX . SetProxy ( Global . Loopback , port ) ;
38+ }
2539 }
2640 else if ( type == ESysProxyType . ForcedClear )
2741 {
28- await UnsetProxy ( ) ;
42+ if ( Utils . IsWindows ( ) )
43+ {
44+ //TODO
45+ }
46+ else if ( Utils . IsLinux ( ) )
47+ {
48+ await ProxySettingLinux . UnsetProxy ( ) ;
49+ }
50+ else if ( Utils . IsOSX ( ) )
51+ {
52+ await ProxySettingOSX . UnsetProxy ( ) ;
53+ }
2954 }
30- else if ( type == ESysProxyType . Unchanged )
55+ else if ( type == ESysProxyType . Pac )
3156 {
3257 }
58+
59+ //if (type != ESysProxyType.Pac)
60+ //{
61+ // PacHandler.Stop();
62+ //}
3363 }
3464 catch ( Exception ex )
3565 {
3666 Logging . SaveLog ( ex . Message , ex ) ;
3767 }
3868 return true ;
3969 }
40-
41- private static async Task SetProxy ( string ? strProxy )
42- {
43- await Task . Run ( ( ) =>
44- {
45- var httpProxy = strProxy is null ? null : $ "{ Global . HttpProtocol } { strProxy } ";
46- var socksProxy = strProxy is null ? null : $ "{ Global . SocksProtocol } { strProxy } ";
47- var noProxy = $ "localhost,127.0.0.0/8,::1";
48-
49- Environment . SetEnvironmentVariable ( "http_proxy" , httpProxy , EnvironmentVariableTarget . User ) ;
50- Environment . SetEnvironmentVariable ( "https_proxy" , httpProxy , EnvironmentVariableTarget . User ) ;
51- Environment . SetEnvironmentVariable ( "all_proxy" , socksProxy , EnvironmentVariableTarget . User ) ;
52- Environment . SetEnvironmentVariable ( "no_proxy" , noProxy , EnvironmentVariableTarget . User ) ;
53- } ) ;
54- }
55-
56- private static async Task UnsetProxy ( )
57- {
58- await SetProxy ( null ) ;
59- }
6070 }
6171}
0 commit comments