mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-10-01 19:33:05 +00:00
code cleanup
This commit is contained in:
@@ -603,7 +603,7 @@ namespace ElectronNET.API
|
||||
}
|
||||
|
||||
private static App _app;
|
||||
private static object _syncRoot = new object();
|
||||
private static readonly object _syncRoot = new();
|
||||
|
||||
/// <summary>
|
||||
/// Try to close all windows. The <see cref="BeforeQuit"/> event will be emitted first. If all windows are successfully
|
||||
@@ -1376,7 +1376,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public void DestroySplashScreen() => BridgeConnector.Emit("splashscreen-destroy");
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
@@ -313,7 +313,7 @@ namespace ElectronNET.API
|
||||
private event Action<UpdateInfo> _updateDownloaded;
|
||||
|
||||
private static AutoUpdater _autoUpdater;
|
||||
private static object _syncRoot = new object();
|
||||
private static readonly object _syncRoot = new();
|
||||
|
||||
internal AutoUpdater() { }
|
||||
|
||||
|
||||
@@ -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<SocketIO> _connectedSocketTask = new TaskCompletionSource<SocketIO>();
|
||||
private static TaskCompletionSource<SocketIO> _connectedSocketTask = new();
|
||||
|
||||
private static Task<SocketIO> _waitForConnection
|
||||
{
|
||||
|
||||
@@ -1106,7 +1106,6 @@ namespace ElectronNET.API
|
||||
/// sum any extra width and height areas you have within the overall content view.
|
||||
/// </summary>
|
||||
/// <param name="aspectRatio">The aspect ratio to maintain for some portion of the content view.</param>
|
||||
/// <param name="extraSize">The extra size not to be included while maintaining the aspect ratio.</param>
|
||||
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.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
|
||||
private List<MenuItem> _items = new List<MenuItem>();
|
||||
private readonly List<MenuItem> _items = new();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the menu as the window’s menu bar,
|
||||
@@ -1844,7 +1843,7 @@ namespace ElectronNET.API
|
||||
/// </value>
|
||||
public IReadOnlyCollection<ThumbarButton> ThumbarButtons { get { return _thumbarButtons.AsReadOnly(); } }
|
||||
|
||||
private List<ThumbarButton> _thumbarButtons = new List<ThumbarButton>();
|
||||
private readonly List<ThumbarButton> _thumbarButtons = new();
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace ElectronNET.API
|
||||
|
||||
private static CommandLine _commandLine;
|
||||
|
||||
private static object _syncRoot = new object();
|
||||
private static readonly object _syncRoot = new();
|
||||
|
||||
/// <summary>
|
||||
/// Append a switch (with optional value) to Chromium's command line.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
|
||||
private List<MenuItem> _items = new List<MenuItem>();
|
||||
private readonly List<MenuItem> _items = new();
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace ElectronNET.API.Entities
|
||||
public bool? FullscreenWindowTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Activate the Window Controls Overlay on Windows, when combined with <see cref="TitleBarStyle"/> = <see cref="TitleBarStyle.Hidden"/>
|
||||
/// Activate the Window Controls Overlay on Windows, when combined with <see cref="TitleBarStyle"/> = <see cref="TitleBarStyle.hidden"/>
|
||||
/// </summary>
|
||||
[SupportedOSPlatform("win")]
|
||||
[DefaultValue(null)]
|
||||
|
||||
@@ -16,10 +16,10 @@ namespace ElectronNET.API.Entities
|
||||
[JsonConverter(typeof(NativeImageJsonConverter))]
|
||||
public class NativeImage
|
||||
{
|
||||
private readonly Dictionary<float, Image> _images = new Dictionary<float, Image>();
|
||||
private readonly Dictionary<float, Image> _images = new();
|
||||
private bool _isTemplateImage;
|
||||
|
||||
private static readonly Dictionary<string, float> ScaleFactorPairs = new Dictionary<string, float>
|
||||
private static readonly Dictionary<string, float> 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},
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ElectronNET.API.Extensions
|
||||
|
||||
public static MenuItem GetMenuItem(this List<MenuItem> menuItems, string id)
|
||||
{
|
||||
MenuItem result = new MenuItem();
|
||||
MenuItem result = new();
|
||||
|
||||
foreach (var item in menuItems)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ElectronNET.API.Extensions
|
||||
|
||||
public static ThumbarButton GetThumbarButton(this List<ThumbarButton> thumbarButtons, string id)
|
||||
{
|
||||
ThumbarButton result = new ThumbarButton("");
|
||||
ThumbarButton result = new("");
|
||||
|
||||
foreach (var item in thumbarButtons)
|
||||
{
|
||||
|
||||
@@ -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<string, Action> _shortcuts = new Dictionary<string, Action>();
|
||||
private readonly Dictionary<string, Action> _shortcuts = new();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a global shortcut of accelerator.
|
||||
|
||||
@@ -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() { }
|
||||
|
||||
|
||||
@@ -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
|
||||
/// <param name="data">Arguments data.</param>
|
||||
public void Send(BrowserWindow browserWindow, string channel, params object[] data)
|
||||
{
|
||||
var objectsWithCorrectSerialization = new List<object>();
|
||||
|
||||
objectsWithCorrectSerialization.Add(browserWindow.Id);
|
||||
objectsWithCorrectSerialization.Add(channel);
|
||||
var objectsWithCorrectSerialization = new List<object>
|
||||
{
|
||||
browserWindow.Id,
|
||||
channel
|
||||
};
|
||||
|
||||
foreach (var parameterObject in data)
|
||||
{
|
||||
@@ -209,9 +210,9 @@ namespace ElectronNET.API
|
||||
/// <param name="data">Arguments data.</param>
|
||||
public void Send(BrowserView browserView, string channel, params object[] data)
|
||||
{
|
||||
List<JObject> jobjects = new List<JObject>();
|
||||
List<JArray> jarrays = new List<JArray>();
|
||||
List<object> objects = new List<object>();
|
||||
List<JObject> jobjects = new();
|
||||
List<JArray> jarrays = new();
|
||||
List<object> 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,
|
||||
|
||||
@@ -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.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<MenuItem> MenuItems { get { return _menuItems.AsReadOnly(); } }
|
||||
private List<MenuItem> _menuItems = new List<MenuItem>();
|
||||
private readonly List<MenuItem> _menuItems = new();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the application menu.
|
||||
@@ -75,7 +75,7 @@ namespace ElectronNET.API
|
||||
/// The context menu items.
|
||||
/// </value>
|
||||
public IReadOnlyDictionary<int, ReadOnlyCollection<MenuItem>> ContextMenuItems { get; internal set; }
|
||||
private Dictionary<int, List<MenuItem>> _contextMenuItems = new Dictionary<int, List<MenuItem>>();
|
||||
private readonly Dictionary<int, List<MenuItem>> _contextMenuItems = new();
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
@@ -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() { }
|
||||
|
||||
|
||||
@@ -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> _notificationOptions = new List<NotificationOptions>();
|
||||
private static readonly List<NotificationOptions> _notificationOptions = new();
|
||||
|
||||
/// <summary>
|
||||
/// 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,
|
||||
|
||||
@@ -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() { }
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace ElectronNET.API
|
||||
private event Action<Display, string[]> _onDisplayMetricsChanged;
|
||||
|
||||
private static Screen _screen;
|
||||
private static object _syncRoot = new object();
|
||||
private static readonly object _syncRoot = new();
|
||||
|
||||
internal Screen() { }
|
||||
|
||||
|
||||
@@ -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() { }
|
||||
|
||||
|
||||
@@ -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.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
|
||||
private List<MenuItem> _items = new List<MenuItem>();
|
||||
private readonly List<MenuItem> _items = new();
|
||||
|
||||
/// <summary>
|
||||
/// Shows the Traybar.
|
||||
@@ -368,7 +368,7 @@ namespace ElectronNET.API
|
||||
/// <param name="fn">The handler</param>
|
||||
public void Once(string eventName, Action<object> fn) => Events.Instance.Once(ModuleName, eventName, fn);
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
|
||||
@@ -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<int, BrowserWindow> _browserWindows = new ();
|
||||
private readonly ConcurrentDictionary<int, BrowserWindow> _browserWindows = new ();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the browser views.
|
||||
@@ -84,7 +84,7 @@ namespace ElectronNET.API
|
||||
/// The browser view.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<BrowserView> BrowserViews { get { return _browserViews.Values.ToList().AsReadOnly(); } }
|
||||
private ConcurrentDictionary<int, BrowserView> _browserViews = new ();
|
||||
private readonly ConcurrentDictionary<int, BrowserView> _browserViews = new ();
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
Reference in New Issue
Block a user