Skip to content

Commit 3648126

Browse files
committed
Revert JSON Null change + fix more warnings
See comment inline re:JSON null
1 parent b853991 commit 3648126

File tree

26 files changed

+158
-68
lines changed

26 files changed

+158
-68
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ public List<Result> LoadContextMenus(Result selectedResult)
6969
private static readonly JsonSerializerOptions options = new()
7070
{
7171
PropertyNameCaseInsensitive = true,
72-
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
72+
#pragma warning disable SYSLIB0020
73+
// IgnoreNullValues is obsolete, but the replacement JsonIgnoreCondition.WhenWritingNull still
74+
// deserializes null, instead of ignoring it and leaving the default (empty list). We can change the behaviour
75+
// to accept null and fallback to a default etc, or just keep IgnoreNullValues for now
76+
// see: https://github.com/dotnet/runtime/issues/39152
77+
IgnoreNullValues = true,
78+
#pragma warning restore SYSLIB0020 // Type or member is obsolete
7379
Converters =
7480
{
7581
new JsonObjectConverter()
@@ -82,12 +88,15 @@ public List<Result> LoadContextMenus(Result selectedResult)
8288
};
8389
private Dictionary<string, object> Settings { get; set; }
8490

85-
private Dictionary<string, FrameworkElement> _settingControls = new();
91+
private readonly Dictionary<string, FrameworkElement> _settingControls = new();
8692

8793
private async Task<List<Result>> DeserializedResultAsync(Stream output)
8894
{
8995
if (output == Stream.Null) return null;
9096

97+
var temp = System.Text.Encoding.UTF8.GetString(((MemoryStream)output).ToArray());
98+
System.Diagnostics.Debug.WriteLine(temp);
99+
91100
var queryResponseModel =
92101
await JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, options);
93102

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static async ValueTask DisposePluginsAsync()
7474
}
7575
}
7676

77-
public static async Task ReloadData()
77+
public static async Task ReloadDataAsync()
7878
{
7979
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
8080
{
@@ -327,4 +327,4 @@ public static void ReplaceActionKeyword(string id, string oldActionKeyword, stri
327327
}
328328
}
329329
}
330-
}
330+
}

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
4545
var assembly = assemblyLoader.LoadAssemblyAndDependencies();
4646
var type = assemblyLoader.FromAssemblyGetTypeOfInterface(assembly,
4747
typeof(IAsyncPlugin));
48-
48+
#pragma warning disable IDE0019 // "Use Pattern Matching" - disabled because the pattern is useful for RELEASE
4949
var plugin = Activator.CreateInstance(type) as IAsyncPlugin;
50+
#pragma warning restore IDE0019
51+
5052
#else
5153
Assembly assembly = null;
5254
IAsyncPlugin plugin = null;

Flow.Launcher.Core/Updater.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Net;
44
using System.Net.Http;
@@ -40,7 +40,7 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
4040
api.ShowMsg(api.GetTranslation("pleaseWait"),
4141
api.GetTranslation("update_flowlauncher_update_check"));
4242

43-
using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false);
43+
using var updateManager = await GitHubUpdateManagerAsync(GitHubRepository).ConfigureAwait(false);
4444

4545
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
4646
var newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false);
@@ -115,7 +115,7 @@ private class GithubRelease
115115
}
116116

117117
/// https://github.com/Squirrel/Squirrel.Windows/blob/master/src/Squirrel/UpdateManager.Factory.cs
118-
private async Task<UpdateManager> GitHubUpdateManager(string repository)
118+
private async Task<UpdateManager> GitHubUpdateManagerAsync(string repository)
119119
{
120120
var uri = new Uri(repository);
121121
var api = $"https://api.github.com/repos{uri.AbsolutePath}/releases";
@@ -145,4 +145,4 @@ public string NewVersinoTips(string version)
145145
}
146146

147147
}
148-
}
148+
}

