refactor: Migrated from Newtonsoft.Json to System.Text.Json, missing one test passing

This commit is contained in:
Denny09310
2025-11-09 12:05:07 +01:00
parent fc69598b09
commit 71ced8db56
80 changed files with 720 additions and 878 deletions

View File

@@ -1,12 +1,9 @@
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.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -100,11 +97,11 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource<BrowserWindow>();
BridgeConnector.Socket.On("BrowserWindowCreated", (id) =>
BridgeConnector.Socket.On<JsonElement>("BrowserWindowCreated", (id) =>
{
BridgeConnector.Socket.Off("BrowserWindowCreated");
var browserWindowId = int.Parse(id.ToString()!);
var browserWindowId = id.GetInt32();
var browserWindow = new BrowserWindow(browserWindowId);
_browserWindows.Add(browserWindow);
@@ -112,11 +109,11 @@ namespace ElectronNET.API
taskCompletionSource.SetResult(browserWindow);
});
BridgeConnector.Socket.On<object>("BrowserWindowClosed", (ids) =>
BridgeConnector.Socket.On<JsonElement>("BrowserWindowClosed", (ids) =>
{
BridgeConnector.Socket.Off("BrowserWindowClosed");
var browserWindowIds = ((JArray)ids).ToObject<int[]>();
var browserWindowIds = ids.Deserialize<int[]>(Serialization.ElectronJson.Options);
for (int index = 0; index < _browserWindows.Count; index++)
{
@@ -127,7 +124,7 @@ namespace ElectronNET.API
}
});
if (loadUrl.ToUpper() == "HTTP://LOCALHOST" && ElectronNetRuntime.AspNetWebPort.HasValue)
if (loadUrl.Equals("http://localhost", StringComparison.OrdinalIgnoreCase) && ElectronNetRuntime.AspNetWebPort.HasValue)
{
loadUrl = $"{loadUrl}:{ElectronNetRuntime.AspNetWebPort}";
}
@@ -145,7 +142,7 @@ namespace ElectronNET.API
options.X = 0;
options.Y = 0;
await BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, this._jsonSerializer), loadUrl).ConfigureAwait(false);
await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false);
}
else
{
@@ -156,7 +153,7 @@ namespace ElectronNET.API
options.X -= 7;
}
await BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, this._jsonSerializer), loadUrl).ConfigureAwait(false);
await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false);
}
return await taskCompletionSource.Task.ConfigureAwait(false);
@@ -189,32 +186,22 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource<BrowserView>();
BridgeConnector.Socket.On("BrowserViewCreated", (id) =>
BridgeConnector.Socket.On<JsonElement>("BrowserViewCreated", (id) =>
{
BridgeConnector.Socket.Off("BrowserViewCreated");
string browserViewId = id.ToString();
BrowserView browserView = new BrowserView(int.Parse(browserViewId));
var browserViewId = id.GetInt32();
BrowserView browserView = new(browserViewId);
_browserViews.Add(browserView);
taskCompletionSource.SetResult(browserView);
});
var ownjsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
};
await BridgeConnector.Socket.Emit("createBrowserView", JObject.FromObject(options, ownjsonSerializer)).ConfigureAwait(false);
await BridgeConnector.Socket.Emit("createBrowserView", options).ConfigureAwait(false);
return await taskCompletionSource.Task.ConfigureAwait(false);
}
private readonly JsonSerializer _jsonSerializer = new()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
};
}
}