From d5622367ccb82485e35e7956bc048dd7ae933f4f Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sat, 13 Jan 2024 23:49:08 -0600 Subject: [PATCH] ignore null datetimes for pluginstoreitem --- .../ExternalPlugins/CommunityPluginSource.cs | 19 +++++++++++++++---- .../ExternalPlugins/UserPlugin.cs | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs b/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs index d3ee4695c..68be746f2 100644 --- a/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs +++ b/Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; @@ -16,6 +18,11 @@ namespace Flow.Launcher.Core.ExternalPlugins private List plugins = new(); + private static JsonSerializerOptions PluginStoreItemSerializationOption = new JsonSerializerOptions() + { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault + }; + /// /// Fetch and deserialize the contents of a plugins.json file found at . /// 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); - 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) { - this.plugins = await response.Content.ReadFromJsonAsync>(cancellationToken: token).ConfigureAwait(false); - this.latestEtag = response.Headers.ETag.Tag; + this.plugins = await response.Content + .ReadFromJsonAsync>(PluginStoreItemSerializationOption, cancellationToken: token) + .ConfigureAwait(false); + this.latestEtag = response.Headers.ETag?.Tag; Log.Info(nameof(CommunityPluginSource), $"Loaded {this.plugins.Count} plugins from {ManifestFileUrl}"); return this.plugins; @@ -49,7 +59,8 @@ namespace Flow.Launcher.Core.ExternalPlugins } 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}"); } } diff --git a/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs index bb1279b2c..64c4cd627 100644 --- a/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs +++ b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs @@ -14,8 +14,8 @@ namespace Flow.Launcher.Core.ExternalPlugins public string UrlDownload { get; set; } public string UrlSourceCode { get; set; } public string IcoPath { get; set; } - public DateTime LatestReleaseDate { get; set; } - public DateTime DateAdded { get; set; } + public DateTime? LatestReleaseDate { get; set; } + public DateTime? DateAdded { get; set; } } }