diff --git a/src/ElectronNET.API/API/ApiBase.cs b/src/ElectronNET.API/API/ApiBase.cs
index 13285ca..83adcfb 100644
--- a/src/ElectronNET.API/API/ApiBase.cs
+++ b/src/ElectronNET.API/API/ApiBase.cs
@@ -1,11 +1,13 @@
namespace ElectronNET.API
{
+ using ElectronNET.API.Serialization;
+ using ElectronNET.Common;
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Runtime.CompilerServices;
+ using System.Text.Json;
using System.Threading.Tasks;
- using ElectronNET.Common;
public abstract class ApiBase
{
@@ -156,8 +158,19 @@
lock (this)
{
- this.tcs?.SetResult(result);
- this.tcs = null;
+ try
+ {
+ var value = result;
+ this.tcs?.SetResult(value);
+ }
+ catch (Exception ex)
+ {
+ this.tcs?.TrySetException(ex);
+ }
+ finally
+ {
+ this.tcs = null;
+ }
}
});
@@ -170,7 +183,7 @@
BridgeConnector.Socket.Emit(messageName);
}
- System.Threading.Tasks.Task.Delay(ApiBase.PropertyTimeout).ContinueWith(_ =>
+ System.Threading.Tasks.Task.Delay(PropertyTimeout).ContinueWith(_ =>
{
if (this.tcs != null)
{
diff --git a/src/ElectronNET.API/API/App.cs b/src/ElectronNET.API/API/App.cs
index 4739d0a..7a9a665 100644
--- a/src/ElectronNET.API/API/App.cs
+++ b/src/ElectronNET.API/API/App.cs
@@ -1,13 +1,12 @@
-using ElectronNET.API.Entities;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
+using ElectronNET.API.Entities;
+using ElectronNET.API.Extensions;
+using ElectronNET.API.Serialization;
+using ElectronNET.Common;
using System;
using System.Runtime.InteropServices;
+using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
-using ElectronNET.API.Extensions;
-using ElectronNET.Common;
// ReSharper disable InconsistentNaming
@@ -271,7 +270,7 @@ namespace ElectronNET.API
/// when Chrome's accessibility support is enabled, otherwise.
public event Action AccessibilitySupportChanged
{
- add => ApiEventManager.AddEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value, (args) => (bool)args);
+ add => ApiEventManager.AddEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value, (args) => args.GetBoolean());
remove => ApiEventManager.RemoveEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value);
}
@@ -414,10 +413,7 @@ namespace ElectronNET.API
private static App _app;
private static object _syncRoot = new object();
- private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver()
- };
+
///
/// Try to close all windows. The event will be emitted first. If all windows are successfully
@@ -475,7 +471,7 @@ namespace ElectronNET.API
/// Options for the relaunch.
public void Relaunch(RelaunchOptions relaunchOptions)
{
- this.CallMethod1(JObject.FromObject(relaunchOptions, _jsonSerializer));
+ this.CallMethod1(relaunchOptions);
}
///
@@ -495,7 +491,7 @@ namespace ElectronNET.API
///
public void Focus(FocusOptions focusOptions)
{
- this.CallMethod1(JObject.FromObject(focusOptions, _jsonSerializer));
+ this.CallMethod1(focusOptions);
}
///
@@ -551,11 +547,11 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appGetPathCompleted", (path) =>
+ BridgeConnector.Socket.On("appGetPathCompleted", (path) =>
{
BridgeConnector.Socket.Off("appGetPathCompleted");
- taskCompletionSource.SetResult(path.ToString());
+ taskCompletionSource.SetResult(path);
});
BridgeConnector.Socket.Emit("appGetPath", pathName.GetDescription());
@@ -720,10 +716,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appSetAsDefaultProtocolClientCompleted", (success) =>
+ BridgeConnector.Socket.On("appSetAsDefaultProtocolClientCompleted", (success) =>
{
BridgeConnector.Socket.Off("appSetAsDefaultProtocolClientCompleted");
- taskCompletionSource.SetResult((bool)success);
+ taskCompletionSource.SetResult(success);
});
BridgeConnector.Socket.Emit("appSetAsDefaultProtocolClient", protocol, path, args);
@@ -774,10 +770,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appRemoveAsDefaultProtocolClientCompleted", (success) =>
+ BridgeConnector.Socket.On("appRemoveAsDefaultProtocolClientCompleted", (success) =>
{
BridgeConnector.Socket.Off("appRemoveAsDefaultProtocolClientCompleted");
- taskCompletionSource.SetResult((bool)success);
+ taskCompletionSource.SetResult(success);
});
BridgeConnector.Socket.Emit("appRemoveAsDefaultProtocolClient", protocol, path, args);
@@ -846,10 +842,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appIsDefaultProtocolClientCompleted", (success) =>
+ BridgeConnector.Socket.On("appIsDefaultProtocolClientCompleted", (success) =>
{
BridgeConnector.Socket.Off("appIsDefaultProtocolClientCompleted");
- taskCompletionSource.SetResult((bool)success);
+ taskCompletionSource.SetResult(success);
});
BridgeConnector.Socket.Emit("appIsDefaultProtocolClient", protocol, path, args);
@@ -874,13 +870,13 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appSetUserTasksCompleted", (success) =>
+ BridgeConnector.Socket.On("appSetUserTasksCompleted", (success) =>
{
BridgeConnector.Socket.Off("appSetUserTasksCompleted");
- taskCompletionSource.SetResult((bool)success);
+ taskCompletionSource.SetResult(success);
});
- BridgeConnector.Socket.Emit("appSetUserTasks", JArray.FromObject(userTasks, _jsonSerializer));
+ BridgeConnector.Socket.Emit("appSetUserTasks", userTasks);
return await taskCompletionSource.Task
.ConfigureAwait(false);
@@ -916,7 +912,7 @@ namespace ElectronNET.API
/// Array of objects.
public void SetJumpList(JumpListCategory[] categories)
{
- this.CallMethod1(JArray.FromObject(categories, _jsonSerializer));
+ this.CallMethod1(categories);
}
///
@@ -947,19 +943,21 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appRequestSingleInstanceLockCompleted", (success) =>
+ BridgeConnector.Socket.On("appRequestSingleInstanceLockCompleted", (success) =>
{
BridgeConnector.Socket.Off("appRequestSingleInstanceLockCompleted");
- taskCompletionSource.SetResult((bool)success);
+ taskCompletionSource.SetResult(success);
});
BridgeConnector.Socket.Off("secondInstance");
- BridgeConnector.Socket.On("secondInstance", (result) =>
+ BridgeConnector.Socket.On("secondInstance", (result) =>
{
- JArray results = (JArray)result;
- string[] args = results.First.ToObject();
- string workingDirectory = results.Last.ToObject();
-
+ var arr = result.EnumerateArray();
+ var e = arr.GetEnumerator();
+ e.MoveNext();
+ var args = e.Current.Deserialize(JsonSerializerOptions.Default);
+ e.MoveNext();
+ var workingDirectory = e.Current.GetString();
newInstanceOpened(args, workingDirectory);
});
@@ -1071,13 +1069,13 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appImportCertificateCompleted", (result) =>
+ BridgeConnector.Socket.On("appImportCertificateCompleted", (result) =>
{
BridgeConnector.Socket.Off("appImportCertificateCompleted");
- taskCompletionSource.SetResult((int)result);
+ taskCompletionSource.SetResult(result);
});
- BridgeConnector.Socket.Emit("appImportCertificate", JObject.FromObject(options, _jsonSerializer));
+ BridgeConnector.Socket.Emit("appImportCertificate", options);
return await taskCompletionSource.Task
.ConfigureAwait(false);
@@ -1127,10 +1125,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appSetBadgeCountCompleted", (success) =>
+ BridgeConnector.Socket.On("appSetBadgeCountCompleted", (success) =>
{
BridgeConnector.Socket.Off("appSetBadgeCountCompleted");
- taskCompletionSource.SetResult((bool)success);
+ taskCompletionSource.SetResult(success);
});
BridgeConnector.Socket.Emit("appSetBadgeCount", count);
@@ -1187,12 +1185,9 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appGetLoginItemSettingsCompleted", (loginItemSettings) =>
+ BridgeConnector.Socket.On("appGetLoginItemSettingsCompleted", (result) =>
{
BridgeConnector.Socket.Off("appGetLoginItemSettingsCompleted");
-
- var result = ((JObject)loginItemSettings).ToObject();
-
taskCompletionSource.SetResult(result);
});
@@ -1202,7 +1197,7 @@ namespace ElectronNET.API
}
else
{
- BridgeConnector.Socket.Emit("appGetLoginItemSettings", JObject.FromObject(options, _jsonSerializer));
+ BridgeConnector.Socket.Emit("appGetLoginItemSettings", options);
}
return await taskCompletionSource.Task
@@ -1218,7 +1213,7 @@ namespace ElectronNET.API
///
public void SetLoginItemSettings(LoginSettings loginSettings)
{
- this.CallMethod1(JObject.FromObject(loginSettings, _jsonSerializer));
+ this.CallMethod1(loginSettings);
}
///
@@ -1270,7 +1265,7 @@ namespace ElectronNET.API
/// About panel options.
public void SetAboutPanelOptions(AboutPanelOptions options)
{
- this.CallMethod1(JObject.FromObject(options, _jsonSerializer));
+ this.CallMethod1(options);
}
///
@@ -1306,14 +1301,14 @@ namespace ElectronNET.API
{
get
{
- return Task.Run(() =>
+ return Task.Run(() =>
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("appGetUserAgentFallbackCompleted", (result) =>
+ BridgeConnector.Socket.On("appGetUserAgentFallbackCompleted", (result) =>
{
BridgeConnector.Socket.Off("appGetUserAgentFallbackCompleted");
- taskCompletionSource.SetResult((string)result);
+ taskCompletionSource.SetResult(result);
});
BridgeConnector.Socket.Emit("appGetUserAgentFallback");
@@ -1364,4 +1359,4 @@ namespace ElectronNET.API
public async Task Once(string eventName, Action
public event Action OnUpdateAvailable
{
- add => ApiEventManager.AddEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value, (args) => JObject.Parse(args.ToString()).ToObject());
+ add => ApiEventManager.AddEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value);
}
@@ -322,7 +319,7 @@ namespace ElectronNET.API
///
public event Action OnUpdateNotAvailable
{
- add => ApiEventManager.AddEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value, (args) => JObject.Parse(args.ToString()).ToObject());
+ add => ApiEventManager.AddEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value);
}
@@ -333,7 +330,7 @@ namespace ElectronNET.API
///
public event Action OnDownloadProgress
{
- add => ApiEventManager.AddEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value, (args) => JObject.Parse(args.ToString()).ToObject());
+ add => ApiEventManager.AddEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value, (args) => args.Deserialize(ElectronJsonContext.Default.ProgressInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value);
}
@@ -344,7 +341,7 @@ namespace ElectronNET.API
///
public event Action OnUpdateDownloaded
{
- add => ApiEventManager.AddEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value, (args) => JObject.Parse(args.ToString()).ToObject());
+ add => ApiEventManager.AddEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value);
}
@@ -385,26 +382,25 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesComplete" + guid, (updateCheckResult) =>
+ BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesComplete" + guid, (result) =>
{
try
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
- taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject());
+ taskCompletionSource.SetResult(result);
}
catch (Exception ex)
{
taskCompletionSource.SetException(ex);
}
});
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesError" + guid, (error) =>
+ BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesError" + guid, (result) =>
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
string message = "An error occurred in CheckForUpdatesAsync";
- if (error != null && !string.IsNullOrEmpty(error.ToString()))
- message = JsonConvert.SerializeObject(error);
+ if (!string.IsNullOrEmpty(result)) message = result;
taskCompletionSource.SetException(new Exception(message));
});
@@ -424,29 +420,25 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (updateCheckResult) =>
+ BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (result) =>
{
try
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
- if (updateCheckResult == null)
- taskCompletionSource.SetResult(null);
- else
- taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject());
+ taskCompletionSource.SetResult(result);
}
catch (Exception ex)
{
taskCompletionSource.SetException(ex);
}
});
- BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (error) =>
+ BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (result) =>
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
string message = "An error occurred in autoUpdaterCheckForUpdatesAndNotify";
- if (error != null)
- message = JsonConvert.SerializeObject(error);
+ if (!string.IsNullOrEmpty(result)) message = result;
taskCompletionSource.SetException(new Exception(message));
});
@@ -478,10 +470,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterDownloadUpdateComplete" + guid, (downloadedPath) =>
+ BridgeConnector.Socket.On("autoUpdaterDownloadUpdateComplete" + guid, (downloadedPath) =>
{
BridgeConnector.Socket.Off("autoUpdaterDownloadUpdateComplete" + guid);
- taskCompletionSource.SetResult(downloadedPath.ToString());
+ taskCompletionSource.SetResult(downloadedPath);
});
BridgeConnector.Socket.Emit("autoUpdaterDownloadUpdate", guid);
@@ -498,10 +490,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
string guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("autoUpdaterGetFeedURLComplete" + guid, (downloadedPath) =>
+ BridgeConnector.Socket.On("autoUpdaterGetFeedURLComplete" + guid, (downloadedPath) =>
{
BridgeConnector.Socket.Off("autoUpdaterGetFeedURLComplete" + guid);
- taskCompletionSource.SetResult(downloadedPath.ToString());
+ taskCompletionSource.SetResult(downloadedPath);
});
BridgeConnector.Socket.Emit("autoUpdaterGetFeedURL", guid);
@@ -509,9 +501,8 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
- private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver()
- };
+
}
-}
\ No newline at end of file
+}
+
+
diff --git a/src/ElectronNET.API/API/BrowserView.cs b/src/ElectronNET.API/API/BrowserView.cs
index 50814f2..2a4aa0c 100644
--- a/src/ElectronNET.API/API/BrowserView.cs
+++ b/src/ElectronNET.API/API/BrowserView.cs
@@ -1,14 +1,13 @@
-using ElectronNET.API.Entities;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
+using ElectronNET.API.Entities;
+using ElectronNET.API.Serialization;
+using System.Text.Json;
using System.Threading.Tasks;
namespace ElectronNET.API
{
///
- /// A BrowserView can be used to embed additional web content into a BrowserWindow.
- /// It is like a child window, except that it is positioned relative to its owning window.
+ /// A BrowserView can be used to embed additional web content into a BrowserWindow.
+ /// It is like a child window, except that it is positioned relative to its owning window.
/// It is meant to be an alternative to the webview tag.
///
public class BrowserView
@@ -16,9 +15,6 @@ namespace ElectronNET.API
///
/// Gets the identifier.
///
- ///
- /// The identifier.
- ///
public int Id { get; internal set; }
///
@@ -28,7 +24,6 @@ namespace ElectronNET.API
///
/// Resizes and moves the view to the supplied bounds relative to the window.
- ///
/// (experimental)
///
public Rectangle Bounds
@@ -52,7 +47,7 @@ namespace ElectronNET.API
}
set
{
- BridgeConnector.Socket.Emit("browserView-setBounds", Id, JObject.FromObject(value, _jsonSerializer));
+ BridgeConnector.Socket.Emit("browserView-setBounds", Id, value);
}
}
@@ -74,12 +69,11 @@ namespace ElectronNET.API
///
public void SetAutoResize(AutoResizeOptions options)
{
- BridgeConnector.Socket.Emit("browserView-setAutoResize", Id, JObject.FromObject(options, _jsonSerializer));
+ BridgeConnector.Socket.Emit("browserView-setAutoResize", Id, options);
}
///
/// Color in #aarrggbb or #argb form. The alpha channel is optional.
- ///
/// (experimental)
///
/// Color in #aarrggbb or #argb form. The alpha channel is optional.
@@ -87,11 +81,6 @@ namespace ElectronNET.API
{
BridgeConnector.Socket.Emit("browserView-setBackgroundColor", Id, color);
}
-
- private JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- NullValueHandling = NullValueHandling.Ignore
- };
}
-}
\ No newline at end of file
+}
+
diff --git a/src/ElectronNET.API/API/BrowserWindow.cs b/src/ElectronNET.API/API/BrowserWindow.cs
index 0c0e54a..454ab8c 100644
--- a/src/ElectronNET.API/API/BrowserWindow.cs
+++ b/src/ElectronNET.API/API/BrowserWindow.cs
@@ -1,23 +1,17 @@
-using ElectronNET.API.Entities;
+using ElectronNET.API.Entities;
using ElectronNET.API.Extensions;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
-using ElectronNET.Common;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API;
-using System.Collections.Concurrent;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
using ElectronNET.Common;
+using System.Text.Json;
///
/// Create and control browser windows.
@@ -469,7 +463,7 @@ public class BrowserWindow : ApiBase
/// The aspect ratio to maintain for some portion of the content view.
/// The extra size not to be included while maintaining the aspect ratio.
public void SetAspectRatio(double aspectRatio, Size extraSize) =>
- this.CallMethod2(aspectRatio, JObject.FromObject(extraSize, _jsonSerializer));
+ this.CallMethod2(aspectRatio, extraSize);
///
/// This will make a window maintain an aspect ratio. The extra size allows a developer to have space,
@@ -486,7 +480,7 @@ public class BrowserWindow : ApiBase
/// The aspect ratio to maintain for some portion of the content view.
/// The extra size not to be included while maintaining the aspect ratio.
public void SetAspectRatio(int aspectRatio, Size extraSize) =>
- this.CallMethod2(aspectRatio, JObject.FromObject(extraSize, _jsonSerializer));
+ this.CallMethod2(aspectRatio, extraSize);
///
/// Uses Quick Look to preview a file at a given path.
@@ -515,14 +509,14 @@ public class BrowserWindow : ApiBase
/// Resizes and moves the window to the supplied bounds
///
///
- public void SetBounds(Rectangle bounds) => this.CallMethod1(JObject.FromObject(bounds, _jsonSerializer));
+ public void SetBounds(Rectangle bounds) => this.CallMethod1(bounds);
///
/// Resizes and moves the window to the supplied bounds
///
///
///
- public void SetBounds(Rectangle bounds, bool animate) => this.CallMethod2(JObject.FromObject(bounds, _jsonSerializer), animate);
+ public void SetBounds(Rectangle bounds, bool animate) => this.CallMethod2(bounds, animate);
///
/// Gets the bounds asynchronous.
@@ -534,14 +528,14 @@ public class BrowserWindow : ApiBase
/// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds.
///
///
- public void SetContentBounds(Rectangle bounds) => this.CallMethod1(JObject.FromObject(bounds, _jsonSerializer));
+ public void SetContentBounds(Rectangle bounds) => this.CallMethod1(bounds);
///
/// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds.
///
///
///
- public void SetContentBounds(Rectangle bounds, bool animate) => this.CallMethod2(JObject.FromObject(bounds, _jsonSerializer), animate);
+ public void SetContentBounds(Rectangle bounds, bool animate) => this.CallMethod2(bounds, animate);
///
/// Gets the content bounds asynchronous.
@@ -749,10 +743,10 @@ public class BrowserWindow : ApiBase
{
// Workaround Windows 10 / Electron Bug
// https://github.com/electron/electron/issues/4045
- ////if (isWindows10())
- ////{
- //// x = x - 7;
- ////}
+ //if (isWindows10())
+ //{
+ // x = x - 7;
+ //}
this.CallMethod2(x, y);
}
@@ -766,10 +760,11 @@ public class BrowserWindow : ApiBase
{
// Workaround Windows 10 / Electron Bug
// https://github.com/electron/electron/issues/4045
- ////if (isWindows10())
- ////{
- //// x = x - 7;
- ////}
+ //if (isWindows10())
+ //{
+ // x = x - 7;
+ //}
+
this.CallMethod3(x, y, animate);
}
@@ -894,7 +889,7 @@ public class BrowserWindow : ApiBase
///
///
///
- public void LoadURL(string url, LoadURLOptions options) => this.CallMethod2(url, JObject.FromObject(options, _jsonSerializer));
+ public void LoadURL(string url, LoadURLOptions options) => this.CallMethod2(url, options);
///
/// Same as webContents.reload.
@@ -925,13 +920,13 @@ public class BrowserWindow : ApiBase
public void SetMenu(MenuItem[] menuItems)
{
menuItems.AddMenuItemsId();
- this.CallMethod1(JArray.FromObject(menuItems, _jsonSerializer));
+ this.CallMethod1(menuItems);
_items.AddRange(menuItems);
BridgeConnector.Socket.Off("windowMenuItemClicked");
- BridgeConnector.Socket.On("windowMenuItemClicked", (id) =>
+ BridgeConnector.Socket.On("windowMenuItemClicked", (id) =>
{
- MenuItem menuItem = _items.GetMenuItem(id.ToString());
+ MenuItem menuItem = _items.GetMenuItem(id);
menuItem?.Click();
});
}
@@ -967,7 +962,7 @@ public class BrowserWindow : ApiBase
///
///
public void SetProgressBar(double progress, ProgressBarOptions progressBarOptions) =>
- this.CallMethod2(progress, JObject.FromObject(progressBarOptions, _jsonSerializer));
+ this.CallMethod2(progress, progressBarOptions);
///
/// Sets whether the window should have a shadow. On Windows and Linux does nothing.
@@ -1015,22 +1010,22 @@ public class BrowserWindow : ApiBase
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("browserWindowSetThumbarButtons-completed", (success) =>
+ BridgeConnector.Socket.On("browserWindowSetThumbarButtons-completed", (success) =>
{
BridgeConnector.Socket.Off("browserWindowSetThumbarButtons-completed");
- taskCompletionSource.SetResult((bool)success);
+ taskCompletionSource.SetResult(success);
});
thumbarButtons.AddThumbarButtonsId();
- BridgeConnector.Socket.Emit("browserWindowSetThumbarButtons", Id, JArray.FromObject(thumbarButtons, _jsonSerializer));
+ BridgeConnector.Socket.Emit("browserWindowSetThumbarButtons", Id, thumbarButtons);
_thumbarButtons.Clear();
_thumbarButtons.AddRange(thumbarButtons);
BridgeConnector.Socket.Off("thumbarButtonClicked");
- BridgeConnector.Socket.On("thumbarButtonClicked", (id) =>
+ BridgeConnector.Socket.On("thumbarButtonClicked", (id) =>
{
- ThumbarButton thumbarButton = _thumbarButtons.GetThumbarButton(id.ToString());
+ ThumbarButton thumbarButton = _thumbarButtons.GetThumbarButton(id);
thumbarButton?.Click();
});
@@ -1058,7 +1053,7 @@ public class BrowserWindow : ApiBase
/// If one of those properties is not set, then neither will be used.
///
///
- public void SetAppDetails(AppDetailsOptions options) => this.CallMethod1(JObject.FromObject(options, _jsonSerializer));
+ public void SetAppDetails(AppDetailsOptions options) => this.CallMethod1(options);
///
/// Same as webContents.showDefinitionForSelection().
@@ -1146,7 +1141,7 @@ public class BrowserWindow : ApiBase
}
else
{
- BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
+ BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, parent);
}
}
@@ -1210,10 +1205,4 @@ public class BrowserWindow : ApiBase
// This message name does not match the default ApiBase naming convention.
BridgeConnector.Socket.Emit("browserWindow-setBrowserView", Id, browserView.Id);
}
-
- private readonly JsonSerializer _jsonSerializer = new()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- NullValueHandling = NullValueHandling.Ignore
- };
}
\ No newline at end of file
diff --git a/src/ElectronNET.API/API/Clipboard.cs b/src/ElectronNET.API/API/Clipboard.cs
index 4a80847..b487adb 100644
--- a/src/ElectronNET.API/API/Clipboard.cs
+++ b/src/ElectronNET.API/API/Clipboard.cs
@@ -1,7 +1,6 @@
-using ElectronNET.API.Entities;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
+using ElectronNET.API.Entities;
+using ElectronNET.API.Serialization;
+using System.Text.Json;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -46,11 +45,11 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("clipboard-readText-Completed", (text) =>
+ BridgeConnector.Socket.On("clipboard-readText-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readText-Completed");
- taskCompletionSource.SetResult(text.ToString());
+ taskCompletionSource.SetResult(text);
});
BridgeConnector.Socket.Emit("clipboard-readText", type);
@@ -77,11 +76,11 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("clipboard-readHTML-Completed", (text) =>
+ BridgeConnector.Socket.On("clipboard-readHTML-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readHTML-Completed");
- taskCompletionSource.SetResult(text.ToString());
+ taskCompletionSource.SetResult(text);
});
BridgeConnector.Socket.Emit("clipboard-readHTML", type);
@@ -108,11 +107,11 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("clipboard-readRTF-Completed", (text) =>
+ BridgeConnector.Socket.On("clipboard-readRTF-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readRTF-Completed");
- taskCompletionSource.SetResult(text.ToString());
+ taskCompletionSource.SetResult(text);
});
BridgeConnector.Socket.Emit("clipboard-readRTF", type);
@@ -140,11 +139,10 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("clipboard-readBookmark-Completed", (bookmark) =>
+ BridgeConnector.Socket.On("clipboard-readBookmark-Completed", (result) =>
{
BridgeConnector.Socket.Off("clipboard-readBookmark-Completed");
-
- taskCompletionSource.SetResult(((JObject)bookmark).ToObject());
+ taskCompletionSource.SetResult(result);
});
BridgeConnector.Socket.Emit("clipboard-readBookmark");
@@ -177,11 +175,10 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("clipboard-readFindText-Completed", (text) =>
+ BridgeConnector.Socket.On("clipboard-readFindText-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readFindText-Completed");
-
- taskCompletionSource.SetResult(text.ToString());
+ taskCompletionSource.SetResult(text);
});
BridgeConnector.Socket.Emit("clipboard-readFindText");
@@ -217,11 +214,10 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("clipboard-availableFormats-Completed", (formats) =>
+ BridgeConnector.Socket.On("clipboard-availableFormats-Completed", (formats) =>
{
BridgeConnector.Socket.Off("clipboard-availableFormats-Completed");
-
- taskCompletionSource.SetResult(((JArray)formats).ToObject());
+ taskCompletionSource.SetResult(formats);
});
BridgeConnector.Socket.Emit("clipboard-availableFormats", type);
@@ -236,7 +232,7 @@ namespace ElectronNET.API
///
public void Write(Data data, string type = "")
{
- BridgeConnector.Socket.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type);
+ BridgeConnector.Socket.Emit("clipboard-write", data, type);
}
///
@@ -248,13 +244,10 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource();
- BridgeConnector.Socket.On("clipboard-readImage-Completed", (image) =>
+ BridgeConnector.Socket.On("clipboard-readImage-Completed", (result) =>
{
BridgeConnector.Socket.Off("clipboard-readImage-Completed");
-
- var nativeImage = ((JObject)image).ToObject();
-
- taskCompletionSource.SetResult(nativeImage);
+ taskCompletionSource.SetResult(result);
});
BridgeConnector.Socket.Emit("clipboard-readImage", type);
@@ -269,14 +262,7 @@ namespace ElectronNET.API
///
public void WriteImage(NativeImage image, string type = "")
{
- BridgeConnector.Socket.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type);
+ BridgeConnector.Socket.Emit("clipboard-writeImage", JsonSerializer.Serialize(image, ElectronJson.Options), type);
}
-
- private JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- NullValueHandling = NullValueHandling.Ignore,
- DefaultValueHandling = DefaultValueHandling.Ignore
- };
}
-}
\ No newline at end of file
+}
diff --git a/src/ElectronNET.API/API/CommandLine.cs b/src/ElectronNET.API/API/CommandLine.cs
index 184a345..d3e1b7e 100644
--- a/src/ElectronNET.API/API/CommandLine.cs
+++ b/src/ElectronNET.API/API/CommandLine.cs
@@ -1,4 +1,5 @@
-using System.Threading;
+using System.Text.Json;
+using System.Threading;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -75,10 +76,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appCommandLineHasSwitchCompleted", (result) =>
+ BridgeConnector.Socket.On("appCommandLineHasSwitchCompleted", (result) =>
{
BridgeConnector.Socket.Off("appCommandLineHasSwitchCompleted");
- taskCompletionSource.SetResult((bool)result);
+ taskCompletionSource.SetResult(result);
});
BridgeConnector.Socket.Emit("appCommandLineHasSwitch", switchName);
@@ -103,10 +104,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("appCommandLineGetSwitchValueCompleted", (result) =>
+ BridgeConnector.Socket.On("appCommandLineGetSwitchValueCompleted", (result) =>
{
BridgeConnector.Socket.Off("appCommandLineGetSwitchValueCompleted");
- taskCompletionSource.SetResult((string)result);
+ taskCompletionSource.SetResult(result);
});
BridgeConnector.Socket.Emit("appCommandLineGetSwitchValue", switchName);
diff --git a/src/ElectronNET.API/API/Cookies.cs b/src/ElectronNET.API/API/Cookies.cs
index 9e35c0f..8540598 100644
--- a/src/ElectronNET.API/API/Cookies.cs
+++ b/src/ElectronNET.API/API/Cookies.cs
@@ -1,9 +1,7 @@
-using System;
-using System.Threading.Tasks;
using ElectronNET.API.Entities;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
+using ElectronNET.API.Serialization;
+using System;
+using System.Text.Json;
namespace ElectronNET.API
{
@@ -34,11 +32,15 @@ namespace ElectronNET.API
{
if (_changed == null)
{
- BridgeConnector.Socket.On("webContents-session-cookies-changed" + Id, (args) =>
+ BridgeConnector.Socket.On("webContents-session-cookies-changed" + Id, (args) =>
{
- Cookie cookie = ((JArray)args)[0].ToObject();
- CookieChangedCause cause = ((JArray)args)[1].ToObject();
- bool removed = ((JArray)args)[2].ToObject();
+ var e = args.EnumerateArray().GetEnumerator();
+ e.MoveNext();
+ var cookie = e.Current.Deserialize(ElectronJson.Options);
+ e.MoveNext();
+ var cause = e.Current.Deserialize(ElectronJson.Options);
+ e.MoveNext();
+ var removed = e.Current.GetBoolean();
_changed(cookie, cause, removed);
});
@@ -58,11 +60,6 @@ namespace ElectronNET.API
private event Action _changed;
- private JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- NullValueHandling = NullValueHandling.Ignore,
- DefaultValueHandling = DefaultValueHandling.Ignore
- };
+
}
-}
\ No newline at end of file
+}
diff --git a/src/ElectronNET.API/API/Dialog.cs b/src/ElectronNET.API/API/Dialog.cs
index a8085e0..a824c09 100644
--- a/src/ElectronNET.API/API/Dialog.cs
+++ b/src/ElectronNET.API/API/Dialog.cs
@@ -1,9 +1,7 @@
-using ElectronNET.API.Entities;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
+using ElectronNET.API.Entities;
+using ElectronNET.API.Serialization;
using System;
-using System.Collections.Generic;
+using System.Text.Json;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -52,18 +50,16 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
var guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("showOpenDialogComplete" + guid, (filePaths) =>
+ BridgeConnector.Socket.On("showOpenDialogComplete" + guid, (filePaths) =>
{
BridgeConnector.Socket.Off("showOpenDialogComplete" + guid);
-
- var result = ((JArray)filePaths).ToObject();
- taskCompletionSource.SetResult(result);
+ taskCompletionSource.SetResult(filePaths);
});
BridgeConnector.Socket.Emit("showOpenDialog",
- JObject.FromObject(browserWindow, _jsonSerializer),
- JObject.FromObject(options, _jsonSerializer), guid);
+ browserWindow,
+ options, guid);
return taskCompletionSource.Task;
}
@@ -79,16 +75,15 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
var guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("showSaveDialogComplete" + guid, (filename) =>
+ BridgeConnector.Socket.On("showSaveDialogComplete" + guid, (filename) =>
{
BridgeConnector.Socket.Off("showSaveDialogComplete" + guid);
-
- taskCompletionSource.SetResult(filename.ToString());
+ taskCompletionSource.SetResult(filename);
});
BridgeConnector.Socket.Emit("showSaveDialog",
- JObject.FromObject(browserWindow, _jsonSerializer),
- JObject.FromObject(options, _jsonSerializer),
+ browserWindow,
+ options,
guid);
return taskCompletionSource.Task;
@@ -148,28 +143,34 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
var guid = Guid.NewGuid().ToString();
- BridgeConnector.Socket.On("showMessageBoxComplete" + guid, (args) =>
+ BridgeConnector.Socket.On("showMessageBoxComplete" + guid, (args) =>
{
BridgeConnector.Socket.Off("showMessageBoxComplete" + guid);
- var result = ((JArray)args);
+ // args is [response:int, checkboxChecked:boolean]
+ var arr = args.EnumerateArray();
+ var e = arr.GetEnumerator();
+ e.MoveNext();
+ var response = e.Current.GetInt32();
+ e.MoveNext();
+ var checkbox = e.Current.GetBoolean();
taskCompletionSource.SetResult(new MessageBoxResult
{
- Response = (int)result.First,
- CheckboxChecked = (bool)result.Last
+ Response = response,
+ CheckboxChecked = checkbox
});
});
if (browserWindow == null)
{
- BridgeConnector.Socket.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer), guid);
+ BridgeConnector.Socket.Emit("showMessageBox", messageBoxOptions, guid);
}
else
{
BridgeConnector.Socket.Emit("showMessageBox",
- JObject.FromObject(browserWindow, _jsonSerializer),
- JObject.FromObject(messageBoxOptions, _jsonSerializer),
+ browserWindow,
+ messageBoxOptions,
guid);
}
@@ -223,18 +224,13 @@ namespace ElectronNET.API
});
BridgeConnector.Socket.Emit("showCertificateTrustDialog",
- JObject.FromObject(browserWindow, _jsonSerializer),
- JObject.FromObject(options, _jsonSerializer),
+ browserWindow,
+ options,
guid);
return taskCompletionSource.Task;
}
- private JsonSerializer _jsonSerializer = new JsonSerializer()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- NullValueHandling = NullValueHandling.Ignore,
- DefaultValueHandling = DefaultValueHandling.Ignore
- };
+
}
-}
\ No newline at end of file
+}
diff --git a/src/ElectronNET.API/API/Dock.cs b/src/ElectronNET.API/API/Dock.cs
index caf018e..1e6fc6f 100644
--- a/src/ElectronNET.API/API/Dock.cs
+++ b/src/ElectronNET.API/API/Dock.cs
@@ -1,11 +1,10 @@
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
using ElectronNET.API.Entities;
using ElectronNET.API.Extensions;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
+using ElectronNET.API.Serialization;
+using System.Collections.Generic;
+using System.Text.Json;
+using System.Threading;
+using System.Threading.Tasks;
namespace ElectronNET.API
{
@@ -57,10 +56,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("dock-bounce-completed", (id) =>
+ BridgeConnector.Socket.On("dock-bounce-completed", (id) =>
{
BridgeConnector.Socket.Off("dock-bounce-completed");
- taskCompletionSource.SetResult((int)id);
+ taskCompletionSource.SetResult(id);
});
BridgeConnector.Socket.Emit("dock-bounce", type.GetDescription());
@@ -109,10 +108,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("dock-getBadge-completed", (text) =>
+ BridgeConnector.Socket.On("dock-getBadge-completed", (text) =>
{
BridgeConnector.Socket.Off("dock-getBadge-completed");
- taskCompletionSource.SetResult((string)text);
+ taskCompletionSource.SetResult(text);
});
BridgeConnector.Socket.Emit("dock-getBadge");
@@ -151,10 +150,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource();
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
- BridgeConnector.Socket.On("dock-isVisible-completed", (isVisible) =>
+ BridgeConnector.Socket.On("dock-isVisible-completed", (isVisible) =>
{
BridgeConnector.Socket.Off("dock-isVisible-completed");
- taskCompletionSource.SetResult((bool)isVisible);
+ taskCompletionSource.SetResult(isVisible);
});
BridgeConnector.Socket.Emit("dock-isVisible");
@@ -186,13 +185,13 @@ namespace ElectronNET.API
public void SetMenu(MenuItem[] menuItems)
{
menuItems.AddMenuItemsId();
- BridgeConnector.Socket.Emit("dock-setMenu", JArray.FromObject(menuItems, _jsonSerializer));
+ BridgeConnector.Socket.Emit("dock-setMenu", new[] { menuItems });
_items.AddRange(menuItems);
BridgeConnector.Socket.Off("dockMenuItemClicked");
- BridgeConnector.Socket.On("dockMenuItemClicked", (id) =>
+ BridgeConnector.Socket.On("dockMenuItemClicked", (id) =>
{
- MenuItem menuItem = _items.GetMenuItem(id.ToString());
+ MenuItem menuItem = _items.GetMenuItem(id);
menuItem?.Click();
});
}
@@ -208,10 +207,10 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource