mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 05:34:48 +00:00
refactor: Migrated from Newtonsoft.Json to System.Text.Json, missing one test passing
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -50,7 +48,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
GenerateIDsForDefinedActions(notificationOptions);
|
||||
|
||||
BridgeConnector.Socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("createNotification", notificationOptions);
|
||||
}
|
||||
|
||||
private static void GenerateIDsForDefinedActions(NotificationOptions notificationOptions)
|
||||
@@ -63,7 +61,7 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventShow");
|
||||
BridgeConnector.Socket.On("NotificationEventShow", (id) => { _notificationOptions.Single(x => x.ShowID == id.ToString()).OnShow(); });
|
||||
BridgeConnector.Socket.On<JsonElement>("NotificationEventShow", (id) => { _notificationOptions.Single(x => x.ShowID == id.GetString()).OnShow(); });
|
||||
}
|
||||
|
||||
if (notificationOptions.OnClick != null)
|
||||
@@ -72,7 +70,7 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventClick");
|
||||
BridgeConnector.Socket.On("NotificationEventClick", (id) => { _notificationOptions.Single(x => x.ClickID == id.ToString()).OnClick(); });
|
||||
BridgeConnector.Socket.On<JsonElement>("NotificationEventClick", (id) => { _notificationOptions.Single(x => x.ClickID == id.GetString()).OnClick(); });
|
||||
}
|
||||
|
||||
if (notificationOptions.OnClose != null)
|
||||
@@ -81,7 +79,7 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventClose");
|
||||
BridgeConnector.Socket.On("NotificationEventClose", (id) => { _notificationOptions.Single(x => x.CloseID == id.ToString()).OnClose(); });
|
||||
BridgeConnector.Socket.On<JsonElement>("NotificationEventClose", (id) => { _notificationOptions.Single(x => x.CloseID == id.GetString()).OnClose(); });
|
||||
}
|
||||
|
||||
if (notificationOptions.OnReply != null)
|
||||
@@ -90,10 +88,10 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventReply");
|
||||
BridgeConnector.Socket.On("NotificationEventReply", (args) =>
|
||||
BridgeConnector.Socket.On<JsonElement>("NotificationEventReply", (args) =>
|
||||
{
|
||||
var arguments = ((JArray)args).ToObject<string[]>();
|
||||
_notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnReply(arguments[1].ToString());
|
||||
var arguments = args.Deserialize<string[]>(Serialization.ElectronJson.Options);
|
||||
_notificationOptions.Single(x => x.ReplyID == arguments[0]).OnReply(arguments[1]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,10 +101,10 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventAction");
|
||||
BridgeConnector.Socket.On("NotificationEventAction", (args) =>
|
||||
BridgeConnector.Socket.On<JsonElement>("NotificationEventAction", (args) =>
|
||||
{
|
||||
var arguments = ((JArray)args).ToObject<string[]>();
|
||||
_notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnAction(arguments[1].ToString());
|
||||
var arguments = JsonSerializer.Deserialize<string[]>(args, Serialization.ElectronJson.Options);
|
||||
_notificationOptions.Single(x => x.ReplyID == arguments[0]).OnAction(arguments[1]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,10 +122,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("notificationIsSupportedComplete", (isSupported) =>
|
||||
BridgeConnector.Socket.On<JsonElement>("notificationIsSupportedComplete", (isSupported) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("notificationIsSupportedComplete");
|
||||
taskCompletionSource.SetResult((bool)isSupported);
|
||||
taskCompletionSource.SetResult(isSupported.GetBoolean());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("notificationIsSupported");
|
||||
@@ -135,11 +133,6 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user