9
9
using System ;
10
10
using System . ComponentModel ;
11
11
using System . Threading ;
12
+ using System . Windows . Interop ;
13
+ using Flow . Launcher . Plugin ;
12
14
13
15
namespace Flow . Launcher . Infrastructure . Http
14
16
{
@@ -18,6 +20,8 @@ public static class Http
18
20
19
21
private static HttpClient client = new HttpClient ( ) ;
20
22
23
+ public static IPublicAPI API { get ; set ; }
24
+
21
25
static Http ( )
22
26
{
23
27
// need to be added so it would work on a win10 machine
@@ -50,25 +54,36 @@ public static HttpProxy Proxy
50
54
/// </summary>
51
55
public static void UpdateProxy ( ProxyProperty property )
52
56
{
53
- ( WebProxy . Address , WebProxy . Credentials ) = property switch
57
+ if ( string . IsNullOrEmpty ( Proxy . Server ) )
58
+ return ;
59
+
60
+ try
54
61
{
55
- ProxyProperty . Enabled => Proxy . Enabled switch
62
+ ( WebProxy . Address , WebProxy . Credentials ) = property switch
56
63
{
57
- true => Proxy . UserName switch
64
+ ProxyProperty . Enabled => Proxy . Enabled switch
58
65
{
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 )
63
74
} ,
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
+ }
72
87
}
73
88
74
89
public static async Task DownloadAsync ( [ NotNull ] string url , [ NotNull ] string filePath , CancellationToken token = default )
0 commit comments