Remove unecessary JsonSerializer settings, fix default serializer

This commit is contained in:
rafael-aero
2021-08-23 11:57:42 +02:00
parent bf48bc8227
commit 31094f9d2b
18 changed files with 64 additions and 220 deletions

View File

@@ -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()
};
/// <summary>
/// Try to close all windows. The <see cref="BeforeQuit"/> event will be emitted first. If all windows are successfully
/// closed, the <see cref="WillQuit"/> event will be emitted and by default the application will terminate. This method
@@ -586,7 +581,7 @@ namespace ElectronNET.API
/// <param name="relaunchOptions">Options for the relaunch.</param>
public void Relaunch(RelaunchOptions relaunchOptions)
{
BridgeConnector.EmitSync("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer));
BridgeConnector.EmitSync("appRelaunch", relaunchOptions);
}
/// <summary>
@@ -606,7 +601,7 @@ namespace ElectronNET.API
/// </summary>
public void Focus(FocusOptions focusOptions)
{
BridgeConnector.Emit("appFocus", JObject.FromObject(focusOptions, _jsonSerializer));
BridgeConnector.Emit("appFocus", focusOptions);
}
/// <summary>
@@ -896,7 +891,7 @@ namespace ElectronNET.API
/// <param name="userTasks">Array of <see cref="UserTask"/> objects.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Whether the call succeeded.</returns>
public Task<bool> SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appSetUserTasks", "appSetUserTasksCompleted", cancellationToken, JArray.FromObject(userTasks, _jsonSerializer));
public Task<bool> SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<bool>("appSetUserTasks", "appSetUserTasksCompleted", cancellationToken, userTasks);
/// <summary>
/// Jump List settings for the application.
@@ -923,7 +918,7 @@ namespace ElectronNET.API
/// <param name="categories">Array of <see cref="JumpListCategory"/> objects.</param>
public void SetJumpList(JumpListCategory[] categories)
{
BridgeConnector.Emit("appSetJumpList", JArray.FromObject(categories, _jsonSerializer));
BridgeConnector.Emit("appSetJumpList", categories);
}
/// <summary>
@@ -1059,7 +1054,7 @@ namespace ElectronNET.API
/// <param name="options"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Result of import. Value of 0 indicates success.</returns>
public Task<int> ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<int>("appImportCertificate", "appImportCertificateCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer));
public Task<int> ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default) => BridgeConnector.OnResult<int>("appImportCertificate", "appImportCertificateCompleted", cancellationToken, options);
/// <summary>
/// Memory and cpu usage statistics of all the processes associated with the app.
@@ -1125,7 +1120,7 @@ namespace ElectronNET.API
/// <param name="cancellationToken">The cancellation token.</param>
public Task<LoginItemSettings> GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default) =>
options is null ? BridgeConnector.OnResult<LoginItemSettings>("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken)
: BridgeConnector.OnResult<LoginItemSettings>("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken, JObject.FromObject(options, _jsonSerializer));
: BridgeConnector.OnResult<LoginItemSettings>("appGetLoginItemSettings", "appGetLoginItemSettingsCompleted", cancellationToken, options);
/// <summary>
/// Set the app's login item settings.
@@ -1135,7 +1130,7 @@ namespace ElectronNET.API
/// <param name="loginSettings"></param>
public void SetLoginItemSettings(LoginSettings loginSettings)
{
BridgeConnector.Emit("appSetLoginItemSettings", JObject.FromObject(loginSettings, _jsonSerializer));
BridgeConnector.Emit("appSetLoginItemSettings", loginSettings);
}
/// <summary>
@@ -1184,7 +1179,7 @@ namespace ElectronNET.API
/// <param name="options">About panel options.</param>
public void SetAboutPanelOptions(AboutPanelOptions options)
{
BridgeConnector.Emit("appSetAboutPanelOptions", JObject.FromObject(options, _jsonSerializer));
BridgeConnector.Emit("appSetAboutPanelOptions", options);
}
/// <summary>

View File

@@ -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()
};
}
}

