diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index 5376045..cf23444 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -603,7 +603,7 @@ namespace ElectronNET.API } private static App _app; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); /// /// Try to close all windows. The event will be emitted first. If all windows are successfully @@ -1376,7 +1376,7 @@ namespace ElectronNET.API /// public void DestroySplashScreen() => BridgeConnector.Emit("splashscreen-destroy"); - private readonly JsonSerializer _jsonSerializer = new JsonSerializer() + private readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver() }; diff --git a/ElectronNET.API/AutoUpdater.cs b/ElectronNET.API/AutoUpdater.cs index d21ed04..038981c 100644 --- a/ElectronNET.API/AutoUpdater.cs +++ b/ElectronNET.API/AutoUpdater.cs @@ -313,7 +313,7 @@ namespace ElectronNET.API private event Action _updateDownloaded; private static AutoUpdater _autoUpdater; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal AutoUpdater() { } diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index b71708a..b0ad6e0 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -86,12 +86,12 @@ namespace ElectronNET.API private static SocketIO _socket; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); - private static SemaphoreSlim _socketSemaphoreEmit = new SemaphoreSlim(1, 1); - private static SemaphoreSlim _socketSemaphoreHandlers = new SemaphoreSlim(1, 1); + private static readonly SemaphoreSlim _socketSemaphoreEmit = new(1, 1); + private static readonly SemaphoreSlim _socketSemaphoreHandlers = new(1, 1); - private static TaskCompletionSource _connectedSocketTask = new TaskCompletionSource(); + private static TaskCompletionSource _connectedSocketTask = new(); private static Task _waitForConnection { diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs index fb5c1e4..986b10e 100644 --- a/ElectronNET.API/BrowserWindow.cs +++ b/ElectronNET.API/BrowserWindow.cs @@ -1106,7 +1106,6 @@ namespace ElectronNET.API /// sum any extra width and height areas you have within the overall content view. /// /// The aspect ratio to maintain for some portion of the content view. - /// The extra size not to be included while maintaining the aspect ratio. public void SetAspectRatio(int aspectRatio) { BridgeConnector.Emit("browserWindowSetAspectRatio", Id, aspectRatio, new Size() { Height = 0, Width = 0 }); @@ -1524,7 +1523,7 @@ namespace ElectronNET.API // https://github.com/electron/electron/issues/4045 if (isWindows10()) { - x = x - 7; + x -= 7; } BridgeConnector.Emit("browserWindowSetPosition", Id, x, y); @@ -1543,7 +1542,7 @@ namespace ElectronNET.API // https://github.com/electron/electron/issues/4045 if (isWindows10()) { - x = x - 7; + x -= 7; } BridgeConnector.Emit("browserWindowSetPosition", Id, x, y, animate); @@ -1747,7 +1746,7 @@ namespace ElectronNET.API /// The menu items. /// public IReadOnlyCollection MenuItems { get { return _items.AsReadOnly(); } } - private List _items = new List(); + private readonly List _items = new(); /// /// Sets the menu as the window’s menu bar, @@ -1844,7 +1843,7 @@ namespace ElectronNET.API /// public IReadOnlyCollection ThumbarButtons { get { return _thumbarButtons.AsReadOnly(); } } - private List _thumbarButtons = new List(); + private readonly List _thumbarButtons = new(); /// /// Add a thumbnail toolbar with a specified set of buttons to the thumbnail @@ -2114,7 +2113,7 @@ namespace ElectronNET.API BridgeConnector.Emit("browserWindow-setBrowserView", Id, browserView.Id); } - private static readonly JsonSerializer _jsonSerializer = new JsonSerializer() + private static readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore diff --git a/ElectronNET.API/Clipboard.cs b/ElectronNET.API/Clipboard.cs index 3e8e87a..3583c33 100644 --- a/ElectronNET.API/Clipboard.cs +++ b/ElectronNET.API/Clipboard.cs @@ -13,7 +13,7 @@ namespace ElectronNET.API public sealed class Clipboard { private static Clipboard _clipboard; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Clipboard() { } @@ -178,7 +178,7 @@ namespace ElectronNET.API BridgeConnector.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type); } - private static JsonSerializer _jsonSerializer = new JsonSerializer() + private static readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, diff --git a/ElectronNET.API/CommandLine.cs b/ElectronNET.API/CommandLine.cs index 40c48e4..6aa1e50 100644 --- a/ElectronNET.API/CommandLine.cs +++ b/ElectronNET.API/CommandLine.cs @@ -31,7 +31,7 @@ namespace ElectronNET.API private static CommandLine _commandLine; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); /// /// Append a switch (with optional value) to Chromium's command line. diff --git a/ElectronNET.API/Cookies.cs b/ElectronNET.API/Cookies.cs index dce7de0..f5de870 100644 --- a/ElectronNET.API/Cookies.cs +++ b/ElectronNET.API/Cookies.cs @@ -139,7 +139,7 @@ namespace ElectronNET.API return taskCompletionSource.Task; } - private static JsonSerializer _jsonSerializer = new JsonSerializer() + private static readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, diff --git a/ElectronNET.API/Dialog.cs b/ElectronNET.API/Dialog.cs index af81e28..02d22aa 100644 --- a/ElectronNET.API/Dialog.cs +++ b/ElectronNET.API/Dialog.cs @@ -16,7 +16,7 @@ namespace ElectronNET.API public sealed class Dialog { private static Dialog _dialog; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Dialog() { } @@ -225,7 +225,7 @@ namespace ElectronNET.API return taskCompletionSource.Task; } - private static JsonSerializer _jsonSerializer = new JsonSerializer() + private static readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, diff --git a/ElectronNET.API/Dock.cs b/ElectronNET.API/Dock.cs index 791cb3f..b5ea5d4 100644 --- a/ElectronNET.API/Dock.cs +++ b/ElectronNET.API/Dock.cs @@ -17,7 +17,7 @@ namespace ElectronNET.API public sealed class Dock { private static Dock _dock; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Dock() { @@ -132,7 +132,7 @@ namespace ElectronNET.API /// The menu items. /// public IReadOnlyCollection MenuItems { get { return _items.AsReadOnly(); } } - private List _items = new List(); + private readonly List _items = new(); /// /// Sets the application's dock menu. @@ -165,7 +165,7 @@ namespace ElectronNET.API BridgeConnector.Emit("dock-setIcon", image); } - private static readonly JsonSerializer _jsonSerializer = new JsonSerializer() + private static readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore diff --git a/ElectronNET.API/Entities/BrowserWindowOptions.cs b/ElectronNET.API/Entities/BrowserWindowOptions.cs index c7263ae..0042772 100644 --- a/ElectronNET.API/Entities/BrowserWindowOptions.cs +++ b/ElectronNET.API/Entities/BrowserWindowOptions.cs @@ -223,7 +223,7 @@ namespace ElectronNET.API.Entities public bool? FullscreenWindowTitle { get; set; } /// - /// Activate the Window Controls Overlay on Windows, when combined with = + /// Activate the Window Controls Overlay on Windows, when combined with = /// [SupportedOSPlatform("win")] [DefaultValue(null)] diff --git a/ElectronNET.API/Entities/NativeImage.cs b/ElectronNET.API/Entities/NativeImage.cs index 5b1724c..8ba6663 100644 --- a/ElectronNET.API/Entities/NativeImage.cs +++ b/ElectronNET.API/Entities/NativeImage.cs @@ -16,10 +16,10 @@ namespace ElectronNET.API.Entities [JsonConverter(typeof(NativeImageJsonConverter))] public class NativeImage { - private readonly Dictionary _images = new Dictionary(); + private readonly Dictionary _images = new(); private bool _isTemplateImage; - private static readonly Dictionary ScaleFactorPairs = new Dictionary + private static readonly Dictionary ScaleFactorPairs = new() { {"@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}, diff --git a/ElectronNET.API/Events.cs b/ElectronNET.API/Events.cs index 6c01cdc..2eb65d8 100644 --- a/ElectronNET.API/Events.cs +++ b/ElectronNET.API/Events.cs @@ -9,8 +9,8 @@ namespace ElectronNET.API internal class Events { private static Events _events; - private static object _syncRoot = new object(); - private TextInfo _ti = new CultureInfo("en-US", false).TextInfo; + private static readonly object _syncRoot = new(); + private readonly TextInfo _ti = new CultureInfo("en-US", false).TextInfo; private Events() { diff --git a/ElectronNET.API/Extensions/EnumExtensions.cs b/ElectronNET.API/Extensions/EnumExtensions.cs index 4424310..949c1fc 100644 --- a/ElectronNET.API/Extensions/EnumExtensions.cs +++ b/ElectronNET.API/Extensions/EnumExtensions.cs @@ -11,7 +11,7 @@ namespace ElectronNET.API.Extensions Type type = enumerationValue.GetType(); if (!type.IsEnum) { - throw new ArgumentException("EnumerationValue must be of Enum type", "enumerationValue"); + throw new ArgumentException("EnumerationValue must be of Enum type", nameof(enumerationValue)); } //Tries to find a DescriptionAttribute for a potential friendly name diff --git a/ElectronNET.API/Extensions/MenuItemExtensions.cs b/ElectronNET.API/Extensions/MenuItemExtensions.cs index 37a5b9c..44678a2 100644 --- a/ElectronNET.API/Extensions/MenuItemExtensions.cs +++ b/ElectronNET.API/Extensions/MenuItemExtensions.cs @@ -28,7 +28,7 @@ namespace ElectronNET.API.Extensions public static MenuItem GetMenuItem(this List menuItems, string id) { - MenuItem result = new MenuItem(); + MenuItem result = new(); foreach (var item in menuItems) { diff --git a/ElectronNET.API/Extensions/ThumbarButtonExtensions.cs b/ElectronNET.API/Extensions/ThumbarButtonExtensions.cs index 3b15554..4d51005 100644 --- a/ElectronNET.API/Extensions/ThumbarButtonExtensions.cs +++ b/ElectronNET.API/Extensions/ThumbarButtonExtensions.cs @@ -23,7 +23,7 @@ namespace ElectronNET.API.Extensions public static ThumbarButton GetThumbarButton(this List thumbarButtons, string id) { - ThumbarButton result = new ThumbarButton(""); + ThumbarButton result = new(""); foreach (var item in thumbarButtons) { diff --git a/ElectronNET.API/GlobalShortcut.cs b/ElectronNET.API/GlobalShortcut.cs index 9efbdf2..9d356b2 100644 --- a/ElectronNET.API/GlobalShortcut.cs +++ b/ElectronNET.API/GlobalShortcut.cs @@ -10,7 +10,7 @@ namespace ElectronNET.API public sealed class GlobalShortcut { private static GlobalShortcut _globalShortcut; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal GlobalShortcut() { } @@ -33,7 +33,7 @@ namespace ElectronNET.API } } - private Dictionary _shortcuts = new Dictionary(); + private readonly Dictionary _shortcuts = new(); /// /// Registers a global shortcut of accelerator. diff --git a/ElectronNET.API/HostHook.cs b/ElectronNET.API/HostHook.cs index a5c4e9a..3fcd791 100644 --- a/ElectronNET.API/HostHook.cs +++ b/ElectronNET.API/HostHook.cs @@ -16,8 +16,8 @@ namespace ElectronNET.API public sealed class HostHook { private static HostHook _electronHostHook; - private static object _syncRoot = new object(); - string oneCallguid = Guid.NewGuid().ToString(); + private static readonly object _syncRoot = new(); + readonly string oneCallguid = Guid.NewGuid().ToString(); internal HostHook() { } diff --git a/ElectronNET.API/IpcMain.cs b/ElectronNET.API/IpcMain.cs index d6e1eee..6efb051 100644 --- a/ElectronNET.API/IpcMain.cs +++ b/ElectronNET.API/IpcMain.cs @@ -14,7 +14,7 @@ namespace ElectronNET.API public sealed class IpcMain { private static IpcMain _ipcMain; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal IpcMain() { } @@ -174,10 +174,11 @@ namespace ElectronNET.API /// Arguments data. public void Send(BrowserWindow browserWindow, string channel, params object[] data) { - var objectsWithCorrectSerialization = new List(); - - objectsWithCorrectSerialization.Add(browserWindow.Id); - objectsWithCorrectSerialization.Add(channel); + var objectsWithCorrectSerialization = new List + { + browserWindow.Id, + channel + }; foreach (var parameterObject in data) { @@ -209,9 +210,9 @@ namespace ElectronNET.API /// Arguments data. public void Send(BrowserView browserView, string channel, params object[] data) { - List jobjects = new List(); - List jarrays = new List(); - List objects = new List(); + List jobjects = new(); + List jarrays = new(); + List objects = new(); foreach (var parameterObject in data) { @@ -258,7 +259,7 @@ namespace ElectronNET.API BridgeConnector.Emit("console-stderr", text); } - private JsonSerializer _jsonSerializer = new JsonSerializer() + private readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, diff --git a/ElectronNET.API/Menu.cs b/ElectronNET.API/Menu.cs index aa98613..b5b68d2 100644 --- a/ElectronNET.API/Menu.cs +++ b/ElectronNET.API/Menu.cs @@ -15,7 +15,7 @@ namespace ElectronNET.API public sealed class Menu { private static Menu _menu; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Menu() { } @@ -45,7 +45,7 @@ namespace ElectronNET.API /// The menu items. /// public IReadOnlyCollection MenuItems { get { return _menuItems.AsReadOnly(); } } - private List _menuItems = new List(); + private readonly List _menuItems = new(); /// /// Sets the application menu. @@ -75,7 +75,7 @@ namespace ElectronNET.API /// The context menu items. /// public IReadOnlyDictionary> ContextMenuItems { get; internal set; } - private Dictionary> _contextMenuItems = new Dictionary>(); + private readonly Dictionary> _contextMenuItems = new(); /// /// Sets the context menu. @@ -113,7 +113,7 @@ namespace ElectronNET.API BridgeConnector.Emit("menu-contextMenuPopup", browserWindow.Id); } - private JsonSerializer _jsonSerializer = new JsonSerializer() + private readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore diff --git a/ElectronNET.API/NativeTheme.cs b/ElectronNET.API/NativeTheme.cs index 235d349..421db08 100644 --- a/ElectronNET.API/NativeTheme.cs +++ b/ElectronNET.API/NativeTheme.cs @@ -12,7 +12,7 @@ namespace ElectronNET.API public sealed class NativeTheme { private static NativeTheme _nativeTheme; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal NativeTheme() { } diff --git a/ElectronNET.API/Notification.cs b/ElectronNET.API/Notification.cs index 86d9ac3..54172ca 100644 --- a/ElectronNET.API/Notification.cs +++ b/ElectronNET.API/Notification.cs @@ -15,7 +15,7 @@ namespace ElectronNET.API public sealed class Notification { private static Notification _notification; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Notification() { } @@ -38,7 +38,7 @@ namespace ElectronNET.API } } - private static List _notificationOptions = new List(); + private static readonly List _notificationOptions = new(); /// /// Create OS desktop notifications @@ -135,7 +135,7 @@ namespace ElectronNET.API return taskCompletionSource.Task; } - private static JsonSerializer _jsonSerializer = new JsonSerializer() + private static readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, diff --git a/ElectronNET.API/PowerMonitor.cs b/ElectronNET.API/PowerMonitor.cs index c92bff9..8ddde89 100644 --- a/ElectronNET.API/PowerMonitor.cs +++ b/ElectronNET.API/PowerMonitor.cs @@ -232,7 +232,7 @@ namespace ElectronNET.API private event Action _shutdown; private static PowerMonitor _powerMonitor; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal PowerMonitor() { } diff --git a/ElectronNET.API/Screen.cs b/ElectronNET.API/Screen.cs index 48bf392..a8e9168 100644 --- a/ElectronNET.API/Screen.cs +++ b/ElectronNET.API/Screen.cs @@ -102,7 +102,7 @@ namespace ElectronNET.API private event Action _onDisplayMetricsChanged; private static Screen _screen; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Screen() { } diff --git a/ElectronNET.API/Shell.cs b/ElectronNET.API/Shell.cs index 929daac..d51c142 100644 --- a/ElectronNET.API/Shell.cs +++ b/ElectronNET.API/Shell.cs @@ -14,7 +14,7 @@ namespace ElectronNET.API public sealed class Shell { private static Shell _shell; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Shell() { } diff --git a/ElectronNET.API/Tray.cs b/ElectronNET.API/Tray.cs index c1b6cbb..50ef49d 100644 --- a/ElectronNET.API/Tray.cs +++ b/ElectronNET.API/Tray.cs @@ -204,7 +204,7 @@ namespace ElectronNET.API // TODO: Implement macOS Events private static Tray _tray; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal Tray() { } @@ -234,7 +234,7 @@ namespace ElectronNET.API /// The menu items. /// public IReadOnlyCollection MenuItems { get { return _items.AsReadOnly(); } } - private List _items = new List(); + private readonly List _items = new(); /// /// Shows the Traybar. @@ -368,7 +368,7 @@ namespace ElectronNET.API /// The handler public void Once(string eventName, Action fn) => Events.Instance.Once(ModuleName, eventName, fn); - private JsonSerializer _jsonSerializer = new JsonSerializer() + private readonly JsonSerializer _jsonSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore diff --git a/ElectronNET.API/WindowManager.cs b/ElectronNET.API/WindowManager.cs index 88d8e6a..ec73cae 100644 --- a/ElectronNET.API/WindowManager.cs +++ b/ElectronNET.API/WindowManager.cs @@ -18,7 +18,7 @@ namespace ElectronNET.API public sealed class WindowManager { private static WindowManager _windowManager; - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new(); internal WindowManager() { } @@ -75,7 +75,7 @@ namespace ElectronNET.API public bool TryGetBrowserWindows(int id, out BrowserWindow window) => _browserWindows.TryGetValue(id, out window); - private ConcurrentDictionary _browserWindows = new (); + private readonly ConcurrentDictionary _browserWindows = new (); /// /// Gets the browser views. @@ -84,7 +84,7 @@ namespace ElectronNET.API /// The browser view. /// public IReadOnlyCollection BrowserViews { get { return _browserViews.Values.ToList().AsReadOnly(); } } - private ConcurrentDictionary _browserViews = new (); + private readonly ConcurrentDictionary _browserViews = new (); /// /// Get a browser view using the ID @@ -248,14 +248,7 @@ namespace ElectronNET.API return destroyed; } - private static JsonSerializer _jsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore - }; - - private static JsonSerializer _keepDefaultValuesSerializer = new JsonSerializer() + private static readonly JsonSerializer _keepDefaultValuesSerializer = new() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore diff --git a/ElectronNET.CLI/Commands/Actions/DirectoryCopy.cs b/ElectronNET.CLI/Commands/Actions/DirectoryCopy.cs index 39ded69..2509f54 100644 --- a/ElectronNET.CLI/Commands/Actions/DirectoryCopy.cs +++ b/ElectronNET.CLI/Commands/Actions/DirectoryCopy.cs @@ -8,16 +8,14 @@ namespace ElectronNET.CLI.Commands.Actions public static void Do(string sourceDirName, string destDirName, bool copySubDirs, List ignoredSubDirs) { // Get the subdirectories for the specified directory. - DirectoryInfo dir = new DirectoryInfo(sourceDirName); + var dir = new DirectoryInfo(sourceDirName); if (!dir.Exists) { - throw new DirectoryNotFoundException( - "Source directory does not exist or could not be found: " - + sourceDirName); + throw new DirectoryNotFoundException($"Source directory does not exist or could not be found: {sourceDirName}"); } - DirectoryInfo[] dirs = dir.GetDirectories(); + var dirs = dir.GetDirectories(); // If the destination directory doesn't exist, create it. if (!Directory.Exists(destDirName)) { @@ -25,13 +23,14 @@ namespace ElectronNET.CLI.Commands.Actions } else { - DirectoryInfo targetDir = new DirectoryInfo(destDirName); + var targetDir = new DirectoryInfo(destDirName); - foreach (FileInfo fileDel in targetDir.EnumerateFiles()) + foreach (var fileDel in targetDir.EnumerateFiles()) { fileDel.Delete(); } - foreach (DirectoryInfo dirDel in targetDir.EnumerateDirectories()) + + foreach (var dirDel in targetDir.EnumerateDirectories()) { dirDel.Delete(true); } @@ -41,8 +40,8 @@ namespace ElectronNET.CLI.Commands.Actions // Get the files in the directory and copy them to the new location. - FileInfo[] files = dir.GetFiles(); - foreach (FileInfo file in files) + var files = dir.GetFiles(); + foreach (var file in files) { string temppath = Path.Combine(destDirName, file.Name); file.CopyTo(temppath, false); @@ -51,7 +50,7 @@ namespace ElectronNET.CLI.Commands.Actions // If copying subdirectories, copy them and their contents to new location. if (copySubDirs) { - foreach (DirectoryInfo subdir in dirs) + foreach (var subdir in dirs) { if (ignoredSubDirs.Contains(subdir.Name)) { diff --git a/ElectronNET.CLI/Commands/AddCommand.cs b/ElectronNET.CLI/Commands/AddCommand.cs index cbfb0dd..9d00240 100644 --- a/ElectronNET.CLI/Commands/AddCommand.cs +++ b/ElectronNET.CLI/Commands/AddCommand.cs @@ -16,14 +16,14 @@ namespace ElectronNET.CLI.Commands public static IList CommandOptions { get; set; } = new List(); - private string[] _args; + private readonly string[] _args; public AddCommand(string[] args) { _args = args; } - private static string ElectronHostHookFolderName = "ElectronHostHook"; + private const string ElectronHostHookFolderName = "ElectronHostHook"; public Task ExecuteAsync() { @@ -124,11 +124,10 @@ namespace ElectronNET.CLI.Commands OmitXmlDeclaration = true, Indent = true }; - using (XmlWriter xw = XmlWriter.Create(stream, xws)) - { - xmlDocument.Save(xw); - } + + using XmlWriter xw = XmlWriter.Create(stream, xws); + xmlDocument.Save(xw); } Console.WriteLine($"Publish setting added in csproj/fsproj!"); diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 080998b..a4a94b7 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -11,19 +11,20 @@ namespace ElectronNET.CLI.Commands { public const string COMMAND_NAME = "build"; public const string COMMAND_DESCRIPTION = "Build your Electron Application."; - public static string COMMAND_ARGUMENTS = "Needed: '/target' with params 'win/osx/linux' to build for a typical app or use 'custom' and specify .NET Core build config & electron build config" + Environment.NewLine + - " for custom target, check .NET Core RID Catalog and Electron build target/" + Environment.NewLine + - " e.g. '/target win' or '/target custom \"win7-x86;win\"'" + Environment.NewLine + - "Optional: '/dotnet-configuration' with the desired .NET Core build config e.g. release or debug. Default = Release" + Environment.NewLine + - "Optional: '/electron-arch' to specify the resulting electron processor architecture (e.g. ia86 for x86 builds). Be aware to use the '/target custom' param as well!" + Environment.NewLine + - "Optional: '/electron-params' specify any other valid parameter, which will be routed to the electron-packager." + Environment.NewLine + - "Optional: '/relative-path' to specify output a subdirectory for output." + Environment.NewLine + - "Optional: '/absolute-path to specify and absolute path for output." + Environment.NewLine + - "Optional: '/package-json' to specify a custom package.json file." + Environment.NewLine + - "Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine + - "Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version'" + Environment.NewLine + - "Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion" + Environment.NewLine + - "Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \""; + public const string COMMAND_ARGUMENTS = +@"Needed: '/target' with params 'win/osx/linux' to build for a typical app or use 'custom' and specify .NET Core build config & electron build config +for custom target, check .NET Core RID Catalog and Electron build target/ +e.g. '/target win' or '/target custom ""win7-x86;win""' +Optional: '/dotnet-configuration' with the desired .NET Core build config e.g. release or debug. Default = Release +Optional: '/electron-arch' to specify the resulting electron processor architecture (e.g. ia86 for x86 builds). Be aware to use the '/target custom' param as well! +Optional: '/electron-params' specify any other valid parameter, which will be routed to the electron-packager. +Optional: '/relative-path' to specify output a subdirectory for output. +Optional: '/absolute-path to specify and absolute path for output. +Optional: '/package-json' to specify a custom package.json file. +Optional: '/install-modules' to force node module install. Implied by '/package-json' +Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version' +Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion +Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params ""--prune=true """; public static IList CommandOptions { get; set; } = new List(); diff --git a/ElectronNET.CLI/Commands/InitCommand.cs b/ElectronNET.CLI/Commands/InitCommand.cs index c253920..88e7bd5 100644 --- a/ElectronNET.CLI/Commands/InitCommand.cs +++ b/ElectronNET.CLI/Commands/InitCommand.cs @@ -25,8 +25,8 @@ namespace ElectronNET.CLI.Commands _parser.Parse(args); } - private static string _aspCoreProjectPath = "project-path"; - private static string _manifest = "manifest"; + private const string _aspCoreProjectPath = "project-path"; + private const string _manifest = "manifest"; public Task ExecuteAsync() { diff --git a/ElectronNET.CLI/Commands/StartElectronCommand.cs b/ElectronNET.CLI/Commands/StartElectronCommand.cs index ff013cd..11672fa 100644 --- a/ElectronNET.CLI/Commands/StartElectronCommand.cs +++ b/ElectronNET.CLI/Commands/StartElectronCommand.cs @@ -15,7 +15,7 @@ namespace ElectronNET.CLI.Commands public const string COMMAND_ARGUMENTS = " from ASP.NET Core Project."; public static IList CommandOptions { get; set; } = new List(); - private string[] _args; + private readonly string[] _args; public StartElectronCommand(string[] args) { diff --git a/ElectronNET.CLI/Commands/VersionCommand.cs b/ElectronNET.CLI/Commands/VersionCommand.cs index c8f60f8..0d2637c 100644 --- a/ElectronNET.CLI/Commands/VersionCommand.cs +++ b/ElectronNET.CLI/Commands/VersionCommand.cs @@ -12,7 +12,7 @@ namespace ElectronNET.CLI.Commands public const string COMMAND_ARGUMENTS = ""; public static IList CommandOptions { get; set; } = new List(); - public VersionCommand(string[] args) + public VersionCommand() { } diff --git a/ElectronNET.CLI/ProcessHelper.cs b/ElectronNET.CLI/ProcessHelper.cs index 5f7d6cc..9ac02f9 100644 --- a/ElectronNET.CLI/ProcessHelper.cs +++ b/ElectronNET.CLI/ProcessHelper.cs @@ -7,7 +7,7 @@ namespace ElectronNET.CLI { public class ProcessHelper { - private static ConcurrentDictionary _activeProcess = new(); + private static readonly ConcurrentDictionary _activeProcess = new(); public static void KillActive() { diff --git a/ElectronNET.CLI/Program.cs b/ElectronNET.CLI/Program.cs index 891b15e..8621efc 100644 --- a/ElectronNET.CLI/Program.cs +++ b/ElectronNET.CLI/Program.cs @@ -42,7 +42,7 @@ namespace ElectronNET.CLI command = new AddCommand(args.Skip(1).ToArray()); break; case VersionCommand.COMMAND_NAME: - command = new VersionCommand(args.Skip(1).ToArray()); + command = new VersionCommand(); break; case "--help": case "--h": @@ -90,27 +90,27 @@ namespace ElectronNET.CLI Console.WriteLine("\t"); Console.WriteLine("Commands to start the Electron Application:"); Console.WriteLine("\t"); - Console.WriteLine($"\t{StartElectronCommand.COMMAND_NAME.PadRight(NAME_WIDTH)} {StartElectronCommand.COMMAND_DESCRIPTION}"); + Console.WriteLine($"\t{StartElectronCommand.COMMAND_NAME,-NAME_WIDTH} {StartElectronCommand.COMMAND_DESCRIPTION}"); Console.WriteLine("\t"); Console.WriteLine("Command to build the Electron Application:"); Console.WriteLine("\t"); - Console.WriteLine($"\t{BuildCommand.COMMAND_NAME.PadRight(NAME_WIDTH)} {BuildCommand.COMMAND_DESCRIPTION}"); + Console.WriteLine($"\t{BuildCommand.COMMAND_NAME,-NAME_WIDTH} {BuildCommand.COMMAND_DESCRIPTION}"); Console.WriteLine("\t"); Console.WriteLine("Command to init the Electron Application:"); Console.WriteLine("\t"); - Console.WriteLine($"\t{InitCommand.COMMAND_NAME.PadRight(NAME_WIDTH)} {InitCommand.COMMAND_DESCRIPTION}"); + Console.WriteLine($"\t{InitCommand.COMMAND_NAME,-NAME_WIDTH} {InitCommand.COMMAND_DESCRIPTION}"); Console.WriteLine("\t"); Console.WriteLine("Command to add a custom npm packages to the Electron Application:"); Console.WriteLine("\t"); - Console.WriteLine($"\t{AddCommand.COMMAND_NAME.PadRight(NAME_WIDTH)} {AddCommand.COMMAND_DESCRIPTION}"); + Console.WriteLine($"\t{AddCommand.COMMAND_NAME,-NAME_WIDTH} {AddCommand.COMMAND_DESCRIPTION}"); Console.WriteLine("\t"); Console.WriteLine("Commands to see the current ElectronNET version number:"); Console.WriteLine("\t"); - Console.WriteLine($"\t{VersionCommand.COMMAND_NAME.PadRight(NAME_WIDTH)} {VersionCommand.COMMAND_DESCRIPTION}"); + Console.WriteLine($"\t{VersionCommand.COMMAND_NAME,-NAME_WIDTH} {VersionCommand.COMMAND_DESCRIPTION}"); Console.WriteLine("\t"); Console.WriteLine("\t"); @@ -172,7 +172,7 @@ namespace ElectronNET.CLI StringBuilder stringBuilder = new StringBuilder(); if (option.ShortSwitch != null) { - stringBuilder.Append($"{option.ShortSwitch.PadRight(6)} | "); + stringBuilder.Append($"{option.ShortSwitch,-6} | "); } stringBuilder.Append($"{option.Switch}"); @@ -184,7 +184,7 @@ namespace ElectronNET.CLI stringBuilder.Append(option.Description); - Console.WriteLine($"{new string(' ', INDENT * 2)}{stringBuilder.ToString()}"); + Console.WriteLine($"{new string(' ', INDENT * 2)}{stringBuilder}"); } } diff --git a/ElectronNET.CLI/SimpleCommandLineParser.cs b/ElectronNET.CLI/SimpleCommandLineParser.cs index 9da5d73..2391951 100644 --- a/ElectronNET.CLI/SimpleCommandLineParser.cs +++ b/ElectronNET.CLI/SimpleCommandLineParser.cs @@ -20,14 +20,20 @@ namespace ElectronNET.CLI if (arg.StartsWith("/")) { if (currentName != "") + { Arguments[currentName] = values.ToArray(); + } values.Clear(); currentName = arg.Substring(1); } else if (currentName == "") - Arguments[arg] = new string[0]; + { + Arguments[arg] = Array.Empty(); + } else + { values.Add(arg); + } } if (currentName != "") Arguments[currentName] = values.ToArray(); diff --git a/ElectronNET.WebApp/Controllers/AppSysInformationController.cs b/ElectronNET.WebApp/Controllers/AppSysInformationController.cs index 0ff6167..b7a7bbc 100644 --- a/ElectronNET.WebApp/Controllers/AppSysInformationController.cs +++ b/ElectronNET.WebApp/Controllers/AppSysInformationController.cs @@ -15,24 +15,30 @@ namespace ElectronNET.WebApp.Controllers { string appPath = await Electron.App.GetAppPathAsync(); - var mainWindow = Electron.WindowManager.BrowserWindows.First(); - Electron.IpcMain.Send(mainWindow, "got-app-path", appPath); + if (Electron.WindowManager.TryGetBrowserWindows(info.browserId, out var window)) + { + Electron.IpcMain.Send(window, "got-app-path", appPath); + } }); Electron.IpcMain.OnWithId("sys-info", async (info) => { string homePath = await Electron.App.GetPathAsync(PathName.Home); - var mainWindow = Electron.WindowManager.BrowserWindows.First(); - Electron.IpcMain.Send(mainWindow, "got-sys-info", homePath); + if (Electron.WindowManager.TryGetBrowserWindows(info.browserId, out var window)) + { + Electron.IpcMain.Send(window, "got-sys-info", homePath); + } }); Electron.IpcMain.OnWithId("screen-info", async (info) => { var display = await Electron.Screen.GetPrimaryDisplayAsync(); - var mainWindow = Electron.WindowManager.BrowserWindows.First(); - Electron.IpcMain.Send(mainWindow, "got-screen-info", display.Size); + if (Electron.WindowManager.TryGetBrowserWindows(info.browserId, out var window)) + { + Electron.IpcMain.Send(window, "got-screen-info", display.Size); + } }); } diff --git a/ElectronNET.WebApp/Controllers/MenusController.cs b/ElectronNET.WebApp/Controllers/MenusController.cs index a279774..5bb39b0 100644 --- a/ElectronNET.WebApp/Controllers/MenusController.cs +++ b/ElectronNET.WebApp/Controllers/MenusController.cs @@ -70,9 +70,11 @@ namespace ElectronNET.WebApp.Controllers { Label = "App Menu Demo", Click = async () => { - var options = new MessageBoxOptions("This demo is for the Menu section, showing how to create a clickable menu item in the application menu."); - options.Type = MessageBoxType.info; - options.Title = "Application Menu Demo"; + var options = new MessageBoxOptions("This demo is for the Menu section, showing how to create a clickable menu item in the application menu.") + { + Type = MessageBoxType.info, + Title = "Application Menu Demo" + }; await Electron.Dialog.ShowMessageBoxAsync(options); } }