99using System ;
1010using System . ComponentModel ;
1111using System . Threading ;
12+ using System . Windows . Interop ;
13+ using Flow . Launcher . Plugin ;
1214
1315namespace Flow . Launcher . Infrastructure . Http
1416{
@@ -18,6 +20,8 @@ public static class Http
1820
1921 private static HttpClient client = new HttpClient ( ) ;
2022
23+ public static IPublicAPI API { get ; set ; }
24+
2125 static Http ( )
2226 {
2327 // need to be added so it would work on a win10 machine
@@ -50,25 +54,36 @@ public static HttpProxy Proxy
5054 /// </summary>
5155 public static void UpdateProxy ( ProxyProperty property )
5256 {
53- ( WebProxy . Address , WebProxy . Credentials ) = property switch
57+ if ( string . IsNullOrEmpty ( Proxy . Server ) )
58+ return ;
59+
60+ try
5461 {
55- ProxyProperty . Enabled => Proxy . Enabled switch
62+ ( WebProxy . Address , WebProxy . Credentials ) = property switch
5663 {
57- true => Proxy . UserName switch
64+ ProxyProperty . Enabled => Proxy . Enabled switch
5865 {
59- var userName when ! string . IsNullOrEmpty ( userName ) =>
60- ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") , null ) ,
61- _ => ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") ,
62- new NetworkCredential ( Proxy . UserName , Proxy . Password ) )
66+ true when ! string . IsNullOrEmpty ( Proxy . Server ) => Proxy . UserName switch
67+ {
68+ var userName when string . IsNullOrEmpty ( userName ) =>
69+ ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") , null ) ,
70+ _ => ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") ,
71+ new NetworkCredential ( Proxy . UserName , Proxy . Password ) )
72+ } ,
73+ _ => ( null , null )
6374 } ,
64- false => ( null , null )
65- } ,
66- ProxyProperty . Server => ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") , WebProxy . Credentials ) ,
67- ProxyProperty . Port => ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") , WebProxy . Credentials ) ,
68- ProxyProperty . UserName => ( WebProxy . Address , new NetworkCredential ( Proxy . UserName , Proxy . Password ) ) ,
69- ProxyProperty . Password => ( WebProxy . Address , new NetworkCredential ( Proxy . UserName , Proxy . Password ) ) ,
70- _ => throw new ArgumentOutOfRangeException ( )
71- } ;
75+ ProxyProperty . Server => ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") , WebProxy . Credentials ) ,
76+ ProxyProperty . Port => ( new Uri ( $ "http://{ Proxy . Server } :{ Proxy . Port } ") , WebProxy . Credentials ) ,
77+ ProxyProperty . UserName => ( WebProxy . Address , new NetworkCredential ( Proxy . UserName , Proxy . Password ) ) ,
78+ ProxyProperty . Password => ( WebProxy . Address , new NetworkCredential ( Proxy . UserName , Proxy . Password ) ) ,
79+ _ => throw new ArgumentOutOfRangeException ( )
80+ } ;
81+ }
82+ catch ( UriFormatException e )
83+ {
84+ API . ShowMsg ( "Please try again" , "Unable to parse Http Proxy" ) ;
85+ Log . Exception ( "Flow.Launcher.Infrastructure.Http" , "Unable to parse Uri" , e ) ;
86+ }
7287 }
7388
7489 public static async Task DownloadAsync ( [ NotNull ] string url , [ NotNull ] string filePath , CancellationToken token = default )
0 commit comments