1- using Flow . Launcher . Infrastructure . Http ;
21using Flow . Launcher . Infrastructure . Logger ;
32using System ;
43using System . Collections . Generic ;
4+ using System . Net ;
5+ using System . Net . Http ;
56using System . Text . Json ;
67using System . Threading ;
78using System . Threading . Tasks ;
@@ -10,43 +11,45 @@ namespace Flow.Launcher.Core.ExternalPlugins
1011{
1112 public static class PluginsManifest
1213 {
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" ;
1915
20- public static Task UpdateTask { get ; private set ; }
16+ private static HttpClient httpClient = new HttpClient ( ) ;
2117
2218 private static readonly SemaphoreSlim manifestUpdateLock = new ( 1 ) ;
2319
24- public static Task UpdateManifestAsync ( )
25- {
26- if ( manifestUpdateLock . CurrentCount == 0 )
27- {
28- return UpdateTask ;
29- }
20+ private static string latestEtag = "" ;
3021
31- return UpdateTask = DownloadManifestAsync ( ) ;
32- }
22+ public static List < UserPlugin > UserPlugins { get ; private set ; } = new List < UserPlugin > ( ) ;
3323
34- private static async Task DownloadManifestAsync ( )
24+ public static async Task UpdateManifestAsync ( )
3525 {
3626 try
3727 {
3828 await manifestUpdateLock . WaitAsync ( ) . ConfigureAwait ( false ) ;
3929
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") ;
4238
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+ }
4449 }
4550 catch ( Exception e )
4651 {
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 ) ;
5053 }
5154 finally
5255 {
0 commit comments