Skip to content

Commit d562236

Browse files
committed
ignore null datetimes for pluginstoreitem
1 parent 2c965b1 commit d562236

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Net;
66
using System.Net.Http;
77
using System.Net.Http.Json;
8+
using System.Text.Json;
9+
using System.Text.Json.Serialization;
810
using System.Threading;
911
using System.Threading.Tasks;
1012

@@ -16,6 +18,11 @@ public record CommunityPluginSource(string ManifestFileUrl)
1618

1719
private List<UserPlugin> plugins = new();
1820

21+
private static JsonSerializerOptions PluginStoreItemSerializationOption = new JsonSerializerOptions()
22+
{
23+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
24+
};
25+
1926
/// <summary>
2027
/// Fetch and deserialize the contents of a plugins.json file found at <see cref="ManifestFileUrl"/>.
2128
/// We use conditional http requests to keep repeat requests fast.
@@ -32,12 +39,15 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
3239

3340
request.Headers.Add("If-None-Match", latestEtag);
3441

35-
using var response = await Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);
42+
using var response = await Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token)
43+
.ConfigureAwait(false);
3644

3745
if (response.StatusCode == HttpStatusCode.OK)
3846
{
39-
this.plugins = await response.Content.ReadFromJsonAsync<List<UserPlugin>>(cancellationToken: token).ConfigureAwait(false);
40-
this.latestEtag = response.Headers.ETag.Tag;
47+
this.plugins = await response.Content
48+
.ReadFromJsonAsync<List<UserPlugin>>(PluginStoreItemSerializationOption, cancellationToken: token)
49+
.ConfigureAwait(false);
50+
this.latestEtag = response.Headers.ETag?.Tag;
4151

4252
Log.Info(nameof(CommunityPluginSource), $"Loaded {this.plugins.Count} plugins from {ManifestFileUrl}");
4353
return this.plugins;
@@ -49,7 +59,8 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
4959
}
5060
else
5161
{
52-
Log.Warn(nameof(CommunityPluginSource), $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
62+
Log.Warn(nameof(CommunityPluginSource),
63+
$"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
5364
throw new Exception($"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
5465
}
5566
}

Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public record UserPlugin
1414
public string UrlDownload { get; set; }
1515
public string UrlSourceCode { get; set; }
1616
public string IcoPath { get; set; }
17-
public DateTime LatestReleaseDate { get; set; }
18-
public DateTime DateAdded { get; set; }
17+
public DateTime? LatestReleaseDate { get; set; }
18+
public DateTime? DateAdded { get; set; }
1919

2020
}
2121
}

0 commit comments

Comments
 (0)