View File

@@ -273,7 +273,9 @@ namespace ElectronNET.API
{
return new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -31,24 +31,11 @@ namespace ElectronNET.API
///
/// (experimental)
/// </summary>
public Task<Rectangle> GetBoundsAsync()
{
var taskCompletionSource = new TaskCompletionSource<Rectangle>(TaskCreationOptions.RunContinuationsAsynchronously);
BridgeConnector.On<Rectangle>("browserView-getBounds-reply", (result) =>
{
BridgeConnector.Off("browserView-getBounds-reply");
taskCompletionSource.SetResult(result);
});
BridgeConnector.Emit("browserView-getBounds", Id);
return taskCompletionSource.Task;
}
public Task<Rectangle> GetBoundsAsync() => BridgeConnector.OnResult<Rectangle>("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);
}
/// <summary>
@@ -69,7 +56,7 @@ namespace ElectronNET.API
/// <param name="options"></param>
public void SetAutoResize(AutoResizeOptions options)
{
BridgeConnector.Emit("browserView-setAutoResize", Id, JObject.FromObject(options, _jsonSerializer));
BridgeConnector.Emit("browserView-setAutoResize", Id, options);
}
/// <summary>
@@ -82,11 +69,5 @@ namespace ElectronNET.API
{
BridgeConnector.Emit("browserView-setBackgroundColor", Id, color);
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
};
}
}

View File

@@ -949,19 +949,13 @@ namespace ElectronNET.API
/// Whether the window is focused.
/// </summary>
/// <returns></returns>
public Task<bool> IsFocusedAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsFocused", "browserWindow-isFocused-completed", Id);
}
public Task<bool> IsFocusedAsync() => BridgeConnector.OnResult<bool>("browserWindowIsFocused", "browserWindow-isFocused-completed", Id);
/// <summary>
/// Whether the window is destroyed.
/// </summary>
/// <returns></returns>
public Task<bool> IsDestroyedAsync()
{
return BridgeConnector.OnResult<bool>("browserWindowIsDestroyed", "browserWindow-isDestroyed-completed", Id);
}
public Task<bool> IsDestroyedAsync() => BridgeConnector.OnResult<bool>("browserWindowIsDestroyed", "browserWindow-isDestroyed-completed", Id);
/// <summary>
/// Shows and gives focus to the window.
@@ -1088,7 +1082,7 @@ namespace ElectronNET.API
/// <param name="extraSize">The extra size not to be included while maintaining the aspect ratio.</param>
public void SetAspectRatio(int aspectRatio, Size extraSize)
{
BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, JObject.FromObject(extraSize, _jsonSerializer));
BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, extraSize);
}
/// <summary>
@@ -1129,7 +1123,7 @@ namespace ElectronNET.API
/// <param name="bounds"></param>
public void SetBounds(Rectangle bounds)
{
BridgeConnector.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer));
BridgeConnector.Emit("browserWindowSetBounds", Id, bounds);
}
/// <summary>
@@ -1139,7 +1133,7 @@ namespace ElectronNET.API
/// <param name="animate"></param>
public void SetBounds(Rectangle bounds, bool animate)
{
BridgeConnector.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
BridgeConnector.Emit("browserWindowSetBounds", Id, bounds, animate);
}
/// <summary>
@@ -1157,7 +1151,7 @@ namespace ElectronNET.API
/// <param name="bounds"></param>
public void SetContentBounds(Rectangle bounds)
{
BridgeConnector.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer));
BridgeConnector.Emit("browserWindowSetContentBounds", Id, bounds);
}
/// <summary>
@@ -1167,7 +1161,7 @@ namespace ElectronNET.API
/// <param name="animate"></param>
public void SetContentBounds(Rectangle bounds, bool animate)
{
BridgeConnector.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
BridgeConnector.Emit("browserWindowSetContentBounds", Id, bounds, animate);
}
/// <summary>
@@ -1660,7 +1654,7 @@ namespace ElectronNET.API
/// <param name="options"></param>
public void LoadURL(string url, LoadURLOptions options)
{
BridgeConnector.Emit("browserWindowLoadURL", Id, url, JObject.FromObject(options, _jsonSerializer));
BridgeConnector.Emit("browserWindowLoadURL", Id, url, options);
}
/// <summary>
@@ -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
/// <param name="progressBarOptions"></param>
public void SetProgressBar(double progress, ProgressBarOptions progressBarOptions)
{
BridgeConnector.Emit("browserWindowSetProgressBar", Id, progress, JObject.FromObject(progressBarOptions, _jsonSerializer));
BridgeConnector.Emit("browserWindowSetProgressBar", Id, progress, progressBarOptions);
}
/// <summary>
@@ -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
/// <param name="options"></param>
public void SetAppDetails(AppDetailsOptions options)
{
BridgeConnector.Emit("browserWindowSetAppDetails", Id, JObject.FromObject(options, _jsonSerializer));
BridgeConnector.Emit("browserWindowSetAppDetails", Id, options);
}
/// <summary>
@@ -1950,7 +1944,7 @@ namespace ElectronNET.API
/// <param name="parent"></param>
public void SetParentWindow(BrowserWindow parent)
{
BridgeConnector.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
BridgeConnector.Emit("browserWindowSetParentWindow", Id, parent);
}
/// <summary>
@@ -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
};
}
}

