Skip to content

Commit 8031ddf

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into AcronymFuzzy
2 parents 7ceb080 + d223d2c commit 8031ddf

File tree

79 files changed

+814
-1360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+814
-1360
lines changed
File renamed without changes.

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Reflection;
6+
using System.Text.Json;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using System.Windows.Forms;
9-
using Newtonsoft.Json;
1010
using Flow.Launcher.Infrastructure.Exception;
1111
using Flow.Launcher.Infrastructure.Logger;
1212
using Flow.Launcher.Plugin;
@@ -65,7 +65,7 @@ private List<Result> DeserializedResult(string output)
6565
{
6666
List<Result> results = new List<Result>();
6767

68-
JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject<JsonRPCQueryResponseModel>(output);
68+
JsonRPCQueryResponseModel queryResponseModel = JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output);
6969
if (queryResponseModel.Result == null) return null;
7070

7171
foreach (JsonRPCResult result in queryResponseModel.Result)
@@ -84,7 +84,7 @@ private List<Result> DeserializedResult(string output)
8484
else
8585
{
8686
string actionReponse = ExecuteCallback(result1.JsonRPCAction);
87-
JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject<JsonRPCRequestModel>(actionReponse);
87+
JsonRPCRequestModel jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionReponse);
8888
if (jsonRpcRequestModel != null
8989
&& !String.IsNullOrEmpty(jsonRpcRequestModel.Method)
9090
&& jsonRpcRequestModel.Method.StartsWith("Flow.Launcher."))

Flow.Launcher.Core/Plugin/PluginConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.IO;
5-
using Newtonsoft.Json;
65
using Flow.Launcher.Infrastructure;
76
using Flow.Launcher.Infrastructure.Logger;
87
using Flow.Launcher.Plugin;
8+
using System.Text.Json;
99

1010
namespace Flow.Launcher.Core.Plugin
1111
{
@@ -61,7 +61,7 @@ private static PluginMetadata GetPluginMetadata(string pluginDirectory)
6161
PluginMetadata metadata;
6262
try
6363
{
64-
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
64+
metadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(configPath));
6565
metadata.PluginDirectory = pluginDirectory;
6666
// for plugins which doesn't has ActionKeywords key
6767
metadata.ActionKeywords = metadata.ActionKeywords ?? new List<string> { metadata.ActionKeyword };

Flow.Launcher.Core/Updater.cs

Lines changed: 52 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
using System.Windows;
99
using JetBrains.Annotations;
1010
using Squirrel;
11-
using Newtonsoft.Json;
1211
using Flow.Launcher.Core.Resource;
1312
using Flow.Launcher.Plugin.SharedCommands;
1413
using Flow.Launcher.Infrastructure;
1514
using Flow.Launcher.Infrastructure.Http;
1615
using Flow.Launcher.Infrastructure.Logger;
17-
using System.IO;
1816
using Flow.Launcher.Infrastructure.UserSettings;
1917
using Flow.Launcher.Plugin;
18+
using System.Text.Json.Serialization;
2019

2120
namespace Flow.Launcher.Core
2221
{
@@ -29,101 +28,80 @@ public Updater(string gitHubRepository)
2928
GitHubRepository = gitHubRepository;
3029
}
3130

32-
public async Task UpdateApp(IPublicAPI api , bool silentUpdate = true)
31+
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
3332
{
34-
UpdateManager updateManager;
35-
UpdateInfo newUpdateInfo;
36-
37-
if (!silentUpdate)
38-
api.ShowMsg("Please wait...", "Checking for new update");
39-
4033
try
4134
{
42-
updateManager = await GitHubUpdateManager(GitHubRepository);
43-
}
44-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
45-
{
46-
Log.Exception($"|Updater.UpdateApp|Please check your connection and proxy settings to api.github.com.", e);
47-
return;
48-
}
35+
UpdateInfo newUpdateInfo;
36+
37+
if (!silentUpdate)
38+
api.ShowMsg("Please wait...", "Checking for new update");
39+
40+
using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false);
41+
4942

50-
try
51-
{
5243
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
53-
newUpdateInfo = await updateManager.CheckForUpdate().NonNull();
54-
}
55-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
56-
{
57-
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to api.github.com.", e);
58-
updateManager.Dispose();
59-
return;
60-
}
44+
newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false);
6145

62-
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
63-
var currentVersion = Version.Parse(Constant.Version);
46+
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
47+
var currentVersion = Version.Parse(Constant.Version);
6448

65-
Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>");
49+
Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>");
50+
51+
if (newReleaseVersion <= currentVersion)
52+
{
53+
if (!silentUpdate)
54+
MessageBox.Show("You already have the latest Flow Launcher version");
55+
return;
56+
}
6657

67-
if (newReleaseVersion <= currentVersion)
68-
{
6958
if (!silentUpdate)
70-
MessageBox.Show("You already have the latest Flow Launcher version");
71-
updateManager.Dispose();
72-
return;
73-
}
59+
api.ShowMsg("Update found", "Updating...");
7460

