Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using Flow.Launcher.Infrastructure.Exception;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin;
Expand Down Expand Up @@ -65,7 +65,7 @@ private List<Result> DeserializedResult(string output)
{
List<Result> results = new List<Result>();

JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject<JsonRPCQueryResponseModel>(output);
JsonRPCQueryResponseModel queryResponseModel = JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output);
if (queryResponseModel.Result == null) return null;

foreach (JsonRPCResult result in queryResponseModel.Result)
Expand All @@ -84,7 +84,7 @@ private List<Result> DeserializedResult(string output)
else
{
string actionReponse = ExecuteCallback(result1.JsonRPCAction);
JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject<JsonRPCRequestModel>(actionReponse);
JsonRPCRequestModel jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionReponse);
if (jsonRpcRequestModel != null
&& !String.IsNullOrEmpty(jsonRpcRequestModel.Method)
&& jsonRpcRequestModel.Method.StartsWith("Flow.Launcher."))
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher.Core/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Newtonsoft.Json;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin;
using System.Text.Json;

namespace Flow.Launcher.Core.Plugin
{
Expand Down Expand Up @@ -61,7 +61,7 @@ private static PluginMetadata GetPluginMetadata(string pluginDirectory)
PluginMetadata metadata;
try
{
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
metadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(configPath));
metadata.PluginDirectory = pluginDirectory;
// for plugins which doesn't has ActionKeywords key
metadata.ActionKeywords = metadata.ActionKeywords ?? new List<string> { metadata.ActionKeyword };
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Logger;
using System.IO;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using System.Text.Json.Serialization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog.Schema" Version="4.7.0-rc1" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.0" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
Expand Down
25 changes: 18 additions & 7 deletions Flow.Launcher.Infrastructure/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Flow.Launcher.Infrastructure
{
public static class Helper
{
static Helper()
{
jsonFormattedSerializerOptions.Converters.Add(new JsonStringEnumConverter());
}

/// <summary>
/// http://www.yinwang.org/blog-cn/2015/11/21/programming-philosophy
/// </summary>
Expand Down Expand Up @@ -65,13 +71,18 @@ public static void ValidateDirectory(string path)
}
}

private static readonly JsonSerializerOptions jsonFormattedSerializerOptions = new JsonSerializerOptions
{
WriteIndented = true
};

public static string Formatted<T>(this T t)
{
var formatted = JsonConvert.SerializeObject(
t,
Formatting.Indented,
new StringEnumConverter()
);
var formatted = JsonSerializer.Serialize(t, new JsonSerializerOptions
{
WriteIndented = true
});

return formatted;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void LogInternal(string message, LogLevel level)
public static void Exception(string message, System.Exception e)
{
#if DEBUG
throw e;
throw e;
#else
if (FormatValid(message))
{
Expand Down
16 changes: 8 additions & 8 deletions Flow.Launcher.Infrastructure/Storage/JsonStorage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using Newtonsoft.Json;
using System.Text.Json;
using Flow.Launcher.Infrastructure.Logger;

namespace Flow.Launcher.Infrastructure.Storage
Expand All @@ -11,7 +11,7 @@ namespace Flow.Launcher.Infrastructure.Storage
/// </summary>
public class JsonStrorage<T>
{
private readonly JsonSerializerSettings _serializerSettings;
private readonly JsonSerializerOptions _serializerSettings;
private T _data;
// need a new directory name
public const string DirectoryName = "Settings";
Expand All @@ -24,10 +24,9 @@ internal JsonStrorage()
{
// use property initialization instead of DefaultValueAttribute
// easier and flexible for default value of object
_serializerSettings = new JsonSerializerSettings
_serializerSettings = new JsonSerializerOptions
{
ObjectCreationHandling = ObjectCreationHandling.Replace,
NullValueHandling = NullValueHandling.Ignore
IgnoreNullValues = false
Comment on lines 25 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming these options and comment are no longer applicable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the default behavior of System.Text.Json is replace, and ignore doesn't work well as my comment before.

};
}

Expand Down Expand Up @@ -56,7 +55,7 @@ private void Deserialize(string searlized)
{
try
{
_data = JsonConvert.DeserializeObject<T>(searlized, _serializerSettings);
_data = JsonSerializer.Deserialize<T>(searlized, _serializerSettings);
}
catch (JsonException e)
{
Expand All @@ -77,7 +76,7 @@ private void LoadDefault()
BackupOriginFile();
}

_data = JsonConvert.DeserializeObject<T>("{}", _serializerSettings);
_data = JsonSerializer.Deserialize<T>("{}", _serializerSettings);
Save();
}

Expand All @@ -94,7 +93,8 @@ private void BackupOriginFile()

public void Save()
{
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
string serialized = JsonSerializer.Serialize(_data, new JsonSerializerOptions() { WriteIndented = true });

File.WriteAllText(FilePath, serialized);
}
}
Expand Down
16 changes: 9 additions & 7 deletions Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.Drawing;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Infrastructure.UserSettings
Expand All @@ -16,7 +15,8 @@ public class Settings : BaseModel
public bool ShowOpenResultHotkey { get; set; } = true;
public string Language
{
get => language; set {
get => language; set
{
language = value;
OnPropertyChanged();
}
Expand Down Expand Up @@ -73,9 +73,7 @@ public string QuerySearchPrecisionString
public int MaxResultsToShow { get; set; } = 5;
public int ActivateTimes { get; set; }

// Order defaults to 0 or -1, so 1 will let this property appear last
[JsonProperty(Order = 1)]
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();

public ObservableCollection<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new ObservableCollection<CustomPluginHotkey>();

public bool DontPromptUpdateMsg { get; set; }
Expand All @@ -100,8 +98,12 @@ public bool HideNotifyIcon

public HttpProxy Proxy { get; set; } = new HttpProxy();

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public LastQueryMode LastQueryMode { get; set; } = LastQueryMode.Selected;


// This needs to be loaded last by staying at the bottom
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
}

public enum LastQueryMode
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions Flow.Launcher.Plugin/PluginMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Flow.Launcher.Plugin
{
[JsonObject(MemberSerialization.OptOut)]
public class PluginMetadata : BaseModel
{
private string _pluginDirectory;
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/Storage/QueryHistory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Storage
Expand Down
3 changes: 1 addition & 2 deletions Flow.Launcher/Storage/TopMostRecord.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using System.Text.Json;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Storage
{
// todo this class is not thread safe.... but used from multiple threads.
public class TopMostRecord
{
[JsonProperty]
private Dictionary<string, Record> records = new Dictionary<string, Record>();

internal bool IsTopMost(Result result)
Expand Down
2 changes: 0 additions & 2 deletions Flow.Launcher/Storage/UserSelectedRecord.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Storage
{
public class UserSelectedRecord
{
[JsonProperty]
private Dictionary<string, int> records = new Dictionary<string, int>();

public void Add(Result result)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Newtonsoft.Json;
using System;
using System;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Flow.Launcher.Plugin.Explorer.Search.FolderLinks
{
[JsonObject(MemberSerialization.OptIn)]
public class FolderLink
{
[JsonProperty]
public string Path { get; set; }

[JsonIgnore]
public string Nickname
{
get
Expand Down
8 changes: 1 addition & 7 deletions Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Flow.Launcher.Plugin.Explorer
{
public class Settings
{
[JsonProperty]
public int MaxResult { get; set; } = 100;

[JsonProperty]
public List<FolderLink> QuickFolderAccessLinks { get; set; } = new List<FolderLink>();

[JsonProperty]
public bool UseWindowsIndexForDirectorySearch { get; set; } = true;

[JsonProperty]
public List<FolderLink> IndexSearchExcludedSubdirectoryPaths { get; set; } = new List<FolderLink>();

[JsonProperty]
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;

[JsonProperty]
public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword;
}
}
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.WebSearch/SearchSource.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.IO;
using System.Windows.Media;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Flow.Launcher.Infrastructure.Image;
using Flow.Launcher.Infrastructure;
using System.Reflection;
using System.Text.Json.Serialization;

namespace Flow.Launcher.Plugin.WebSearch
{
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.WebSearch/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin.WebSearch.SuggestionSources;

namespace Flow.Launcher.Plugin.WebSearch
Expand Down
20 changes: 7 additions & 13 deletions Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Logger;
using System.Net.Http;
Expand Down Expand Up @@ -35,25 +34,20 @@ public override async Task<List<string>> Suggestions(string query)
Match match = _reg.Match(result);
if (match.Success)
{
JContainer json;
JsonDocument json;
try
{
json = JsonConvert.DeserializeObject(match.Groups[1].Value) as JContainer;
json = JsonDocument.Parse(match.Groups[1].Value);
}
catch (JsonSerializationException e)
catch(JsonException e)
{
Log.Exception("|Baidu.Suggestions|can't parse suggestions", e);
return new List<string>();
}

if (json != null)
{
var results = json["s"] as JArray;
if (results != null)
{
return results.OfType<JValue>().Select(o => o.Value).OfType<string>().ToList();
}
}
var results = json?.RootElement.GetProperty("s");

return results?.EnumerateArray().Select(o => o.GetString()).ToList() ?? new List<string>();
}

return new List<string>();
Expand Down
Loading