1
- using Flow . Launcher . Infrastructure . Http ;
2
1
using Flow . Launcher . Infrastructure . Logger ;
3
2
using System ;
4
3
using System . Collections . Generic ;
4
+ using System . Net ;
5
+ using System . Net . Http ;
5
6
using System . Text . Json ;
6
7
using System . Threading ;
7
8
using System . Threading . Tasks ;
@@ -10,43 +11,45 @@ namespace Flow.Launcher.Core.ExternalPlugins
10
11
{
11
12
public static class PluginsManifest
12
13
{
13
- static PluginsManifest ( )
14
- {
15
- UpdateTask = UpdateManifestAsync ( ) ;
16
- }
17
-
18
- public static List < UserPlugin > UserPlugins { get ; private set ; } = new List < UserPlugin > ( ) ;
14
+ private const string manifestFileUrl = "https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json" ;
19
15
20
- public static Task UpdateTask { get ; private set ; }
16
+ private static HttpClient httpClient = new HttpClient ( ) ;
21
17
22
18
private static readonly SemaphoreSlim manifestUpdateLock = new ( 1 ) ;
23
19
24
- public static Task UpdateManifestAsync ( )
25
- {
26
- if ( manifestUpdateLock . CurrentCount == 0 )
27
- {
28
- return UpdateTask ;
29
- }
20
+ private static string latestEtag = "" ;
30
21
31
- return UpdateTask = DownloadManifestAsync ( ) ;
32
- }
22
+ public static List < UserPlugin > UserPlugins { get ; private set ; } = new List < UserPlugin > ( ) ;
33
23
34
- private static async Task DownloadManifestAsync ( )
24
+ public static async Task UpdateManifestAsync ( )
35
25
{
36
26
try
37
27
{
38
28
await manifestUpdateLock . WaitAsync ( ) . ConfigureAwait ( false ) ;
39
29
40
- await using var jsonStream = await Http . GetStreamAsync ( "https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json" )
41
- . ConfigureAwait ( false ) ;
30
+ var request = new HttpRequestMessage ( HttpMethod . Get , manifestFileUrl ) ;
31
+ request . Headers . Add ( "If-None-Match" , latestEtag ) ;
32
+
33
+ var response = await httpClient . SendAsync ( request ) . ConfigureAwait ( false ) ;
34
+
35
+ if ( response . StatusCode == HttpStatusCode . OK )
36
+ {
37
+ Log . Info ( $ "|PluginsManifest.{ nameof ( UpdateManifestAsync ) } |Fetched plugins from manifest repo") ;
42
38
43
- UserPlugins = await JsonSerializer . DeserializeAsync < List < UserPlugin > > ( jsonStream ) . ConfigureAwait ( false ) ;
39
+ var json = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
40
+
41
+ UserPlugins = await JsonSerializer . DeserializeAsync < List < UserPlugin > > ( json ) . ConfigureAwait ( false ) ;
42
+
43
+ latestEtag = response . Headers . ETag . Tag ;
44
+ }
45
+ else if ( response . StatusCode != HttpStatusCode . NotModified )
46
+ {
47
+ Log . Warn ( $ "|PluginsManifest.{ nameof ( UpdateManifestAsync ) } |Http response for manifest file was { response . StatusCode } ") ;
48
+ }
44
49
}
45
50
catch ( Exception e )
46
51
{
47
- Log . Exception ( "|PluginManagement.GetManifest|Encountered error trying to download plugins manifest" , e ) ;
48
-
49
- UserPlugins = new List < UserPlugin > ( ) ;
52
+ Log . Exception ( $ "|PluginsManifest.{ nameof ( UpdateManifestAsync ) } |Http request failed", e ) ;
50
53
}
51
54
finally
52
55
{
0 commit comments