View File

@@ -151,7 +151,7 @@ namespace ElectronNET.API
/// <param name="type"></param>
public void Write(Data data, string type = "")
{
BridgeConnector.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type);
BridgeConnector.Emit("clipboard-write", data, type);
}
/// <summary>
@@ -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
};
}
}

View File

@@ -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
};
}
}

View File

@@ -56,6 +56,7 @@ namespace ElectronNET.API
BridgeConnector.Off("showOpenDialogComplete" + guid);
var list = new List<string>();
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
};
}
}

View File

@@ -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
};
}
}

View File

@@ -86,12 +86,5 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -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
};
}
}

View File

@@ -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
};
}
}

View File

@@ -154,21 +154,13 @@ namespace ElectronNET.API
/// The display nearest the specified point.
/// </summary>
/// <returns>The display nearest the specified point.</returns>
public Task<Display> GetDisplayNearestPointAsync(Point point) => BridgeConnector.OnResult<Display>("screen-getDisplayNearestPoint", "screen-getDisplayNearestPointCompleted", JObject.FromObject(point, _jsonSerializer));
public Task<Display> GetDisplayNearestPointAsync(Point point) => BridgeConnector.OnResult<Display>("screen-getDisplayNearestPoint", "screen-getDisplayNearestPointCompleted", point);
/// <summary>
/// The display that most closely intersects the provided bounds.
/// </summary>
/// <param name="rectangle"></param>
/// <returns>The display that most closely intersects the provided bounds.</returns>
public Task<Display> GetDisplayMatchingAsync(Rectangle rectangle) => BridgeConnector.OnResult<Display>("screen-getDisplayMatching", "screen-getDisplayMatching", JObject.FromObject(rectangle, _jsonSerializer));
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
public Task<Display> GetDisplayMatchingAsync(Rectangle rectangle) => BridgeConnector.OnResult<Display>("screen-getDisplayMatching", "screen-getDisplayMatching", rectangle);
}
}

View File

