@@ -7,6 +7,7 @@ use crate::config::Config;
77const LINUX_SCRIPT : & str = include_str ! ( "../scripts/proxy_set_linux_sh" ) ;
88const MACOS_SCRIPT : & str = include_str ! ( "../scripts/proxy_set_osx_sh" ) ;
99
10+ #[ cfg( all( not( target_os = "android" ) , not( target_os = "ios" ) ) ) ]
1011pub fn enable_system_proxy ( cfg : & Config ) -> Result < ( ) , Error > {
1112 #[ cfg( target_os = "windows" ) ]
1213 {
@@ -26,6 +27,7 @@ pub fn enable_system_proxy(cfg: &Config) -> Result<(), Error> {
2627 Err ( e) => Err ( e) ,
2728 }
2829 }
30+
2931 #[ cfg( target_os = "macos" ) ]
3032 {
3133 run_script (
@@ -39,8 +41,23 @@ pub fn enable_system_proxy(cfg: &Config) -> Result<(), Error> {
3941 )
4042 } )
4143 }
44+
45+ #[ cfg( all( unix, not( target_os = "macos" ) ) ) ]
46+ {
47+ run_script (
48+ LINUX_SCRIPT ,
49+ & [ "manual" , & cfg. listen_host , & cfg. lister_port . to_string ( ) ] ,
50+ )
51+ . map_err ( |e| {
52+ Error :: new (
53+ ErrorKind :: Other ,
54+ format ! ( "Failed to enable system proxy: {}" , e) ,
55+ )
56+ } )
57+ }
4258}
4359
60+ #[ cfg( all( not( target_os = "android" ) , not( target_os = "ios" ) ) ) ]
4461pub fn disable_system_proxy ( ) -> Result < ( ) , Error > {
4562 #[ cfg( target_os = "windows" ) ]
4663 {
@@ -57,6 +74,7 @@ pub fn disable_system_proxy() -> Result<(), Error> {
5774 Err ( e) => Err ( e) ,
5875 }
5976 }
77+
6078 #[ cfg( target_os = "macos" ) ]
6179 {
6280 run_script ( MACOS_SCRIPT , & [ "clear" ] ) . map_err ( |e| {
@@ -66,8 +84,19 @@ pub fn disable_system_proxy() -> Result<(), Error> {
6684 )
6785 } )
6886 }
87+
88+ #[ cfg( all( unix, not( target_os = "macos" ) ) ) ]
89+ {
90+ run_script ( LINUX_SCRIPT , & [ "none" ] ) . map_err ( |e| {
91+ Error :: new (
92+ ErrorKind :: Other ,
93+ format ! ( "Failed to enable system proxy: {}" , e) ,
94+ )
95+ } )
96+ }
6997}
7098
99+ #[ cfg( all( not( target_os = "android" ) , not( target_os = "ios" ) ) ) ]
71100fn run_script ( script_content : & str , args : & [ & str ] ) -> std:: io:: Result < ( ) > {
72101 let script_path = std:: env:: temp_dir ( ) . join ( "proxy_script.sh" ) ;
73102 fs:: write ( & script_path, script_content) ?;
0 commit comments