75-
if (!silentUpdate)
76-
api.ShowMsg("Update found", "Updating...");
61+
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false);
7762

78-
try
79-
{
80-
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply);
81-
}
82-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
83-
{
84-
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
85-
updateManager.Dispose();
86-
return;
87-
}
88-
89-
await updateManager.ApplyReleases(newUpdateInfo);
63+
await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false);
9064

91-
if (DataLocation.PortableDataLocationInUse())
92-
{
93-
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
94-
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
95-
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
96-
MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
97-
$"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}");
98-
}
99-
else
100-
{
101-
await updateManager.CreateUninstallerRegistryEntry();
102-
}
65+
if (DataLocation.PortableDataLocationInUse())
66+
{
67+
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
68+
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
69+
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
70+
MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
71+
$"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}");
72+
}
73+
else
74+
{
75+
await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false);
76+
}
10377

104-
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
105-
106-
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
78+
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
10779

108-
// always dispose UpdateManager
109-
updateManager.Dispose();
80+
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
11081

111-
if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
82+
if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
83+
{
84+
UpdateManager.RestartApp(Constant.ApplicationFileName);
85+
}
86+
}
87+
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
11288
{
113-
UpdateManager.RestartApp(Constant.ApplicationFileName);
89+
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
90+
api.ShowMsg("Update Failed", "Check your connection and try updating proxy settings to github-cloud.s3.amazonaws.com.");
91+
return;
11492
}
11593
}
11694

11795
[UsedImplicitly]
11896
private class GithubRelease
11997
{
120-
[JsonProperty("prerelease")]
98+
[JsonPropertyName("prerelease")]
12199
public bool Prerelease { get; [UsedImplicitly] set; }
122100

123-
[JsonProperty("published_at")]
101+
[JsonPropertyName("published_at")]
124102
public DateTime PublishedAt { get; [UsedImplicitly] set; }
125103

126-
[JsonProperty("html_url")]
104+
[JsonPropertyName("html_url")]
127105
public string HtmlUrl { get; [UsedImplicitly] set; }
128106
}
129107

@@ -133,13 +111,13 @@ private async Task<UpdateManager> GitHubUpdateManager(string repository)
133111
var uri = new Uri(repository);
134112
var api = $"https://api.github.com/repos{uri.AbsolutePath}/releases";
135113

136-
var json = await Http.Get(api);
114+
var jsonStream = await Http.GetStreamAsync(api).ConfigureAwait(false);
137115

138-
var releases = JsonConvert.DeserializeObject<List<GithubRelease>>(json);
116+
var releases = await System.Text.Json.JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
139117
var latest = releases.Where(r => !r.Prerelease).OrderByDescending(r => r.PublishedAt).First();
140118
var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/");
141119

142-
var client = new WebClient { Proxy = Http.WebProxy() };
120+
var client = new WebClient { Proxy = Http.WebProxy };
143121
var downloader = new FileDownloader(client);
144122

145123
var manager = new UpdateManager(latestUrl, urlDownloader: downloader);

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public static class Constant
3030

3131
public static string PythonPath;
3232

33-
public static readonly string QueryTextBoxIconImagePath = $"{ProgramDirectory}\\Images\\mainsearch.png";
33+
public static readonly string QueryTextBoxIconImagePath = $"{ProgramDirectory}\\Images\\mainsearch.svg";
3434

3535
public const string DefaultTheme = "Darker";
3636

3737
public const string Themes = "Themes";
38+
39+
public const string Website = "https://flow-launcher.github.io";
3840
}
3941
}

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
</ItemGroup>
5050

5151
<ItemGroup>
52-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
5352
<PackageReference Include="NLog.Schema" Version="4.7.0-rc1" />
5453
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.0" />
5554
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />

Flow.Launcher.Infrastructure/Helper.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
using System;
22
using System.IO;
3-
using Newtonsoft.Json;
4-
using Newtonsoft.Json.Converters;
3+
using System.Runtime.CompilerServices;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
56

67
namespace Flow.Launcher.Infrastructure
78
{
89
public static class Helper
910
{
11+
static Helper()
12+
{
13+
jsonFormattedSerializerOptions.Converters.Add(new JsonStringEnumConverter());
14+
}
15+
1016
/// <summary>
1117
/// http://www.yinwang.org/blog-cn/2015/11/21/programming-philosophy
1218
/// </summary>
@@ -65,13 +71,18 @@ public static void ValidateDirectory(string path)
6571
}
6672
}
6773

74+
private static readonly JsonSerializerOptions jsonFormattedSerializerOptions = new JsonSerializerOptions
75+
{
76+
WriteIndented = true
77+
};
78+
6879
public static string Formatted<T>(this T t)
6980
{
70-
var formatted = JsonConvert.SerializeObject(
71-
t,
72-
Formatting.Indented,
73-
new StringEnumConverter()
74-
);
81+
var formatted = JsonSerializer.Serialize(t, new JsonSerializerOptions
82+
{
83+
WriteIndented = true
84+
});
85+
7586
return formatted;
7687
}
7788
}

0 commit comments

Comments
 (0)