@@ -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
/// <param name="options"></param>
public void CreateInterruptedDownload(CreateInterruptedDownloadOptions options)
{
BridgeConnector.Emit("webContents-session-createInterruptedDownload", Id, JObject.FromObject(options, _jsonSerializer));
BridgeConnector.Emit("webContents-session-createInterruptedDownload", Id, options);
}
/// <summary>
@@ -189,7 +189,7 @@ namespace ElectronNET.API
/// <param name="options"></param>
public void EnableNetworkEmulation(EnableNetworkEmulationOptions options)
{
BridgeConnector.Emit("webContents-session-enableNetworkEmulation", Id, JObject.FromObject(options, _jsonSerializer));
BridgeConnector.Emit("webContents-session-enableNetworkEmulation", Id, options);
}
/// <summary>
@@ -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
};
}
}

View File

@@ -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
/// <returns>Whether the shortcut was created successfully.</returns>
public Task<bool> WriteShortcutLinkAsync(string shortcutPath, ShortcutLinkOperation operation, ShortcutDetails options)
{
return BridgeConnector.OnResult<bool>("shell-writeShortcutLink", "shell-writeShortcutLinkCompleted", shortcutPath, operation.GetDescription(), JObject.FromObject(options, _jsonSerializer));
return BridgeConnector.OnResult<bool>("shell-writeShortcutLink", "shell-writeShortcutLinkCompleted", shortcutPath, operation.GetDescription(), options);
}
/// <summary>
@@ -156,12 +156,5 @@ namespace ElectronNET.API
{
return BridgeConnector.OnResult<ShortcutDetails>("shell-readShortcutLink", "shell-readShortcutLinkCompleted", shortcutPath);
}
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -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
/// <param name="options"></param>
public void DisplayBalloon(DisplayBalloonOptions options)
{
BridgeConnector.Emit("tray-displayBalloon", JObject.FromObject(options, _jsonSerializer));
BridgeConnector.Emit("tray-displayBalloon", options);
}
/// <summary>
/// Whether the tray icon is destroyed.
/// </summary>
/// <returns></returns>
public Task<bool> IsDestroyedAsync()
{
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
BridgeConnector.On<bool>("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<bool> IsDestroyedAsync() => BridgeConnector.OnResult<bool>("tray-isDestroyed", "tray-isDestroyedCompleted");
private const string ModuleName = "tray";
/// <summary>

View File

@@ -104,7 +104,7 @@ namespace ElectronNET.API
/// <param name="openDevToolsOptions"></param>
public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions)
{
BridgeConnector.Emit("webContentsOpenDevTools", Id, JObject.FromObject(openDevToolsOptions, _jsonSerializer));
BridgeConnector.Emit("webContentsOpenDevTools", Id, openDevToolsOptions);
}
/// <summary>
@@ -121,10 +121,8 @@ namespace ElectronNET.API
/// </summary>
/// <param name="options"></param>
/// <returns>success</returns>
public Task<bool> PrintAsync(PrintOptions options = null)
{
return BridgeConnector.OnResult<bool>("webContents-print", "webContents-print-completed", Id, options is null ? (object)"" : JObject.FromObject(options, _jsonSerializer));
}
public Task<bool> PrintAsync(PrintOptions options = null) => options is null ? BridgeConnector.OnResult<bool>("webContents-print", "webContents-print-completed", Id, "")
: BridgeConnector.OnResult<bool>("webContents-print", "webContents-print-completed", Id, options);
/// <summary>
/// Prints window's web page as PDF with Chromium's preview printing custom
@@ -135,10 +133,8 @@ namespace ElectronNET.API
/// <param name="path"></param>
/// <param name="options"></param>
/// <returns>success</returns>
public Task<bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null)
{
return BridgeConnector.OnResult<bool>("webContents-printToPDF", "webContents-printToPDF-completed", Id, options is null ? (object)"" : JObject.FromObject(options, _jsonSerializer), path);
}
public Task<bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null) => options is null ? BridgeConnector.OnResult<bool>("webContents-printToPDF", "webContents-printToPDF-completed", Id, "", path)
: BridgeConnector.OnResult<bool>("webContents-printToPDF", "webContents-printToPDF-completed", Id, options, path);
/// <summary>
/// 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
};
}
}

View File

@@ -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
};
}
}