Flow.Launcher.Infrastructure/Exception/ExceptionFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static string CreateExceptionReport(System.Exception ex)
7878
sb.AppendLine();
7979
sb.AppendLine("## Assemblies - " + AppDomain.CurrentDomain.FriendlyName);
8080
sb.AppendLine();
81-
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies().OrderBy(o => o.GlobalAssemblyCache ? 50 : 0))
81+
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
8282
{
8383
sb.Append("* ");
8484
sb.Append(ass.FullName);

Flow.Launcher.Infrastructure/Image/ImageHashGenerator.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,23 @@ public class ImageHashGenerator : IImageHashGenerator
1414
{
1515
public string GetHashFromImage(ImageSource imageSource)
1616
{
17-
if (!(imageSource is BitmapSource image))
17+
if (imageSource is not BitmapSource image)
1818
{
1919
return null;
2020
}
2121

2222
try
2323
{
24-
using (var outStream = new MemoryStream())
25-
{
26-
// PngBitmapEncoder enc2 = new PngBitmapEncoder();
27-
// enc2.Frames.Add(BitmapFrame.Create(tt));
28-
29-
var enc = new JpegBitmapEncoder();
30-
var bitmapFrame = BitmapFrame.Create(image);
31-
bitmapFrame.Freeze();
32-
enc.Frames.Add(bitmapFrame);
33-
enc.Save(outStream);
34-
var byteArray = outStream.GetBuffer();
35-
using (var sha1 = new SHA1CryptoServiceProvider())
36-
{
37-
var hash = Convert.ToBase64String(sha1.ComputeHash(byteArray));
38-
return hash;
39-
}
40-
}
24+
using var outStream = new MemoryStream();
25+
var enc = new JpegBitmapEncoder();
26+
var bitmapFrame = BitmapFrame.Create(image);
27+
bitmapFrame.Freeze();
28+
enc.Frames.Add(bitmapFrame);
29+
enc.Save(outStream);
30+
var byteArray = outStream.GetBuffer();
31+
using var sha1 = SHA1.Create();
32+
var hash = Convert.ToBase64String(sha1.ComputeHash(byteArray));
33+
return hash;
4134
}
4235
catch
4336
{
@@ -46,4 +39,4 @@ public string GetHashFromImage(ImageSource imageSource)
4639

4740
}
4841
}
49-
}
42+
}

Flow.Launcher.Infrastructure/Image/ImageLoader.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace Flow.Launcher.Infrastructure.Image
1313
{
1414
public static class ImageLoader
1515
{
16-
private static readonly ImageCache ImageCache = new ImageCache();
16+
private static readonly ImageCache ImageCache = new();
1717
private static BinaryStorage<Dictionary<string, int>> _storage;
18-
private static readonly ConcurrentDictionary<string, string> GuidToKey = new ConcurrentDictionary<string, string>();
18+
private static readonly ConcurrentDictionary<string, string> GuidToKey = new();
1919
private static IImageHashGenerator _hashGenerator;
20-
private static bool EnableImageHash = true;
20+
private static readonly bool EnableImageHash = true;
2121
public static ImageSource DefaultImage { get; } = new BitmapImage(new Uri(Constant.MissingImgIcon));
2222

2323

@@ -243,7 +243,6 @@ public static ImageSource Load(string path, bool loadFullImage = false)
243243
ImageCache[path] = img;
244244
}
245245

246-
247246
return img;
248247
}
249248

Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Flow.Launcher.Infrastructure.Storage
1111
{
12+
#pragma warning disable SYSLIB0011 // BinaryFormatter is obsolete.
1213
/// <summary>
1314
/// Stroage object using binary data
1415
/// Normally, it has better performance, but not readable
@@ -113,4 +114,5 @@ public void Save(T data)
113114
}
114115
}
115116
}
117+
#pragma warning enable SYSLIB0011
116118
}

Flow.Launcher.Plugin/AllowedLanguage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Flow.Launcher.Plugin
22
{
3+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
34
public static class AllowedLanguage
45
{
56
public static string Python
@@ -35,4 +36,5 @@ public static bool IsAllowed(string language)
3536
|| language.ToUpper() == Executable.ToUpper();
3637
}
3738
}
38-
}
39+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
40+
}

Flow.Launcher.Plugin/BaseModel.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@
44

55
namespace Flow.Launcher.Plugin
66
{
7+
/// <summary>
8+
/// Base model for plugin classes
9+
/// </summary>
710
public class BaseModel : INotifyPropertyChanged
811
{
12+
/// <summary>
13+
/// Property changed event handler
14+
/// </summary>
915
public event PropertyChangedEventHandler PropertyChanged;
1016

17+
/// <summary>
18+
/// Invoked when a property changes
19+
/// </summary>
20+
/// <param name="propertyName"></param>
1121
[NotifyPropertyChangedInvocator]
1222
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
1323
{
1424
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
1525
}
1626
}
17-
}
27+
}

0 commit comments

Comments
 (0)