ignore null datetimes for pluginstoreitem

This commit is contained in:
Hongtao Zhang 2024-01-13 23:49:08 -06:00
parent 2c965b1800
commit d5622367cc
2 changed files with 17 additions and 6 deletions

View file

@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,6 +18,11 @@ namespace Flow.Launcher.Core.ExternalPlugins
private List<UserPlugin> plugins = new(); private List<UserPlugin> plugins = new();
private static JsonSerializerOptions PluginStoreItemSerializationOption = new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
};
/// <summary> /// <summary>
/// Fetch and deserialize the contents of a plugins.json file found at <see cref="ManifestFileUrl"/>. /// Fetch and deserialize the contents of a plugins.json file found at <see cref="ManifestFileUrl"/>.
/// We use conditional http requests to keep repeat requests fast. /// We use conditional http requests to keep repeat requests fast.
@ -32,12 +39,15 @@ namespace Flow.Launcher.Core.ExternalPlugins
request.Headers.Add("If-None-Match", latestEtag); request.Headers.Add("If-None-Match", latestEtag);
using var response = await Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false); using var response = await Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token)
.ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK) if (response.StatusCode == HttpStatusCode.OK)
{ {
this.plugins = await response.Content.ReadFromJsonAsync<List<UserPlugin>>(cancellationToken: token).ConfigureAwait(false); this.plugins = await response.Content
this.latestEtag = response.Headers.ETag.Tag; .ReadFromJsonAsync<List<UserPlugin>>(PluginStoreItemSerializationOption, cancellationToken: token)
.ConfigureAwait(false);
this.latestEtag = response.Headers.ETag?.Tag;
Log.Info(nameof(CommunityPluginSource), $"Loaded {this.plugins.Count} plugins from {ManifestFileUrl}"); Log.Info(nameof(CommunityPluginSource), $"Loaded {this.plugins.Count} plugins from {ManifestFileUrl}");
return this.plugins; return this.plugins;
@ -49,7 +59,8 @@ namespace Flow.Launcher.Core.ExternalPlugins
} }
else else
{ {
Log.Warn(nameof(CommunityPluginSource), $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}"); Log.Warn(nameof(CommunityPluginSource),
$"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
throw new Exception($"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}"); throw new Exception($"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
} }
} }

View file

@ -14,8 +14,8 @@ namespace Flow.Launcher.Core.ExternalPlugins
public string UrlDownload { get; set; } public string UrlDownload { get; set; }
public string UrlSourceCode { get; set; } public string UrlSourceCode { get; set; }
public string IcoPath { get; set; } public string IcoPath { get; set; }
public DateTime LatestReleaseDate { get; set; } public DateTime? LatestReleaseDate { get; set; }
public DateTime DateAdded { get; set; } public DateTime? DateAdded { get; set; }
} }
} }