diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index c0be649..0e13d05 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -530,11 +530,6 @@ 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 /// closed, the event will be emitted and by default the application will terminate. This method @@ -586,7 +581,7 @@ namespace ElectronNET.API /// Options for the relaunch. public void Relaunch(RelaunchOptions relaunchOptions) { - BridgeConnector.EmitSync("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer)); + BridgeConnector.EmitSync("appRelaunch", relaunchOptions); } /// @@ -606,7 +601,7 @@ namespace ElectronNET.API /// public void Focus(FocusOptions focusOptions) { - BridgeConnector.Emit("appFocus", JObject.FromObject(focusOptions, _jsonSerializer)); + BridgeConnector.Emit("appFocus", focusOptions); } /// @@ -896,7 +891,7 @@ namespace ElectronNET.API /// Array of objects. /// The cancellation token. /// Whether the call succeeded. - public Task SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appSetUserTasks", "appSetUserTasksCompleted", cancellationToken, JArray.FromObject(userTasks, _jsonSerializer)); + public Task SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appSetUserTasks", "appSetUserTasksCompleted", cancellationToken, userTasks); /// /// Jump List settings for the application. @@ -923,7 +918,7 @@ namespace ElectronNET.API /// Array of objects. public void SetJumpList(JumpListCategory[] categories) { - BridgeConnector.Emit("appSetJumpList", JArray.FromObject(categories, _jsonSerializer)); + BridgeConnector.Emit("appSetJumpList", categories); } /// @@ -1059,7 +1054,7 @@ namespace ElectronNET.API /// /// The cancellation token. /// Result of import. Value of 0 indicates success. - public Task ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appImportCertificate", "appImportCertificateCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer)); + public Task ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default) => BridgeConnector.OnResult("appImportCertificate", "appImportCertificateCompleted", cancellationToken, options); /// /// Memory and cpu usage statistics of all the processes associated with the app. @@ -1125,7 +1120,7 @@ namespace ElectronNET.API /// The cancellation token. public Task GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default) => options is null ? BridgeConnector.OnResult("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken) - : BridgeConnector.OnResult("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer)); + : BridgeConnector.OnResult("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken, options); /// /// Set the app's login item settings. @@ -1135,7 +1130,7 @@ namespace ElectronNET.API /// public void SetLoginItemSettings(LoginSettings loginSettings) { - BridgeConnector.Emit("appSetLoginItemSettings", JObject.FromObject(loginSettings, _jsonSerializer)); + BridgeConnector.Emit("appSetLoginItemSettings", loginSettings); } /// @@ -1184,7 +1179,7 @@ namespace ElectronNET.API /// About panel options. public void SetAboutPanelOptions(AboutPanelOptions options) { - BridgeConnector.Emit("appSetAboutPanelOptions", JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("appSetAboutPanelOptions", options); } /// diff --git a/ElectronNET.API/AutoUpdater.cs b/ElectronNET.API/AutoUpdater.cs index 7f2e345..d21ed04 100644 --- a/ElectronNET.API/AutoUpdater.cs +++ b/ElectronNET.API/AutoUpdater.cs @@ -133,7 +133,7 @@ namespace ElectronNET.API { set { - BridgeConnector.Emit("autoUpdater-requestHeaders-set", JObject.FromObject(value, _jsonSerializer)); + BridgeConnector.Emit("autoUpdater-requestHeaders-set", value); } } @@ -468,10 +468,5 @@ namespace ElectronNET.API return taskCompletionSource.Task; } - - private readonly JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver() - }; } } diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index caa9c03..5329452 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -273,7 +273,9 @@ namespace ElectronNET.API { return new JsonSerializerSettings() { - ContractResolver = new CamelCasePropertyNamesContractResolver() + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore }; } } diff --git a/ElectronNET.API/BrowserView.cs b/ElectronNET.API/BrowserView.cs index 6b6e405..2e9eed3 100644 --- a/ElectronNET.API/BrowserView.cs +++ b/ElectronNET.API/BrowserView.cs @@ -31,24 +31,11 @@ namespace ElectronNET.API /// /// (experimental) /// - public Task GetBoundsAsync() - { - var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - - BridgeConnector.On("browserView-getBounds-reply", (result) => - { - BridgeConnector.Off("browserView-getBounds-reply"); - taskCompletionSource.SetResult(result); - }); - - BridgeConnector.Emit("browserView-getBounds", Id); - - return taskCompletionSource.Task; - } + public Task GetBoundsAsync() => BridgeConnector.OnResult("browserView-getBounds", "browserView-getBounds-reply", Id); public void SetBounds(Rectangle value) { - BridgeConnector.Emit("browserView-setBounds", Id, JObject.FromObject(value, _jsonSerializer)); + BridgeConnector.Emit("browserView-setBounds", Id, value); } /// @@ -69,7 +56,7 @@ namespace ElectronNET.API /// public void SetAutoResize(AutoResizeOptions options) { - BridgeConnector.Emit("browserView-setAutoResize", Id, JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("browserView-setAutoResize", Id, options); } /// @@ -82,11 +69,5 @@ namespace ElectronNET.API { BridgeConnector.Emit("browserView-setBackgroundColor", Id, color); } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs index 37fa676..ea9b697 100644 --- a/ElectronNET.API/BrowserWindow.cs +++ b/ElectronNET.API/BrowserWindow.cs @@ -949,19 +949,13 @@ namespace ElectronNET.API /// Whether the window is focused. /// /// - public Task IsFocusedAsync() - { - return BridgeConnector.OnResult("browserWindowIsFocused", "browserWindow-isFocused-completed", Id); - } + public Task IsFocusedAsync() => BridgeConnector.OnResult("browserWindowIsFocused", "browserWindow-isFocused-completed", Id); /// /// Whether the window is destroyed. /// /// - public Task IsDestroyedAsync() - { - return BridgeConnector.OnResult("browserWindowIsDestroyed", "browserWindow-isDestroyed-completed", Id); - } + public Task IsDestroyedAsync() => BridgeConnector.OnResult("browserWindowIsDestroyed", "browserWindow-isDestroyed-completed", Id); /// /// Shows and gives focus to the window. @@ -1088,7 +1082,7 @@ namespace ElectronNET.API /// The extra size not to be included while maintaining the aspect ratio. public void SetAspectRatio(int aspectRatio, Size extraSize) { - BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, JObject.FromObject(extraSize, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, extraSize); } /// @@ -1129,7 +1123,7 @@ namespace ElectronNET.API /// public void SetBounds(Rectangle bounds) { - BridgeConnector.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetBounds", Id, bounds); } /// @@ -1139,7 +1133,7 @@ namespace ElectronNET.API /// public void SetBounds(Rectangle bounds, bool animate) { - BridgeConnector.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate); + BridgeConnector.Emit("browserWindowSetBounds", Id, bounds, animate); } /// @@ -1157,7 +1151,7 @@ namespace ElectronNET.API /// public void SetContentBounds(Rectangle bounds) { - BridgeConnector.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetContentBounds", Id, bounds); } /// @@ -1167,7 +1161,7 @@ namespace ElectronNET.API /// public void SetContentBounds(Rectangle bounds, bool animate) { - BridgeConnector.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate); + BridgeConnector.Emit("browserWindowSetContentBounds", Id, bounds, animate); } /// @@ -1660,7 +1654,7 @@ namespace ElectronNET.API /// public void LoadURL(string url, LoadURLOptions options) { - BridgeConnector.Emit("browserWindowLoadURL", Id, url, JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("browserWindowLoadURL", Id, url, options); } /// @@ -1688,7 +1682,7 @@ namespace ElectronNET.API public void SetMenu(MenuItem[] menuItems) { menuItems.AddMenuItemsId(); - BridgeConnector.Emit("browserWindowSetMenu", Id, JArray.FromObject(menuItems, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetMenu", Id, menuItems); _items.AddRange(menuItems); BridgeConnector.Off("windowMenuItemClicked"); @@ -1737,7 +1731,7 @@ namespace ElectronNET.API /// public void SetProgressBar(double progress, ProgressBarOptions progressBarOptions) { - BridgeConnector.Emit("browserWindowSetProgressBar", Id, progress, JObject.FromObject(progressBarOptions, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetProgressBar", Id, progress, progressBarOptions); } /// @@ -1794,7 +1788,7 @@ namespace ElectronNET.API }); thumbarButtons.AddThumbarButtonsId(); - BridgeConnector.Emit("browserWindowSetThumbarButtons", Id, JArray.FromObject(thumbarButtons, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetThumbarButtons", Id, thumbarButtons); _thumbarButtons.Clear(); _thumbarButtons.AddRange(thumbarButtons); @@ -1837,7 +1831,7 @@ namespace ElectronNET.API /// public void SetAppDetails(AppDetailsOptions options) { - BridgeConnector.Emit("browserWindowSetAppDetails", Id, JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetAppDetails", Id, options); } /// @@ -1950,7 +1944,7 @@ namespace ElectronNET.API /// public void SetParentWindow(BrowserWindow parent) { - BridgeConnector.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer)); + BridgeConnector.Emit("browserWindowSetParentWindow", Id, parent); } /// @@ -2009,11 +2003,5 @@ namespace ElectronNET.API { BridgeConnector.Emit("browserWindow-setBrowserView", Id, browserView.Id); } - - private static readonly JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/Clipboard.cs b/ElectronNET.API/Clipboard.cs index 5df48b8..b757bb0 100644 --- a/ElectronNET.API/Clipboard.cs +++ b/ElectronNET.API/Clipboard.cs @@ -151,7 +151,7 @@ namespace ElectronNET.API /// public void Write(Data data, string type = "") { - BridgeConnector.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type); + BridgeConnector.Emit("clipboard-write", data, type); } /// @@ -170,12 +170,5 @@ namespace ElectronNET.API { BridgeConnector.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type); } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } } \ No newline at end of file diff --git a/ElectronNET.API/Cookies.cs b/ElectronNET.API/Cookies.cs index 13e6f63..67f16b0 100644 --- a/ElectronNET.API/Cookies.cs +++ b/ElectronNET.API/Cookies.cs @@ -71,7 +71,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(cookies); }); - BridgeConnector.Emit("webContents-session-cookies-get", Id, JObject.FromObject(filter, _jsonSerializer), guid); + BridgeConnector.Emit("webContents-session-cookies-get", Id, filter, guid); return taskCompletionSource.Task; } @@ -92,7 +92,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(null); }); - BridgeConnector.Emit("webContents-session-cookies-set", Id, JObject.FromObject(details, _jsonSerializer), guid); + BridgeConnector.Emit("webContents-session-cookies-set", Id, details, guid); return taskCompletionSource.Task; } @@ -138,12 +138,5 @@ namespace ElectronNET.API 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/ElectronNET.API/Dialog.cs b/ElectronNET.API/Dialog.cs index c8c8aeb..a8ecb82 100644 --- a/ElectronNET.API/Dialog.cs +++ b/ElectronNET.API/Dialog.cs @@ -56,6 +56,7 @@ namespace ElectronNET.API BridgeConnector.Off("showOpenDialogComplete" + guid); var list = new List(); + foreach (var item in filePaths) { list.Add(HttpUtility.UrlDecode(item)); @@ -63,10 +64,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(list.ToArray()); }); - - BridgeConnector.Emit("showOpenDialog", - JObject.FromObject(browserWindow, _jsonSerializer), - JObject.FromObject(options, _jsonSerializer), guid); + BridgeConnector.Emit("showOpenDialog", browserWindow, options, guid); return taskCompletionSource.Task; } @@ -89,10 +87,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(filename); }); - BridgeConnector.Emit("showSaveDialog", - JObject.FromObject(browserWindow, _jsonSerializer), - JObject.FromObject(options, _jsonSerializer), - guid); + BridgeConnector.Emit("showSaveDialog", browserWindow, options, guid); return taskCompletionSource.Task; } @@ -165,13 +160,10 @@ namespace ElectronNET.API if (browserWindow == null) { - BridgeConnector.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer), guid); + BridgeConnector.Emit("showMessageBox", messageBoxOptions, guid); } else { - BridgeConnector.Emit("showMessageBox", - JObject.FromObject(browserWindow, _jsonSerializer), - JObject.FromObject(messageBoxOptions, _jsonSerializer), - guid); + BridgeConnector.Emit("showMessageBox", browserWindow , messageBoxOptions, guid); } return taskCompletionSource.Task; @@ -223,19 +215,9 @@ namespace ElectronNET.API taskCompletionSource.SetResult(null); }); - BridgeConnector.Emit("showCertificateTrustDialog", - JObject.FromObject(browserWindow, _jsonSerializer), - JObject.FromObject(options, _jsonSerializer), - guid); + BridgeConnector.Emit("showCertificateTrustDialog", browserWindow, options, guid); return taskCompletionSource.Task; } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/Dock.cs b/ElectronNET.API/Dock.cs index 3860bd9..9706341 100644 --- a/ElectronNET.API/Dock.cs +++ b/ElectronNET.API/Dock.cs @@ -138,7 +138,7 @@ namespace ElectronNET.API public void SetMenu(MenuItem[] menuItems) { menuItems.AddMenuItemsId(); - BridgeConnector.Emit("dock-setMenu", JArray.FromObject(menuItems, _jsonSerializer)); + BridgeConnector.Emit("dock-setMenu", menuItems); _items.AddRange(menuItems); BridgeConnector.Off("dockMenuItemClicked"); @@ -163,11 +163,5 @@ namespace ElectronNET.API { BridgeConnector.Emit("dock-setIcon", image); } - - private static readonly JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; } } \ No newline at end of file diff --git a/ElectronNET.API/HostHook.cs b/ElectronNET.API/HostHook.cs index 93e1257..a5c4e9a 100644 --- a/ElectronNET.API/HostHook.cs +++ b/ElectronNET.API/HostHook.cs @@ -86,12 +86,5 @@ namespace ElectronNET.API return taskCompletionSource.Task; } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/Menu.cs b/ElectronNET.API/Menu.cs index aa98613..76bba2e 100644 --- a/ElectronNET.API/Menu.cs +++ b/ElectronNET.API/Menu.cs @@ -58,7 +58,7 @@ namespace ElectronNET.API menuItems.AddMenuItemsId(); menuItems.AddSubmenuTypes(); - BridgeConnector.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer)); + BridgeConnector.Emit("menu-setApplicationMenu", menuItems); _menuItems.AddRange(menuItems); BridgeConnector.Off("menuItemClicked"); @@ -87,7 +87,7 @@ namespace ElectronNET.API menuItems.AddMenuItemsId(); menuItems.AddSubmenuTypes(); - BridgeConnector.Emit("menu-setContextMenu", browserWindow.Id, JArray.FromObject(menuItems, _jsonSerializer)); + BridgeConnector.Emit("menu-setContextMenu", browserWindow.Id, menuItems); if (!_contextMenuItems.ContainsKey(browserWindow.Id)) { @@ -112,11 +112,5 @@ namespace ElectronNET.API { BridgeConnector.Emit("menu-contextMenuPopup", browserWindow.Id); } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/Notification.cs b/ElectronNET.API/Notification.cs index 5745cc5..7f93f96 100644 --- a/ElectronNET.API/Notification.cs +++ b/ElectronNET.API/Notification.cs @@ -48,7 +48,7 @@ namespace ElectronNET.API { GenerateIDsForDefinedActions(notificationOptions); - BridgeConnector.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer)); + BridgeConnector.Emit("createNotification", notificationOptions); } private static void GenerateIDsForDefinedActions(NotificationOptions notificationOptions) @@ -134,12 +134,5 @@ namespace ElectronNET.API return taskCompletionSource.Task; } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/Screen.cs b/ElectronNET.API/Screen.cs index dc40a8a..648bf0e 100644 --- a/ElectronNET.API/Screen.cs +++ b/ElectronNET.API/Screen.cs @@ -154,21 +154,13 @@ namespace ElectronNET.API /// The display nearest the specified point. /// /// The display nearest the specified point. - public Task GetDisplayNearestPointAsync(Point point) => BridgeConnector.OnResult("screen-getDisplayNearestPoint", "screen-getDisplayNearestPointCompleted", JObject.FromObject(point, _jsonSerializer)); + public Task GetDisplayNearestPointAsync(Point point) => BridgeConnector.OnResult("screen-getDisplayNearestPoint", "screen-getDisplayNearestPointCompleted", point); /// /// The display that most closely intersects the provided bounds. /// /// /// The display that most closely intersects the provided bounds. - public Task GetDisplayMatchingAsync(Rectangle rectangle) => BridgeConnector.OnResult("screen-getDisplayMatching", "screen-getDisplayMatching", JObject.FromObject(rectangle, _jsonSerializer)); - - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; + public Task GetDisplayMatchingAsync(Rectangle rectangle) => BridgeConnector.OnResult("screen-getDisplayMatching", "screen-getDisplayMatching", rectangle); } } \ No newline at end of file diff --git a/ElectronNET.API/Session.cs b/ElectronNET.API/Session.cs index f15f398..83bfa8f 100644 --- a/ElectronNET.API/Session.cs +++ b/ElectronNET.API/Session.cs @@ -56,7 +56,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(null); }); - BridgeConnector.Emit("webContents-session-clearAuthCache", Id, JObject.FromObject(options, _jsonSerializer), guid); + BridgeConnector.Emit("webContents-session-clearAuthCache", Id, options, guid); return taskCompletionSource.Task; } @@ -156,7 +156,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(null); }); - BridgeConnector.Emit("webContents-session-clearStorageData-options", Id, JObject.FromObject(options, _jsonSerializer), guid); + BridgeConnector.Emit("webContents-session-clearStorageData-options", Id, options, guid); return taskCompletionSource.Task; } @@ -171,7 +171,7 @@ namespace ElectronNET.API /// public void CreateInterruptedDownload(CreateInterruptedDownloadOptions options) { - BridgeConnector.Emit("webContents-session-createInterruptedDownload", Id, JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("webContents-session-createInterruptedDownload", Id, options); } /// @@ -189,7 +189,7 @@ namespace ElectronNET.API /// public void EnableNetworkEmulation(EnableNetworkEmulationOptions options) { - BridgeConnector.Emit("webContents-session-enableNetworkEmulation", Id, JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("webContents-session-enableNetworkEmulation", Id, options); } /// @@ -340,7 +340,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(null); }); - BridgeConnector.Emit("webContents-session-setProxy", Id, JObject.FromObject(config, _jsonSerializer), guid); + BridgeConnector.Emit("webContents-session-setProxy", Id, config, guid); return taskCompletionSource.Task; } @@ -444,12 +444,5 @@ namespace ElectronNET.API return taskCompletionSource.Task; } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/Shell.cs b/ElectronNET.API/Shell.cs index 89c5076..5bf82c4 100644 --- a/ElectronNET.API/Shell.cs +++ b/ElectronNET.API/Shell.cs @@ -110,7 +110,7 @@ namespace ElectronNET.API } else { - BridgeConnector.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("shell-openExternal", url, options); } return taskCompletionSource.Task; @@ -143,7 +143,7 @@ namespace ElectronNET.API /// Whether the shortcut was created successfully. public Task WriteShortcutLinkAsync(string shortcutPath, ShortcutLinkOperation operation, ShortcutDetails options) { - return BridgeConnector.OnResult("shell-writeShortcutLink", "shell-writeShortcutLinkCompleted", shortcutPath, operation.GetDescription(), JObject.FromObject(options, _jsonSerializer)); + return BridgeConnector.OnResult("shell-writeShortcutLink", "shell-writeShortcutLinkCompleted", shortcutPath, operation.GetDescription(), options); } /// @@ -156,12 +156,5 @@ namespace ElectronNET.API { return BridgeConnector.OnResult("shell-readShortcutLink", "shell-readShortcutLinkCompleted", shortcutPath); } - - private readonly JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } } diff --git a/ElectronNET.API/Tray.cs b/ElectronNET.API/Tray.cs index 252756c..fb5db5c 100644 --- a/ElectronNET.API/Tray.cs +++ b/ElectronNET.API/Tray.cs @@ -242,7 +242,7 @@ namespace ElectronNET.API public void Show(string image, MenuItem[] menuItems) { menuItems.AddMenuItemsId(); - BridgeConnector.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer)); + BridgeConnector.Emit("create-tray", image, menuItems); _items.Clear(); _items.AddRange(menuItems); @@ -314,34 +314,14 @@ namespace ElectronNET.API /// public void DisplayBalloon(DisplayBalloonOptions options) { - BridgeConnector.Emit("tray-displayBalloon", JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("tray-displayBalloon", options); } /// /// Whether the tray icon is destroyed. /// /// - public Task IsDestroyedAsync() - { - var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - - BridgeConnector.On("tray-isDestroyedCompleted", (isDestroyed) => - { - BridgeConnector.Off("tray-isDestroyedCompleted"); - - taskCompletionSource.SetResult(isDestroyed); - }); - - BridgeConnector.Emit("tray-isDestroyed"); - - return taskCompletionSource.Task; - } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; + public Task IsDestroyedAsync() => BridgeConnector.OnResult("tray-isDestroyed", "tray-isDestroyedCompleted"); private const string ModuleName = "tray"; /// diff --git a/ElectronNET.API/WebContents.cs b/ElectronNET.API/WebContents.cs index 6affad4..d3d4434 100644 --- a/ElectronNET.API/WebContents.cs +++ b/ElectronNET.API/WebContents.cs @@ -104,7 +104,7 @@ namespace ElectronNET.API /// public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions) { - BridgeConnector.Emit("webContentsOpenDevTools", Id, JObject.FromObject(openDevToolsOptions, _jsonSerializer)); + BridgeConnector.Emit("webContentsOpenDevTools", Id, openDevToolsOptions); } /// @@ -121,10 +121,8 @@ namespace ElectronNET.API /// /// /// success - public Task PrintAsync(PrintOptions options = null) - { - return BridgeConnector.OnResult("webContents-print", "webContents-print-completed", Id, options is null ? (object)"" : JObject.FromObject(options, _jsonSerializer)); - } + public Task PrintAsync(PrintOptions options = null) => options is null ? BridgeConnector.OnResult("webContents-print", "webContents-print-completed", Id, "") + : BridgeConnector.OnResult("webContents-print", "webContents-print-completed", Id, options); /// /// Prints window's web page as PDF with Chromium's preview printing custom @@ -135,10 +133,8 @@ namespace ElectronNET.API /// /// /// success - public Task PrintToPDFAsync(string path, PrintToPDFOptions options = null) - { - return BridgeConnector.OnResult("webContents-printToPDF", "webContents-printToPDF-completed", Id, options is null ? (object)"" : JObject.FromObject(options, _jsonSerializer), path); - } + public Task PrintToPDFAsync(string path, PrintToPDFOptions options = null) => options is null ? BridgeConnector.OnResult("webContents-printToPDF", "webContents-printToPDF-completed", Id, "", path) + : BridgeConnector.OnResult("webContents-printToPDF", "webContents-printToPDF-completed", Id, options, path); /// /// Is used to get the Url of the loaded page. @@ -198,7 +194,7 @@ namespace ElectronNET.API taskCompletionSource.SetException(new InvalidOperationException(error.ToString())); }); - BridgeConnector.Emit("webContents-loadURL", Id, url, JObject.FromObject(options, _jsonSerializer)); + BridgeConnector.Emit("webContents-loadURL", Id, url, options); return taskCompletionSource.Task; } @@ -214,12 +210,5 @@ namespace ElectronNET.API { BridgeConnector.Emit("webContents-insertCSS", Id, isBrowserWindow, path); } - - private static readonly JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } } \ No newline at end of file diff --git a/ElectronNET.API/WindowManager.cs b/ElectronNET.API/WindowManager.cs index 4860aab..cf91098 100644 --- a/ElectronNET.API/WindowManager.cs +++ b/ElectronNET.API/WindowManager.cs @@ -134,7 +134,7 @@ namespace ElectronNET.API options.X = 0; options.Y = 0; - BridgeConnector.Emit("createBrowserWindow", JObject.FromObject(options, _jsonSerializer), loadUrl); + BridgeConnector.Emit("createBrowserWindow", options, loadUrl); } else { @@ -194,21 +194,15 @@ namespace ElectronNET.API taskCompletionSource.SetResult(browserView); }); - var ownjsonSerializer = new JsonSerializer() + var keepDefaultValuesSerializer = new JsonSerializer() { ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Include }; - BridgeConnector.Emit("createBrowserView", JObject.FromObject(options, ownjsonSerializer)); + BridgeConnector.Emit("createBrowserView", JObject.FromObject(options, keepDefaultValuesSerializer)); return taskCompletionSource.Task; } - - private JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; } }