diff --git a/src/ElectronNET.API/API/App.cs b/src/ElectronNET.API/API/App.cs index acf87237..a7233b03 100644 --- a/src/ElectronNET.API/API/App.cs +++ b/src/ElectronNET.API/API/App.cs @@ -45,13 +45,14 @@ public event Action WindowAllClosed BridgeConnector.Socket.Emit("register-app-window-all-closed", GetHashCode()); } + _windowAllClosed += value; } remove { _windowAllClosed -= value; - if(_windowAllClosed == null) + if (_windowAllClosed == null) BridgeConnector.Socket.Off("app-window-all-closed" + GetHashCode()); } } @@ -117,6 +118,7 @@ public event Func BeforeQuit BridgeConnector.Socket.Emit("register-app-before-quit", GetHashCode()); } + _beforeQuit += value; } remove @@ -168,6 +170,7 @@ public event Func WillQuit BridgeConnector.Socket.Emit("register-app-will-quit", GetHashCode()); } + _willQuit += value; } remove @@ -194,7 +197,7 @@ public event Func Quitting { BridgeConnector.Socket.On("app-will-quit" + GetHashCode() + "quitting", async () => { - if(_willQuit == null) + if (_willQuit == null) { await this._quitting().ConfigureAwait(false); Exit(); @@ -203,6 +206,7 @@ public event Func Quitting BridgeConnector.Socket.Emit("register-app-will-quit", GetHashCode() + "quitting"); } + _quitting += value; } remove @@ -276,11 +280,11 @@ public event Action AccessibilitySupportChanged /// /// Emitted when the application has finished basic startup. /// - public event Action Ready + public event Action Ready { add { - if(IsReady) + if (IsReady) { value(); } @@ -298,19 +302,23 @@ public event Action Ready /// /// Application host fully started. /// - public bool IsReady - { - get { return _isReady; } + public bool IsReady + { + get + { + return _isReady; + } internal set { _isReady = value; - if(value) + if (value) { _ready?.Invoke(); } } } + private bool _isReady = false; /// @@ -379,7 +387,7 @@ public Task NameAsync } - internal App() + internal App() { CommandLine = new CommandLine(); } @@ -392,7 +400,7 @@ internal static App Instance { lock (_syncRoot) { - if(_app == null) + if (_app == null) { _app = new App(); } @@ -541,7 +549,7 @@ public async Task GetPathAsync(PathName pathName, CancellationToken canc cancellationToken.ThrowIfCancellationRequested(); var taskCompletionSource = new TaskCompletionSource(); - using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) + using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) { BridgeConnector.Socket.On("appGetPathCompleted", (path) => { @@ -554,7 +562,7 @@ public async Task GetPathAsync(PathName pathName, CancellationToken canc return await taskCompletionSource.Task .ConfigureAwait(false); - } + } } /// @@ -715,7 +723,7 @@ public async Task SetAsDefaultProtocolClientAsync(string protocol, string BridgeConnector.Socket.On("appSetAsDefaultProtocolClientCompleted", (success) => { BridgeConnector.Socket.Off("appSetAsDefaultProtocolClientCompleted"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult((bool)success); }); BridgeConnector.Socket.Emit("appSetAsDefaultProtocolClient", protocol, path, args); @@ -760,7 +768,7 @@ public async Task RemoveAsDefaultProtocolClientAsync(string protocol, stri /// The cancellation token. /// Whether the call succeeded. public async Task RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default) - { + { cancellationToken.ThrowIfCancellationRequested(); var taskCompletionSource = new TaskCompletionSource(); @@ -769,7 +777,7 @@ public async Task RemoveAsDefaultProtocolClientAsync(string protocol, stri BridgeConnector.Socket.On("appRemoveAsDefaultProtocolClientCompleted", (success) => { BridgeConnector.Socket.Off("appRemoveAsDefaultProtocolClientCompleted"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult((bool)success); }); BridgeConnector.Socket.Emit("appRemoveAsDefaultProtocolClient", protocol, path, args); @@ -841,7 +849,7 @@ public async Task IsDefaultProtocolClientAsync(string protocol, string pat BridgeConnector.Socket.On("appIsDefaultProtocolClientCompleted", (success) => { BridgeConnector.Socket.Off("appIsDefaultProtocolClientCompleted"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult((bool)success); }); BridgeConnector.Socket.Emit("appIsDefaultProtocolClient", protocol, path, args); @@ -869,7 +877,7 @@ public async Task SetUserTasksAsync(UserTask[] userTasks, CancellationToke BridgeConnector.Socket.On("appSetUserTasksCompleted", (success) => { BridgeConnector.Socket.Off("appSetUserTasksCompleted"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult((bool)success); }); BridgeConnector.Socket.Emit("appSetUserTasks", JArray.FromObject(userTasks, _jsonSerializer)); @@ -1066,7 +1074,7 @@ public async Task ImportCertificateAsync(ImportCertificateOptions options, BridgeConnector.Socket.On("appImportCertificateCompleted", (result) => { BridgeConnector.Socket.Off("appImportCertificateCompleted"); - taskCompletionSource.SetResult((int) result); + taskCompletionSource.SetResult((int)result); }); BridgeConnector.Socket.Emit("appImportCertificate", JObject.FromObject(options, _jsonSerializer)); @@ -1122,7 +1130,7 @@ public async Task SetBadgeCountAsync(int count, CancellationToken cancella BridgeConnector.Socket.On("appSetBadgeCountCompleted", (success) => { BridgeConnector.Socket.Off("appSetBadgeCountCompleted"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult((bool)success); }); BridgeConnector.Socket.Emit("appSetBadgeCount", count); @@ -1183,7 +1191,7 @@ public async Task GetLoginItemSettingsAsync(LoginItemSettings { BridgeConnector.Socket.Off("appGetLoginItemSettingsCompleted"); - var result = ((JObject) loginItemSettings).ToObject(); + var result = ((JObject)loginItemSettings).ToObject(); taskCompletionSource.SetResult(result); }); @@ -1310,6 +1318,7 @@ internal void PreventQuit() private bool _preventQuit = false; private const string ModuleName = "app"; + /// /// Subscribe to an unmapped event on the module. /// @@ -1317,6 +1326,7 @@ internal void PreventQuit() /// The handler public void On(string eventName, Action action) => Events.Instance.On(ModuleName, eventName, action); + /// /// Subscribe to an unmapped event on the module. /// @@ -1324,6 +1334,7 @@ public void On(string eventName, Action action) /// The handler public async Task On(string eventName, Action action) => await Events.Instance.On(ModuleName, eventName, action).ConfigureAwait(false); + /// /// Subscribe to an unmapped event on the module once. /// @@ -1331,6 +1342,7 @@ public async Task On(string eventName, Action action) /// The handler public void Once(string eventName, Action action) => Events.Instance.Once(ModuleName, eventName, action); + /// /// Subscribe to an unmapped event on the module once. /// @@ -1339,4 +1351,4 @@ public void Once(string eventName, Action action) public async Task Once(string eventName, Action action) => await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false); } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/AutoUpdater.cs b/src/ElectronNET.API/API/AutoUpdater.cs index b06a5ab9..ed7e9e6a 100644 --- a/src/ElectronNET.API/API/AutoUpdater.cs +++ b/src/ElectronNET.API/API/AutoUpdater.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using ElectronNET.Common; + // ReSharper disable InconsistentNaming namespace ElectronNET.API @@ -249,7 +250,6 @@ public Task ChannelAsync } - /// /// The request headers. /// @@ -353,7 +353,9 @@ public event Action OnUpdateDownloaded private static AutoUpdater _autoUpdater; private static object _syncRoot = new object(); - internal AutoUpdater() { } + internal AutoUpdater() + { + } internal static AutoUpdater Instance { @@ -512,4 +514,4 @@ public Task GetFeedURLAsync() 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 96bddd7f..cc25226d 100644 --- a/src/ElectronNET.API/API/BrowserView.cs +++ b/src/ElectronNET.API/API/BrowserView.cs @@ -59,7 +59,7 @@ public Rectangle Bounds /// /// BrowserView /// - internal BrowserView(int id) + internal BrowserView(int id) { Id = id; @@ -94,4 +94,4 @@ public void SetBackgroundColor(string color) 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 6a385f82..d74b82c3 100644 --- a/src/ElectronNET.API/API/BrowserWindow.cs +++ b/src/ElectronNET.API/API/BrowserWindow.cs @@ -9,6 +9,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using ElectronNET.Common; + // ReSharper disable InconsistentNaming namespace ElectronNET.API; @@ -96,8 +97,8 @@ public event Action OnSessionEnd /// public event Action OnUnresponsive { - add => ApiEventManager.AddEvent("browserWindow-unresponsive", Id, _unresponsive, value); - remove => ApiEventManager.RemoveEvent("browserWindow-unresponsive", Id, _unresponsive, value); + add => ApiEventManager.AddEvent("browserWindow-unresponsive", Id, _unresponsive, value); + remove => ApiEventManager.RemoveEvent("browserWindow-unresponsive", Id, _unresponsive, value); } private event Action _unresponsive; @@ -752,6 +753,7 @@ public void SetPosition(int x, int y) { x = x - 7; } + this.CallMethod2(x, y); } @@ -769,6 +771,7 @@ public void SetPosition(int x, int y, bool animate) { x = x - 7; } + this.CallMethod3(x, y, animate); } @@ -906,7 +909,14 @@ private bool isWindows10() /// /// The menu items. /// - public IReadOnlyCollection MenuItems { get { return _items.AsReadOnly(); } } + public IReadOnlyCollection MenuItems + { + get + { + return _items.AsReadOnly(); + } + } + private List _items = new List(); /// @@ -981,7 +991,14 @@ public void SetProgressBar(double progress, ProgressBarOptions progressBarOption /// /// The thumbar buttons. /// - public IReadOnlyCollection ThumbarButtons { get { return _thumbarButtons.AsReadOnly(); } } + public IReadOnlyCollection ThumbarButtons + { + get + { + return _thumbarButtons.AsReadOnly(); + } + } + private List _thumbarButtons = new List(); /// diff --git a/src/ElectronNET.API/API/Clipboard.cs b/src/ElectronNET.API/API/Clipboard.cs index e7535378..4a808475 100644 --- a/src/ElectronNET.API/API/Clipboard.cs +++ b/src/ElectronNET.API/API/Clipboard.cs @@ -14,7 +14,9 @@ public sealed class Clipboard private static Clipboard _clipboard; private static object _syncRoot = new object(); - internal Clipboard() { } + internal Clipboard() + { + } internal static Clipboard Instance { @@ -253,14 +255,13 @@ public Task ReadImageAsync(string type = "") var nativeImage = ((JObject)image).ToObject(); taskCompletionSource.SetResult(nativeImage); - }); BridgeConnector.Socket.Emit("clipboard-readImage", type); - + return taskCompletionSource.Task; } - + /// /// Writes an image to the clipboard. /// diff --git a/src/ElectronNET.API/API/CommandLine.cs b/src/ElectronNET.API/API/CommandLine.cs index 63466b4b..184a3453 100644 --- a/src/ElectronNET.API/API/CommandLine.cs +++ b/src/ElectronNET.API/API/CommandLine.cs @@ -8,7 +8,9 @@ namespace ElectronNET.API /// public sealed class CommandLine { - internal CommandLine() { } + internal CommandLine() + { + } internal static CommandLine Instance { @@ -66,7 +68,7 @@ public void AppendArgument(string value) /// A command-line switch /// /// Whether the command-line switch is present. - public async Task HasSwitchAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken)) + public async Task HasSwitchAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); @@ -113,4 +115,4 @@ public void AppendArgument(string value) } } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Cookies.cs b/src/ElectronNET.API/API/Cookies.cs index 4959cd9a..9e35c0f2 100644 --- a/src/ElectronNET.API/API/Cookies.cs +++ b/src/ElectronNET.API/API/Cookies.cs @@ -44,6 +44,7 @@ public event Action OnChanged BridgeConnector.Socket.Emit("register-webContents-session-cookies-changed", Id); } + _changed += value; } remove diff --git a/src/ElectronNET.API/API/Dialog.cs b/src/ElectronNET.API/API/Dialog.cs index 11946074..a8085e0f 100644 --- a/src/ElectronNET.API/API/Dialog.cs +++ b/src/ElectronNET.API/API/Dialog.cs @@ -16,7 +16,9 @@ public sealed class Dialog private static Dialog _dialog; private static object _syncRoot = new object(); - internal Dialog() { } + internal Dialog() + { + } internal static Dialog Instance { @@ -26,7 +28,7 @@ internal static Dialog Instance { lock (_syncRoot) { - if(_dialog == null) + if (_dialog == null) { _dialog = new Dialog(); } @@ -60,8 +62,8 @@ public Task ShowOpenDialogAsync(BrowserWindow browserWindow, OpenDialo BridgeConnector.Socket.Emit("showOpenDialog", - JObject.FromObject(browserWindow, _jsonSerializer), - JObject.FromObject(options, _jsonSerializer), guid); + JObject.FromObject(browserWindow, _jsonSerializer), + JObject.FromObject(options, _jsonSerializer), guid); return taskCompletionSource.Task; } @@ -85,9 +87,9 @@ public Task ShowSaveDialogAsync(BrowserWindow browserWindow, SaveDialogO }); BridgeConnector.Socket.Emit("showSaveDialog", - JObject.FromObject(browserWindow, _jsonSerializer), - JObject.FromObject(options, _jsonSerializer), - guid); + JObject.FromObject(browserWindow, _jsonSerializer), + JObject.FromObject(options, _jsonSerializer), + guid); return taskCompletionSource.Task; } @@ -157,15 +159,15 @@ public Task ShowMessageBoxAsync(BrowserWindow browserWindow, M Response = (int)result.First, CheckboxChecked = (bool)result.Last }); - }); if (browserWindow == null) { BridgeConnector.Socket.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer), guid); - } else + } + else { - BridgeConnector.Socket.Emit("showMessageBox", + BridgeConnector.Socket.Emit("showMessageBox", JObject.FromObject(browserWindow, _jsonSerializer), JObject.FromObject(messageBoxOptions, _jsonSerializer), guid); @@ -235,4 +237,4 @@ public Task ShowCertificateTrustDialogAsync(BrowserWindow browserWindow, Certifi 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 03276842..caf018ec 100644 --- a/src/ElectronNET.API/API/Dock.cs +++ b/src/ElectronNET.API/API/Dock.cs @@ -60,7 +60,7 @@ public async Task BounceAsync(DockBounceType type, CancellationToken cancel BridgeConnector.Socket.On("dock-bounce-completed", (id) => { BridgeConnector.Socket.Off("dock-bounce-completed"); - taskCompletionSource.SetResult((int) id); + taskCompletionSource.SetResult((int)id); }); BridgeConnector.Socket.Emit("dock-bounce", type.GetDescription()); @@ -112,7 +112,7 @@ public async Task GetBadgeAsync(CancellationToken cancellationToken = de BridgeConnector.Socket.On("dock-getBadge-completed", (text) => { BridgeConnector.Socket.Off("dock-getBadge-completed"); - taskCompletionSource.SetResult((string) text); + taskCompletionSource.SetResult((string)text); }); BridgeConnector.Socket.Emit("dock-getBadge"); @@ -154,7 +154,7 @@ public async Task IsVisibleAsync(CancellationToken cancellationToken = def BridgeConnector.Socket.On("dock-isVisible-completed", (isVisible) => { BridgeConnector.Socket.Off("dock-isVisible-completed"); - taskCompletionSource.SetResult((bool) isVisible); + taskCompletionSource.SetResult((bool)isVisible); }); BridgeConnector.Socket.Emit("dock-isVisible"); @@ -170,7 +170,14 @@ public async Task IsVisibleAsync(CancellationToken cancellationToken = def /// /// The menu items. /// - public IReadOnlyCollection MenuItems { get { return _items.AsReadOnly(); } } + public IReadOnlyCollection MenuItems + { + get + { + return _items.AsReadOnly(); + } + } + private List _items = new List(); /// @@ -183,11 +190,11 @@ public void SetMenu(MenuItem[] 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?.Click(); }); - } /// diff --git a/src/ElectronNET.API/API/Electron.cs b/src/ElectronNET.API/API/Electron.cs index 5c636164..9148016a 100644 --- a/src/ElectronNET.API/API/Electron.cs +++ b/src/ElectronNET.API/API/Electron.cs @@ -8,62 +8,134 @@ public static class Electron /// /// Communicate asynchronously from the main process to renderer processes. /// - public static IpcMain IpcMain { get { return IpcMain.Instance; } } + public static IpcMain IpcMain + { + get + { + return IpcMain.Instance; + } + } /// /// Control your application's event lifecycle. /// - public static App App { get { return App.Instance; } } + public static App App + { + get + { + return App.Instance; + } + } /// /// Enable apps to automatically update themselves. Based on electron-updater. /// - public static AutoUpdater AutoUpdater { get { return AutoUpdater.Instance; } } + public static AutoUpdater AutoUpdater + { + get + { + return AutoUpdater.Instance; + } + } /// /// Control your windows. /// - public static WindowManager WindowManager { get { return WindowManager.Instance; } } + public static WindowManager WindowManager + { + get + { + return WindowManager.Instance; + } + } /// /// Create native application menus and context menus. /// - public static Menu Menu { get { return Menu.Instance; } } + public static Menu Menu + { + get + { + return Menu.Instance; + } + } /// /// Display native system dialogs for opening and saving files, alerting, etc. /// - public static Dialog Dialog { get { return Dialog.Instance; } } + public static Dialog Dialog + { + get + { + return Dialog.Instance; + } + } /// /// Create OS desktop notifications /// - public static Notification Notification { get { return Notification.Instance; } } + public static Notification Notification + { + get + { + return Notification.Instance; + } + } /// /// Add icons and context menus to the system’s notification area. /// - public static Tray Tray { get { return Tray.Instance; } } + public static Tray Tray + { + get + { + return Tray.Instance; + } + } /// /// Detect keyboard events when the application does not have keyboard focus. /// - public static GlobalShortcut GlobalShortcut { get { return GlobalShortcut.Instance; } } + public static GlobalShortcut GlobalShortcut + { + get + { + return GlobalShortcut.Instance; + } + } /// /// Manage files and URLs using their default applications. /// - public static Shell Shell { get { return Shell.Instance; } } + public static Shell Shell + { + get + { + return Shell.Instance; + } + } /// /// Retrieve information about screen size, displays, cursor position, etc. /// - public static Screen Screen { get { return Screen.Instance; } } + public static Screen Screen + { + get + { + return Screen.Instance; + } + } /// /// Perform copy and paste operations on the system clipboard. /// - public static Clipboard Clipboard { get { return Clipboard.Instance; } } + public static Clipboard Clipboard + { + get + { + return Clipboard.Instance; + } + } /// /// Allows you to execute native JavaScript/TypeScript code from the host process. @@ -72,26 +144,56 @@ public static class Electron /// ElectronHostHook directory: /// electronize add HostHook /// - public static HostHook HostHook { get { return HostHook.Instance; } } + public static HostHook HostHook + { + get + { + return HostHook.Instance; + } + } /// /// Allows you to execute native Lock and Unlock process. /// - public static PowerMonitor PowerMonitor { get { return PowerMonitor.Instance; } } + public static PowerMonitor PowerMonitor + { + get + { + return PowerMonitor.Instance; + } + } /// /// Read and respond to changes in Chromium's native color theme. /// - public static NativeTheme NativeTheme { get { return NativeTheme.Instance; } } + public static NativeTheme NativeTheme + { + get + { + return NativeTheme.Instance; + } + } /// /// Control your app in the macOS dock. /// - public static Dock Dock { get { return Dock.Instance; } } + public static Dock Dock + { + get + { + return Dock.Instance; + } + } /// /// Electeon extensions to the Nodejs process object. /// - public static Process Process { get { return Process.Instance; } } + public static Process Process + { + get + { + return Process.Instance; + } + } } } \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/AddRepresentationOptions.cs b/src/ElectronNET.API/API/Entities/AddRepresentationOptions.cs index 476fcbba..96da0cb9 100644 --- a/src/ElectronNET.API/API/Entities/AddRepresentationOptions.cs +++ b/src/ElectronNET.API/API/Entities/AddRepresentationOptions.cs @@ -28,6 +28,6 @@ public class AddRepresentationOptions /// /// Gets or sets the dataURL /// - public string DataUrl { get; set; } + public string DataUrl { get; set; } } } \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/CookieChangedCause.cs b/src/ElectronNET.API/API/Entities/CookieChangedCause.cs index d42430da..32b81271 100644 --- a/src/ElectronNET.API/API/Entities/CookieChangedCause.cs +++ b/src/ElectronNET.API/API/Entities/CookieChangedCause.cs @@ -1,12 +1,13 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; -namespace ElectronNET.API.Entities { +namespace ElectronNET.API.Entities +{ /// /// The cause of the change /// [JsonConverter(typeof(StringEnumConverter))] - public enum CookieChangedCause + public enum CookieChangedCause { /// ///The cookie was changed directly by a consumer's action. diff --git a/src/ElectronNET.API/API/Entities/CookieDetails.cs b/src/ElectronNET.API/API/Entities/CookieDetails.cs index a91d278b..3c44de6a 100644 --- a/src/ElectronNET.API/API/Entities/CookieDetails.cs +++ b/src/ElectronNET.API/API/Entities/CookieDetails.cs @@ -1,10 +1,12 @@ using System.ComponentModel; -namespace ElectronNET.API.Entities { +namespace ElectronNET.API.Entities +{ /// /// /// - public class CookieDetails { + public class CookieDetails + { /// /// The URL to associate the cookie with. The callback will be rejected if the URL is invalid. /// @@ -19,7 +21,7 @@ public class CookieDetails { /// /// (optional) - The value of the cookie. Empty by default if omitted. /// - [DefaultValue("")] + [DefaultValue("")] public string Value { get; set; } /// @@ -31,13 +33,13 @@ public class CookieDetails { /// /// (optional) - The path of the cookie. Empty by default if omitted. /// - [DefaultValue("")] + [DefaultValue("")] public string Path { get; set; } /// /// (optional) - Whether the cookie is marked as secure. Defaults to false. /// - [DefaultValue(false)] + [DefaultValue(false)] public bool Secure { get; set; } /// @@ -53,4 +55,4 @@ public class CookieDetails { [DefaultValue(0)] public long ExpirationDate { get; set; } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/CookieFilter.cs b/src/ElectronNET.API/API/Entities/CookieFilter.cs index 41d3f04b..67e8acb2 100644 --- a/src/ElectronNET.API/API/Entities/CookieFilter.cs +++ b/src/ElectronNET.API/API/Entities/CookieFilter.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using System.Text; -namespace ElectronNET.API.Entities +namespace ElectronNET.API.Entities { /// /// /// - public class CookieFilter + public class CookieFilter { /// /// (optional) - Retrieves cookies which are associated with url.Empty implies retrieving cookies of all URLs. @@ -38,6 +38,5 @@ public class CookieFilter /// (optional) - Filters out session or persistent cookies. /// public bool Session { get; set; } - } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/ImportCertificateOptions.cs b/src/ElectronNET.API/API/Entities/ImportCertificateOptions.cs index cb8775aa..3a93dc68 100644 --- a/src/ElectronNET.API/API/Entities/ImportCertificateOptions.cs +++ b/src/ElectronNET.API/API/Entities/ImportCertificateOptions.cs @@ -9,10 +9,10 @@ public class ImportCertificateOptions /// Path for the pkcs12 file. /// public string Certificate { get; set; } - + /// /// Passphrase for the certificate. /// - public string Password {get; set; } + public string Password { get; set; } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/InputEventType.cs b/src/ElectronNET.API/API/Entities/InputEventType.cs index c2d82473..a64f11d6 100644 --- a/src/ElectronNET.API/API/Entities/InputEventType.cs +++ b/src/ElectronNET.API/API/Entities/InputEventType.cs @@ -9,26 +9,32 @@ public enum InputEventType /// /// undefined, + /// /// /// mouseDown, + /// /// /// mouseUp, + /// /// /// mouseMove, + /// /// /// mouseEnter, + /// /// /// mouseLeave, + /// /// /// diff --git a/src/ElectronNET.API/API/Entities/NativeImage.cs b/src/ElectronNET.API/API/Entities/NativeImage.cs index e1066bed..7904d246 100644 --- a/src/ElectronNET.API/API/Entities/NativeImage.cs +++ b/src/ElectronNET.API/API/Entities/NativeImage.cs @@ -21,9 +21,9 @@ public class NativeImage private static readonly Dictionary ScaleFactorPairs = new Dictionary { - {"@2x", 2.0f}, {"@3x", 3.0f}, {"@1x", 1.0f}, {"@4x", 4.0f}, - {"@5x", 5.0f}, {"@1.25x", 1.25f}, {"@1.33x", 1.33f}, {"@1.4x", 1.4f}, - {"@1.5x", 1.5f}, {"@1.8x", 1.8f}, {"@2.5x", 2.5f} + { "@2x", 2.0f }, { "@3x", 3.0f }, { "@1x", 1.0f }, { "@4x", 4.0f }, + { "@5x", 5.0f }, { "@1.25x", 1.25f }, { "@1.33x", 1.33f }, { "@1.4x", 1.4f }, + { "@1.5x", 1.5f }, { "@1.8x", 1.8f }, { "@2.5x", 2.5f } }; private static float? ExtractDpiFromFilePath(string filePath) @@ -34,6 +34,7 @@ public class NativeImage .Select(p => p.Value) .FirstOrDefault(); } + private static Image BytesToImage(byte[] bytes) { var ms = new MemoryStream(bytes); @@ -83,7 +84,7 @@ public static NativeImage CreateFromBuffer(byte[] buffer, CreateFromBufferOption /// A data URL with a base64 encoded image. public static NativeImage CreateFromDataURL(string dataUrl) { - var images = new Dictionary(); + var images = new Dictionary(); var parsedDataUrl = Regex.Match(dataUrl, @"data:image/(?.+?),(?.+)"); var actualData = parsedDataUrl.Groups["data"].Value; var binData = Convert.FromBase64String(actualData); @@ -101,7 +102,7 @@ public static NativeImage CreateFromDataURL(string dataUrl) /// The path of the image public static NativeImage CreateFromPath(string path) { - var images = new Dictionary(); + var images = new Dictionary(); if (Regex.IsMatch(path, "(@.+?x)")) { var dpi = ExtractDpiFromFilePath(path); @@ -164,7 +165,7 @@ public NativeImage(Dictionary imageDictionary) /// public NativeImage Crop(Rectangle rect) { - var images = new Dictionary(); + var images = new Dictionary(); foreach (var image in _images) { images.Add(image.Key, Crop(rect.X, rect.Y, rect.Width, rect.Height, image.Key)); @@ -196,7 +197,7 @@ public void AddRepresentation(AddRepresentationOptions options) if (options.Buffer.Length > 0) { _images[options.ScaleFactor] = - CreateFromBuffer(options.Buffer, new CreateFromBufferOptions {ScaleFactor = options.ScaleFactor}) + CreateFromBuffer(options.Buffer, new CreateFromBufferOptions { ScaleFactor = options.ScaleFactor }) .GetScale(options.ScaleFactor); } else if (!string.IsNullOrEmpty(options.DataUrl)) @@ -225,7 +226,7 @@ public float GetAspectRatio(float scaleFactor = 1.0f) /// public byte[] GetBitmap(BitmapOptions options) { - return ToBitmap(new ToBitmapOptions{ ScaleFactor = options.ScaleFactor }); + return ToBitmap(new ToBitmapOptions { ScaleFactor = options.ScaleFactor }); } /// @@ -419,12 +420,13 @@ private ImageCodecInfo GetEncoder(ImageFormat format) return codec; } } + return null; } - internal Dictionary GetAllScaledImages() + internal Dictionary GetAllScaledImages() { - var dict = new Dictionary(); + var dict = new Dictionary(); try { foreach (var (scale, image) in _images) @@ -436,7 +438,7 @@ internal Dictionary GetAllScaledImages() { Console.WriteLine(ex); } - + return dict; } @@ -450,4 +452,4 @@ internal Image GetScale(float scaleFactor) return null; } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/NativeImageJsonConverter.cs b/src/ElectronNET.API/API/Entities/NativeImageJsonConverter.cs index a82c38ec..ac564a28 100644 --- a/src/ElectronNET.API/API/Entities/NativeImageJsonConverter.cs +++ b/src/ElectronNET.API/API/Entities/NativeImageJsonConverter.cs @@ -26,9 +26,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var bytes = Convert.FromBase64String(item.Value); newDictionary.Add(item.Key, Image.FromStream(new MemoryStream(bytes))); } + return new NativeImage(newDictionary); } public override bool CanConvert(Type objectType) => objectType == typeof(NativeImage); } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/PrintOptions.cs b/src/ElectronNET.API/API/Entities/PrintOptions.cs index 4b106b38..bb3f6188 100644 --- a/src/ElectronNET.API/API/Entities/PrintOptions.cs +++ b/src/ElectronNET.API/API/Entities/PrintOptions.cs @@ -67,7 +67,7 @@ public class PrintOptions /// true for landscape, false for portrait. /// public bool Landscape { get; set; } - + /// /// The scale factor of the web page /// @@ -102,6 +102,5 @@ public class PrintOptions /// Dpi /// public PrintDpi Dpi { get; set; } - } } \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/PrinterInfo.cs b/src/ElectronNET.API/API/Entities/PrinterInfo.cs index 07062797..88b2f44a 100644 --- a/src/ElectronNET.API/API/Entities/PrinterInfo.cs +++ b/src/ElectronNET.API/API/Entities/PrinterInfo.cs @@ -14,7 +14,7 @@ public class PrinterInfo /// Name /// public string Description { get; set; } - + /// /// Status /// @@ -24,6 +24,5 @@ public class PrinterInfo /// Is default /// public bool IsDefault { get; set; } - } } \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/SemVer.cs b/src/ElectronNET.API/API/Entities/SemVer.cs index e1a08f10..abac145a 100644 --- a/src/ElectronNET.API/API/Entities/SemVer.cs +++ b/src/ElectronNET.API/API/Entities/SemVer.cs @@ -8,35 +8,43 @@ public class SemVer /// /// /// - public string Raw { get; set; } + public string Raw { get; set; } + /// /// /// public bool Loose { get; set; } + /// /// /// public SemVerOptions Options { get; set; } + /// /// /// public int Major { get; set; } + /// /// /// public int Minor { get; set; } + /// /// /// public int Patch { get; set; } + /// /// /// public string Version { get; set; } + /// /// /// public string[] Build { get; set; } + /// /// /// @@ -46,14 +54,16 @@ public class SemVer /// /// /// - public class SemVerOptions { + public class SemVerOptions + { /// /// /// public bool? Loose { get; set; } + /// /// /// public bool? IncludePrerelease { get; set; } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/UpdateCancellationToken.cs b/src/ElectronNET.API/API/Entities/UpdateCancellationToken.cs index f89348c1..84b9c3c7 100644 --- a/src/ElectronNET.API/API/Entities/UpdateCancellationToken.cs +++ b/src/ElectronNET.API/API/Entities/UpdateCancellationToken.cs @@ -15,7 +15,6 @@ public class UpdateCancellationToken /// public void Cancel() { - } /// @@ -23,7 +22,6 @@ public void Cancel() /// public void Dispose() { - } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Entities/UploadRawData.cs b/src/ElectronNET.API/API/Entities/UploadRawData.cs index d0a98de6..c1577978 100644 --- a/src/ElectronNET.API/API/Entities/UploadRawData.cs +++ b/src/ElectronNET.API/API/Entities/UploadRawData.cs @@ -9,7 +9,7 @@ public class UploadRawData : IPostData /// The data is available as a Buffer, in the rawData field. /// public string Type { get; } = "rawData"; - + /// /// The raw bytes of the post data in a Buffer. /// diff --git a/src/ElectronNET.API/API/Extensions/EnumExtensions.cs b/src/ElectronNET.API/API/Extensions/EnumExtensions.cs index 4424310e..42604586 100644 --- a/src/ElectronNET.API/API/Extensions/EnumExtensions.cs +++ b/src/ElectronNET.API/API/Extensions/EnumExtensions.cs @@ -27,8 +27,9 @@ public static string GetDescription(this T enumerationValue) where T : struct return ((DescriptionAttribute)attrs[0]).Description; } } + //If we have no description attribute, just return the ToString of the enum return enumerationValue.ToString(); } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Extensions/MenuItemExtensions.cs b/src/ElectronNET.API/API/Extensions/MenuItemExtensions.cs index 37a5b9cb..d0114172 100644 --- a/src/ElectronNET.API/API/Extensions/MenuItemExtensions.cs +++ b/src/ElectronNET.API/API/Extensions/MenuItemExtensions.cs @@ -56,7 +56,7 @@ public static MenuItem[] AddSubmenuTypes(this MenuItem[] menuItems) var menuItem = menuItems[index]; if (menuItem?.Submenu?.Length > 0) { - if(menuItem.Type == MenuType.normal) + if (menuItem.Type == MenuType.normal) { menuItem.Type = MenuType.submenu; } @@ -68,4 +68,4 @@ public static MenuItem[] AddSubmenuTypes(this MenuItem[] menuItems) return menuItems; } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/GlobalShortcut.cs b/src/ElectronNET.API/API/GlobalShortcut.cs index d2867ecd..ec20d551 100644 --- a/src/ElectronNET.API/API/GlobalShortcut.cs +++ b/src/ElectronNET.API/API/GlobalShortcut.cs @@ -12,7 +12,9 @@ public sealed class GlobalShortcut private static GlobalShortcut _globalShortcut; private static object _syncRoot = new object(); - internal GlobalShortcut() { } + internal GlobalShortcut() + { + } internal static GlobalShortcut Instance { diff --git a/src/ElectronNET.API/API/HostHook.cs b/src/ElectronNET.API/API/HostHook.cs index 37606250..7f0dd625 100644 --- a/src/ElectronNET.API/API/HostHook.cs +++ b/src/ElectronNET.API/API/HostHook.cs @@ -17,9 +17,11 @@ public sealed class HostHook { private static HostHook _electronHostHook; private static object _syncRoot = new object(); - string oneCallguid = Guid.NewGuid().ToString(); + private string oneCallguid = Guid.NewGuid().ToString(); - internal HostHook() { } + internal HostHook() + { + } internal static HostHook Instance { @@ -125,4 +127,4 @@ public Task CallAsync(string socketEventName, params dynamic[] arguments) DefaultValueHandling = DefaultValueHandling.Ignore }; } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/IpcMain.cs b/src/ElectronNET.API/API/IpcMain.cs index 31122d18..c4eed197 100644 --- a/src/ElectronNET.API/API/IpcMain.cs +++ b/src/ElectronNET.API/API/IpcMain.cs @@ -17,17 +17,19 @@ public sealed class IpcMain private static IpcMain _ipcMain; private static object _syncRoot = new object(); - internal IpcMain() { } + internal IpcMain() + { + } internal static IpcMain Instance { get { - if(_ipcMain == null) + if (_ipcMain == null) { lock (_syncRoot) { - if(_ipcMain == null) + if (_ipcMain == null) { _ipcMain = new IpcMain(); } @@ -48,11 +50,11 @@ public async Task On(string channel, Action listener) { await BridgeConnector.Socket.Emit("registerIpcMainChannel", channel).ConfigureAwait(false); BridgeConnector.Socket.Off(channel); - BridgeConnector.Socket.On(channel, (args) => + BridgeConnector.Socket.On(channel, (args) => { List objectArray = FormatArguments(args); - if(objectArray.Count == 1) + if (objectArray.Count == 1) { listener(objectArray.First()); } @@ -91,7 +93,8 @@ private List FormatArguments(object args) public void OnSync(string channel, Func listener) { BridgeConnector.Socket.Emit("registerSyncIpcMainChannel", channel); - BridgeConnector.Socket.On(channel, (args) => { + BridgeConnector.Socket.On(channel, (args) => + { List objectArray = FormatArguments(args); object parameter; if (objectArray.Count == 1) @@ -158,19 +161,21 @@ public void Send(BrowserWindow browserWindow, string channel, params object[] da foreach (var parameterObject in data) { - if(parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable) + if (parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable) { jarrays.Add(JArray.FromObject(parameterObject, _jsonSerializer)); - } else if(parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string)) + } + else if (parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string)) { jobjects.Add(JObject.FromObject(parameterObject, _jsonSerializer)); - } else if(parameterObject.GetType().IsPrimitive || (parameterObject is string)) + } + else if (parameterObject.GetType().IsPrimitive || (parameterObject is string)) { objects.Add(parameterObject); } } - if(jobjects.Count > 0 || jarrays.Count > 0) + if (jobjects.Count > 0 || jarrays.Count > 0) { BridgeConnector.Socket.Emit("sendToIpcRenderer", JObject.FromObject(browserWindow, _jsonSerializer), channel, jarrays.ToArray(), jobjects.ToArray(), objects.ToArray()); } @@ -197,19 +202,21 @@ public void Send(BrowserView browserView, string channel, params object[] data) foreach (var parameterObject in data) { - if(parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable) + if (parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable) { jarrays.Add(JArray.FromObject(parameterObject, _jsonSerializer)); - } else if(parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string)) + } + else if (parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string)) { jobjects.Add(JObject.FromObject(parameterObject, _jsonSerializer)); - } else if(parameterObject.GetType().IsPrimitive || (parameterObject is string)) + } + else if (parameterObject.GetType().IsPrimitive || (parameterObject is string)) { objects.Add(parameterObject); } } - if(jobjects.Count > 0 || jarrays.Count > 0) + if (jobjects.Count > 0 || jarrays.Count > 0) { BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, jarrays.ToArray(), jobjects.ToArray(), objects.ToArray()); } diff --git a/src/ElectronNET.API/API/Menu.cs b/src/ElectronNET.API/API/Menu.cs index 8397a10d..bb98d501 100644 --- a/src/ElectronNET.API/API/Menu.cs +++ b/src/ElectronNET.API/API/Menu.cs @@ -17,7 +17,9 @@ public sealed class Menu private static Menu _menu; private static object _syncRoot = new object(); - internal Menu() { } + internal Menu() + { + } internal static Menu Instance { @@ -27,7 +29,7 @@ internal static Menu Instance { lock (_syncRoot) { - if(_menu == null) + if (_menu == null) { _menu = new Menu(); } @@ -44,7 +46,14 @@ internal static Menu Instance /// /// The menu items. /// - public IReadOnlyCollection MenuItems { get { return _menuItems.AsReadOnly(); } } + public IReadOnlyCollection MenuItems + { + get + { + return _menuItems.AsReadOnly(); + } + } + private List _menuItems = new List(); /// @@ -62,7 +71,8 @@ public void SetApplicationMenu(MenuItem[] menuItems) _menuItems.AddRange(menuItems); BridgeConnector.Socket.Off("menuItemClicked"); - BridgeConnector.Socket.On("menuItemClicked", (id) => { + BridgeConnector.Socket.On("menuItemClicked", (id) => + { MenuItem menuItem = _menuItems.GetMenuItem(id.ToString()); menuItem.Click?.Invoke(); }); @@ -75,6 +85,7 @@ public void SetApplicationMenu(MenuItem[] menuItems) /// The context menu items. /// public IReadOnlyDictionary> ContextMenuItems { get; internal set; } + private Dictionary> _contextMenuItems = new Dictionary>(); /// @@ -122,4 +133,4 @@ public void ContextMenuPopup(BrowserWindow browserWindow) NullValueHandling = NullValueHandling.Ignore }; } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/NativeTheme.cs b/src/ElectronNET.API/API/NativeTheme.cs index 2dfd2103..d38abc35 100644 --- a/src/ElectronNET.API/API/NativeTheme.cs +++ b/src/ElectronNET.API/API/NativeTheme.cs @@ -14,7 +14,9 @@ public sealed class NativeTheme private static NativeTheme _nativeTheme; private static object _syncRoot = new object(); - internal NativeTheme() { } + internal NativeTheme() + { + } internal static NativeTheme Instance { @@ -129,7 +131,8 @@ public Task ShouldUseDarkColorsAsync() { var taskCompletionSource = new TaskCompletionSource(); - BridgeConnector.Socket.On("nativeTheme-shouldUseDarkColors-completed", (shouldUseDarkColors) => { + BridgeConnector.Socket.On("nativeTheme-shouldUseDarkColors-completed", (shouldUseDarkColors) => + { BridgeConnector.Socket.Off("nativeTheme-shouldUseDarkColors-completed"); taskCompletionSource.SetResult((bool)shouldUseDarkColors); @@ -148,7 +151,8 @@ public Task ShouldUseHighContrastColorsAsync() { var taskCompletionSource = new TaskCompletionSource(); - BridgeConnector.Socket.On("nativeTheme-shouldUseHighContrastColors-completed", (shouldUseHighContrastColors) => { + BridgeConnector.Socket.On("nativeTheme-shouldUseHighContrastColors-completed", (shouldUseHighContrastColors) => + { BridgeConnector.Socket.Off("nativeTheme-shouldUseHighContrastColors-completed"); taskCompletionSource.SetResult((bool)shouldUseHighContrastColors); @@ -167,7 +171,8 @@ public Task ShouldUseInvertedColorSchemeAsync() { var taskCompletionSource = new TaskCompletionSource(); - BridgeConnector.Socket.On("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) => { + BridgeConnector.Socket.On("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) => + { BridgeConnector.Socket.Off("nativeTheme-shouldUseInvertedColorScheme-completed"); taskCompletionSource.SetResult((bool)shouldUseInvertedColorScheme); diff --git a/src/ElectronNET.API/API/Notification.cs b/src/ElectronNET.API/API/Notification.cs index 68ac4e14..1913ee29 100644 --- a/src/ElectronNET.API/API/Notification.cs +++ b/src/ElectronNET.API/API/Notification.cs @@ -17,7 +17,9 @@ public sealed class Notification private static Notification _notification; private static object _syncRoot = new object(); - internal Notification() { } + internal Notification() + { + } internal static Notification Instance { @@ -61,9 +63,7 @@ private static void GenerateIDsForDefinedActions(NotificationOptions notificatio isActionDefined = true; BridgeConnector.Socket.Off("NotificationEventShow"); - BridgeConnector.Socket.On("NotificationEventShow", (id) => { - _notificationOptions.Single(x => x.ShowID == id.ToString()).OnShow(); - }); + BridgeConnector.Socket.On("NotificationEventShow", (id) => { _notificationOptions.Single(x => x.ShowID == id.ToString()).OnShow(); }); } if (notificationOptions.OnClick != null) @@ -72,9 +72,7 @@ private static void GenerateIDsForDefinedActions(NotificationOptions notificatio isActionDefined = true; BridgeConnector.Socket.Off("NotificationEventClick"); - BridgeConnector.Socket.On("NotificationEventClick", (id) => { - _notificationOptions.Single(x => x.ClickID == id.ToString()).OnClick(); - }); + BridgeConnector.Socket.On("NotificationEventClick", (id) => { _notificationOptions.Single(x => x.ClickID == id.ToString()).OnClick(); }); } if (notificationOptions.OnClose != null) @@ -83,9 +81,7 @@ private static void GenerateIDsForDefinedActions(NotificationOptions notificatio isActionDefined = true; BridgeConnector.Socket.Off("NotificationEventClose"); - BridgeConnector.Socket.On("NotificationEventClose", (id) => { - _notificationOptions.Single(x => x.CloseID == id.ToString()).OnClose(); - }); + BridgeConnector.Socket.On("NotificationEventClose", (id) => { _notificationOptions.Single(x => x.CloseID == id.ToString()).OnClose(); }); } if (notificationOptions.OnReply != null) @@ -94,7 +90,8 @@ private static void GenerateIDsForDefinedActions(NotificationOptions notificatio isActionDefined = true; BridgeConnector.Socket.Off("NotificationEventReply"); - BridgeConnector.Socket.On("NotificationEventReply", (args) => { + BridgeConnector.Socket.On("NotificationEventReply", (args) => + { var arguments = ((JArray)args).ToObject(); _notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnReply(arguments[1].ToString()); }); @@ -106,7 +103,8 @@ private static void GenerateIDsForDefinedActions(NotificationOptions notificatio isActionDefined = true; BridgeConnector.Socket.Off("NotificationEventAction"); - BridgeConnector.Socket.On("NotificationEventAction", (args) => { + BridgeConnector.Socket.On("NotificationEventAction", (args) => + { var arguments = ((JArray)args).ToObject(); _notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnAction(arguments[1].ToString()); }); @@ -144,4 +142,4 @@ public Task IsSupportedAsync() DefaultValueHandling = DefaultValueHandling.Ignore }; } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/PowerMonitor.cs b/src/ElectronNET.API/API/PowerMonitor.cs index a42e5acd..36556c58 100644 --- a/src/ElectronNET.API/API/PowerMonitor.cs +++ b/src/ElectronNET.API/API/PowerMonitor.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using ElectronNET.Common; + // ReSharper disable InconsistentNaming namespace ElectronNET.API @@ -75,7 +76,7 @@ public event Action OnBattery } private event Action _onBattery; - + /// /// Emitted when the system is about to reboot or shut down. If the event handler /// invokes `e.preventDefault()`, Electron will attempt to delay system shutdown in @@ -93,7 +94,9 @@ public event Action OnShutdown private static PowerMonitor _powerMonitor; private static object _syncRoot = new object(); - internal PowerMonitor() { } + internal PowerMonitor() + { + } internal static PowerMonitor Instance { @@ -114,4 +117,4 @@ internal static PowerMonitor Instance } } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Process.cs b/src/ElectronNET.API/API/Process.cs index 26c0f2f2..0be0181d 100644 --- a/src/ElectronNET.API/API/Process.cs +++ b/src/ElectronNET.API/API/Process.cs @@ -12,7 +12,9 @@ namespace ElectronNET.API /// public sealed class Process { - internal Process() { } + internal Process() + { + } internal static Process Instance { @@ -102,13 +104,13 @@ public Task TypeAsync return taskCompletionSource.Task; } } - - + + /// /// The process.versions property returns an object listing the version strings of /// chrome and electron. /// - public Task VersionsAsync + public Task VersionsAsync { get { @@ -124,8 +126,8 @@ public Task VersionsAsync return taskCompletionSource.Task; } } - - + + /// /// A Boolean. When app is started by being passed as parameter to the default app, this /// property is true in the main process, otherwise it is false. @@ -269,6 +271,5 @@ public Task PlatformAsync return taskCompletionSource.Task; } } - } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Screen.cs b/src/ElectronNET.API/API/Screen.cs index 8f4ee0c1..fd94372b 100644 --- a/src/ElectronNET.API/API/Screen.cs +++ b/src/ElectronNET.API/API/Screen.cs @@ -51,7 +51,9 @@ public event Action OnDisplayMetricsChanged private static Screen _screen; private static object _syncRoot = new object(); - internal Screen() { } + internal Screen() + { + } internal static Screen Instance { @@ -76,7 +78,7 @@ internal static Screen Instance /// The current absolute position of the mouse pointer. /// /// - public Task GetCursorScreenPointAsync() + public Task GetCursorScreenPointAsync() { var taskCompletionSource = new TaskCompletionSource(); diff --git a/src/ElectronNET.API/API/Session.cs b/src/ElectronNET.API/API/Session.cs index a6acbc90..d5a18675 100644 --- a/src/ElectronNET.API/API/Session.cs +++ b/src/ElectronNET.API/API/Session.cs @@ -460,4 +460,4 @@ public Task LoadExtensionAsync(string path, bool allowFileAccess = fa DefaultValueHandling = DefaultValueHandling.Ignore }; } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Shell.cs b/src/ElectronNET.API/API/Shell.cs index 71f458e4..27d75ce7 100644 --- a/src/ElectronNET.API/API/Shell.cs +++ b/src/ElectronNET.API/API/Shell.cs @@ -15,7 +15,9 @@ public sealed class Shell private static Shell _shell; private static object _syncRoot = new object(); - internal Shell() { } + internal Shell() + { + } internal static Shell Instance { @@ -44,10 +46,7 @@ public Task ShowItemInFolderAsync(string fullPath) { var taskCompletionSource = new TaskCompletionSource(); - BridgeConnector.Socket.On("shell-showItemInFolderCompleted", () => - { - BridgeConnector.Socket.Off("shell-showItemInFolderCompleted"); - }); + BridgeConnector.Socket.On("shell-showItemInFolderCompleted", () => { BridgeConnector.Socket.Off("shell-showItemInFolderCompleted"); }); BridgeConnector.Socket.Emit("shell-showItemInFolder", fullPath); @@ -67,7 +66,7 @@ public Task OpenPathAsync(string path) { BridgeConnector.Socket.Off("shell-openPathCompleted"); - taskCompletionSource.SetResult((string) errorMessage); + taskCompletionSource.SetResult((string)errorMessage); }); BridgeConnector.Socket.Emit("shell-openPath", path); @@ -101,7 +100,7 @@ public Task OpenExternalAsync(string url, OpenExternalOptions options) { BridgeConnector.Socket.Off("shell-openExternalCompleted"); - taskCompletionSource.SetResult((string) error); + taskCompletionSource.SetResult((string)error); }); if (options == null) @@ -129,7 +128,7 @@ public Task TrashItemAsync(string fullPath) { BridgeConnector.Socket.Off("shell-trashItem-completed"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult((bool)success); }); BridgeConnector.Socket.Emit("shell-trashItem", fullPath); @@ -160,7 +159,7 @@ public Task WriteShortcutLinkAsync(string shortcutPath, ShortcutLinkOperat { BridgeConnector.Socket.Off("shell-writeShortcutLinkCompleted"); - taskCompletionSource.SetResult((bool) success); + taskCompletionSource.SetResult((bool)success); }); BridgeConnector.Socket.Emit("shell-writeShortcutLink", shortcutPath, operation.GetDescription(), JObject.FromObject(options, _jsonSerializer)); @@ -200,4 +199,4 @@ public Task ReadShortcutLinkAsync(string shortcutPath) DefaultValueHandling = DefaultValueHandling.Ignore }; } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/Tray.cs b/src/ElectronNET.API/API/Tray.cs index f4d353d1..7e559755 100644 --- a/src/ElectronNET.API/API/Tray.cs +++ b/src/ElectronNET.API/API/Tray.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using ElectronNET.Common; + // ReSharper disable InconsistentNaming namespace ElectronNET.API @@ -88,7 +89,9 @@ public event Action OnBalloonClosed private static Tray _tray; private static readonly object _syncRoot = new(); - internal Tray() { } + internal Tray() + { + } internal static Tray Instance { @@ -239,6 +242,7 @@ public async Task IsDestroyedAsync() }; private const string ModuleName = "tray"; + /// /// Subscribe to an unmapped event on the module. /// @@ -246,6 +250,7 @@ public async Task IsDestroyedAsync() /// The handler public void On(string eventName, Action action) => Events.Instance.On(ModuleName, eventName, action); + /// /// Subscribe to an unmapped event on the module. /// @@ -253,6 +258,7 @@ public void On(string eventName, Action action) /// The handler public async Task On(string eventName, Action action) => await Events.Instance.On(ModuleName, eventName, action).ConfigureAwait(false); + /// /// Subscribe to an unmapped event on the module once. /// @@ -260,6 +266,7 @@ public async Task On(string eventName, Action action) /// The handler public void Once(string eventName, Action action) => Events.Instance.Once(ModuleName, eventName, action); + /// /// Subscribe to an unmapped event on the module once. /// @@ -268,4 +275,4 @@ public void Once(string eventName, Action action) public async Task Once(string eventName, Action action) => await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false); } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/API/WebContents.cs b/src/ElectronNET.API/API/WebContents.cs index deaef8c4..94cee556 100644 --- a/src/ElectronNET.API/API/WebContents.cs +++ b/src/ElectronNET.API/API/WebContents.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using ElectronNET.Common; + // ReSharper disable InconsistentNaming namespace ElectronNET.API; @@ -187,7 +188,7 @@ public Task PrintAsync(PrintOptions options = null) taskCompletionSource.SetResult((bool)success); }); - if(options == null) + if (options == null) { BridgeConnector.Socket.Emit("webContents-print", Id, ""); } @@ -218,7 +219,7 @@ public Task PrintToPDFAsync(string path, PrintToPDFOptions options = null) taskCompletionSource.SetResult((bool)success); }); - if(options == null) + if (options == null) { BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path); } diff --git a/src/ElectronNET.API/API/WebRequest.cs b/src/ElectronNET.API/API/WebRequest.cs index 3b551060..2aa448ad 100644 --- a/src/ElectronNET.API/API/WebRequest.cs +++ b/src/ElectronNET.API/API/WebRequest.cs @@ -8,6 +8,7 @@ public class OnBeforeRequestDetails public int Id { get; set; } public string Url { get; set; } public string Method { get; set; } + public int? WebContentsId { get; set; } // Ensure all necessary properties are included as per Electron documentation } @@ -34,14 +35,14 @@ public void OnBeforeRequest(WebRequestFilter filter, Action - { - ////var details = ((JObject)args[0]).ToObject(); - ////var callback = args.Length > 1 ? (Action)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); }) : null; - var details = ((JObject)args).ToObject(); - var callback = (Action)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); }); - - _onBeforeRequest?.Invoke(details, callback); - }); + { + ////var details = ((JObject)args[0]).ToObject(); + ////var callback = args.Length > 1 ? (Action)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); }) : null; + var details = ((JObject)args).ToObject(); + var callback = (Action)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); }); + + _onBeforeRequest?.Invoke(details, callback); + }); BridgeConnector.Socket.Emit("register-webContents-session-webRequest-onBeforeRequest", Id, JObject.FromObject(filter)); } diff --git a/src/ElectronNET.API/API/WindowManager.cs b/src/ElectronNET.API/API/WindowManager.cs index 6ce36d5c..9ec0369f 100644 --- a/src/ElectronNET.API/API/WindowManager.cs +++ b/src/ElectronNET.API/API/WindowManager.cs @@ -19,7 +19,9 @@ public sealed class WindowManager private static WindowManager _windowManager; private static readonly object SyncRoot = new(); - internal WindowManager() { } + internal WindowManager() + { + } internal static WindowManager Instance { @@ -55,6 +57,7 @@ public bool IsQuitOnWindowAllClosed _isQuitOnWindowAllClosed = value; } } + private bool _isQuitOnWindowAllClosed = true; /// @@ -214,4 +217,4 @@ public async Task CreateBrowserViewAsync(BrowserViewConstructorOpti NullValueHandling = NullValueHandling.Ignore }; } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/Bridge/Events.cs b/src/ElectronNET.API/Bridge/Events.cs index 8bcff02f..f2dca2c1 100644 --- a/src/ElectronNET.API/Bridge/Events.cs +++ b/src/ElectronNET.API/Bridge/Events.cs @@ -16,7 +16,8 @@ internal class Events private readonly TextInfo _textInfo = new CultureInfo("en-US", false).TextInfo; private Events() - { } + { + } public static Events Instance { @@ -94,6 +95,5 @@ public async Task Once(string moduleName, string eventName, Action action) BridgeConnector.Socket.Once(listener, action); await BridgeConnector.Socket.Emit(subscriber, eventName, listener).ConfigureAwait(false); } - } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/Bridge/SocketIOFacade.cs b/src/ElectronNET.API/Bridge/SocketIOFacade.cs index 64324179..21c03ae2 100644 --- a/src/ElectronNET.API/Bridge/SocketIOFacade.cs +++ b/src/ElectronNET.API/Bridge/SocketIOFacade.cs @@ -33,10 +33,7 @@ public SocketIoFacade(string uri) public void Connect() { - _socket.OnError += (sender, e) => - { - Console.WriteLine($"BridgeConnector Error: {sender} {e}"); - }; + _socket.OnError += (sender, e) => { Console.WriteLine($"BridgeConnector Error: {sender} {e}"); }; _socket.OnConnected += (_, _) => { @@ -57,10 +54,7 @@ public void On(string eventName, Action action) { lock (_lockObj) { - _socket.On(eventName, _ => - { - Task.Run(action); - }); + _socket.On(eventName, _ => { Task.Run(action); }); } } @@ -107,10 +101,10 @@ public void Once(string eventName, Action action) lock (_lockObj) { _socket.On(eventName, (socketIoResponse) => - { - _socket.Off(eventName); - Task.Run(() => action(socketIoResponse.GetValue())); - }); + { + _socket.Off(eventName); + Task.Run(() => action(socketIoResponse.GetValue())); + }); } } diff --git a/src/ElectronNET.API/Common/ApiEventManager.cs b/src/ElectronNET.API/Common/ApiEventManager.cs index 4aed5c1e..61ef2c7d 100644 --- a/src/ElectronNET.API/Common/ApiEventManager.cs +++ b/src/ElectronNET.API/Common/ApiEventManager.cs @@ -14,15 +14,16 @@ internal static void AddEvent(string eventName, object id, Action callback, Acti BridgeConnector.Socket.On(eventName + id, () => { callback(); }); BridgeConnector.Socket.Emit($"register-{eventName}{suffix}", id); } + callback += value; } - + internal static void RemoveEvent(string eventName, object id, Action callback, Action value) { callback -= value; if (callback == null) BridgeConnector.Socket.Off(eventName + id); } - + internal static void AddEvent(string eventName, object id, Action callback, Action value, Func converter, string suffix = "") { if (callback == null) @@ -34,9 +35,10 @@ internal static void AddEvent(string eventName, object id, Action callback }); BridgeConnector.Socket.Emit($"register-{eventName}{suffix}", id); } + callback += value; } - + internal static void AddEvent(string eventName, object id, Action callback, Action value) { if (callback == null) @@ -44,15 +46,16 @@ internal static void AddEvent(string eventName, object id, Action callback BridgeConnector.Socket.On(eventName + id, (args) => callback(args)); BridgeConnector.Socket.Emit($"register-{eventName}", id); } + callback += value; } - + internal static void RemoveEvent(string eventName, object id, Action callback, Action value) { callback -= value; if (callback == null) BridgeConnector.Socket.Off(eventName + id); } - + internal static void AddTrayEvent(string eventName, object id, Action callback, Action value) { if (callback == null) @@ -74,7 +77,7 @@ internal static void RemoveTrayEvent(string eventName, object id, Action callback, Action value) { if (callback == null) @@ -89,11 +92,10 @@ internal static void AddScreenEvent(string eventName, object id, Action callback, Action value) { callback -= value; if (callback == null) BridgeConnector.Socket.Off(eventName + id); } - } \ No newline at end of file diff --git a/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerBase.cs b/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerBase.cs index c80c0d6a..65c911ad 100644 --- a/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerBase.cs +++ b/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerBase.cs @@ -20,7 +20,6 @@ protected RuntimeControllerBase() protected override Task StartCore() { - return Task.CompletedTask; } @@ -28,6 +27,5 @@ protected override Task StopCore() { return Task.CompletedTask; } - } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerDotNetFirst.cs b/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerDotNetFirst.cs index 7b8e888d..af615cfb 100644 --- a/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerDotNetFirst.cs +++ b/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerDotNetFirst.cs @@ -68,7 +68,6 @@ private void ElectronProcess_Ready(object sender, EventArgs e) private void SocketBridge_Ready(object sender, EventArgs e) { this.TransitionState(LifetimeState.Ready); - } private void SocketBridge_Stopped(object sender, EventArgs e) @@ -102,6 +101,5 @@ protected override Task StopCore() this.electronProcess.Stop(); return Task.CompletedTask; } - } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerElectronFirst.cs b/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerElectronFirst.cs index c8b9031c..cc97cd01 100644 --- a/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerElectronFirst.cs +++ b/src/ElectronNET.API/Runtime/Controllers/RuntimeControllerElectronFirst.cs @@ -103,6 +103,5 @@ protected override Task StopCore() this.socketBridge.Stop(); return Task.CompletedTask; } - } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/Runtime/Services/LifetimeServiceBase.cs b/src/ElectronNET.API/Runtime/Services/LifetimeServiceBase.cs index 15c5823f..90a14108 100644 --- a/src/ElectronNET.API/Runtime/Services/LifetimeServiceBase.cs +++ b/src/ElectronNET.API/Runtime/Services/LifetimeServiceBase.cs @@ -14,7 +14,9 @@ public abstract class LifetimeServiceBase private LifetimeState state = LifetimeState.Uninitialized; - protected LifetimeServiceBase() { } + protected LifetimeServiceBase() + { + } public event EventHandler Starting; @@ -132,4 +134,4 @@ protected void TransitionState(LifetimeState newState) } } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs b/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs index 12530518..fea9d0a4 100644 --- a/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs +++ b/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs @@ -5,7 +5,7 @@ using ElectronNET.API; using ElectronNET.Runtime.Data; - internal class SocketBridgeService : LifetimeServiceBase + internal class SocketBridgeService : LifetimeServiceBase { private readonly int socketPort; private readonly string socketUrl; @@ -53,4 +53,4 @@ private void Socket_BridgeConnected(object sender, EventArgs e) this.TransitionState(LifetimeState.Ready); } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.API/Runtime/StartupManager.cs b/src/ElectronNET.API/Runtime/StartupManager.cs index 74077147..a405a6e5 100644 --- a/src/ElectronNET.API/Runtime/StartupManager.cs +++ b/src/ElectronNET.API/Runtime/StartupManager.cs @@ -103,7 +103,7 @@ private void CollectProcessData() { ElectronNetRuntime.ElectronProcessId = result; - Console.WriteLine("Electron Process ID: " + result); + Console.WriteLine("Electron Process ID: " + result); } } } @@ -122,7 +122,6 @@ private void SetElectronExecutable() } ElectronNetRuntime.ElectronExecutable = executable; - } private BuildInfo GatherBuildInfo() @@ -166,4 +165,4 @@ private BuildInfo GatherBuildInfo() return buildInfo; } } -} +} \ No newline at end of file diff --git a/src/ElectronNET.AspNet/Runtime/Services/AspNetLifetimeAdapter.cs b/src/ElectronNET.AspNet/Runtime/Services/AspNetLifetimeAdapter.cs index 9971ed56..6922df4e 100644 --- a/src/ElectronNET.AspNet/Runtime/Services/AspNetLifetimeAdapter.cs +++ b/src/ElectronNET.AspNet/Runtime/Services/AspNetLifetimeAdapter.cs @@ -5,7 +5,7 @@ using ElectronNET.Runtime.Services; using Microsoft.Extensions.Hosting; - internal class AspNetLifetimeAdapter : LifetimeServiceBase + internal class AspNetLifetimeAdapter : LifetimeServiceBase { private readonly IHostApplicationLifetime lifetimeService; @@ -24,4 +24,4 @@ protected override Task StopCore() return Task.CompletedTask; } } -} +} \ No newline at end of file