Merge pull request #914 from softworkz/submit_whitespace

Fix and normalize whitespace
This commit is contained in:
Florian Rappl
2025-11-09 12:25:49 +01:00
committed by GitHub
50 changed files with 429 additions and 231 deletions

View File

@@ -45,13 +45,14 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("register-app-before-quit", GetHashCode());
}
_beforeQuit += value;
}
remove
@@ -168,6 +170,7 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("register-app-will-quit", GetHashCode());
}
_willQuit += value;
}
remove
@@ -194,7 +197,7 @@ namespace ElectronNET.API
{
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 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("register-app-will-quit", GetHashCode() + "quitting");
}
_quitting += value;
}
remove
@@ -276,11 +280,11 @@ namespace ElectronNET.API
/// <summary>
/// Emitted when the application has finished basic startup.
/// </summary>
public event Action Ready
public event Action Ready
{
add
{
if(IsReady)
if (IsReady)
{
value();
}
@@ -298,19 +302,23 @@ namespace ElectronNET.API
/// <summary>
/// Application host fully started.
/// </summary>
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;
/// <summary>
@@ -379,7 +387,7 @@ namespace ElectronNET.API
}
internal App()
internal App()
{
CommandLine = new CommandLine();
}
@@ -392,7 +400,7 @@ namespace ElectronNET.API
{
lock (_syncRoot)
{
if(_app == null)
if (_app == null)
{
_app = new App();
}
@@ -541,7 +549,7 @@ namespace ElectronNET.API
cancellationToken.ThrowIfCancellationRequested();
var taskCompletionSource = new TaskCompletionSource<string>();
using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
BridgeConnector.Socket.On("appGetPathCompleted", (path) =>
{
@@ -554,7 +562,7 @@ namespace ElectronNET.API
return await taskCompletionSource.Task
.ConfigureAwait(false);
}
}
}
/// <summary>
@@ -715,7 +723,7 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Whether the call succeeded.</returns>
public async Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default)
{
{
cancellationToken.ThrowIfCancellationRequested();
var taskCompletionSource = new TaskCompletionSource<bool>();
@@ -769,7 +777,7 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
{
BridgeConnector.Socket.Off("appGetLoginItemSettingsCompleted");
var result = ((JObject) loginItemSettings).ToObject<LoginItemSettings>();
var result = ((JObject)loginItemSettings).ToObject<LoginItemSettings>();
taskCompletionSource.SetResult(result);
});
@@ -1310,6 +1318,7 @@ namespace ElectronNET.API
private bool _preventQuit = false;
private const string ModuleName = "app";
/// <summary>
/// Subscribe to an unmapped event on the <see cref="App"/> module.
/// </summary>
@@ -1317,6 +1326,7 @@ namespace ElectronNET.API
/// <param name="action">The handler</param>
public void On(string eventName, Action action)
=> Events.Instance.On(ModuleName, eventName, action);
/// <summary>
/// Subscribe to an unmapped event on the <see cref="App"/> module.
/// </summary>
@@ -1324,6 +1334,7 @@ namespace ElectronNET.API
/// <param name="action">The handler</param>
public async Task On(string eventName, Action<object> action)
=> await Events.Instance.On(ModuleName, eventName, action).ConfigureAwait(false);
/// <summary>
/// Subscribe to an unmapped event on the <see cref="App"/> module once.
/// </summary>
@@ -1331,6 +1342,7 @@ namespace ElectronNET.API
/// <param name="action">The handler</param>
public void Once(string eventName, Action action)
=> Events.Instance.Once(ModuleName, eventName, action);
/// <summary>
/// Subscribe to an unmapped event on the <see cref="App"/> module once.
/// </summary>
@@ -1339,4 +1351,4 @@ namespace ElectronNET.API
public async Task Once(string eventName, Action<object> action)
=> await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false);
}
}
}

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ElectronNET.Common;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API
@@ -249,7 +250,6 @@ namespace ElectronNET.API
}
/// <summary>
/// The request headers.
/// </summary>
@@ -353,7 +353,9 @@ namespace ElectronNET.API
private static AutoUpdater _autoUpdater;
private static object _syncRoot = new object();
internal AutoUpdater() { }
internal AutoUpdater()
{
}
internal static AutoUpdater Instance
{
@@ -512,4 +514,4 @@ namespace ElectronNET.API
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
}
}
}

View File

@@ -59,7 +59,7 @@ namespace ElectronNET.API
/// <summary>
/// BrowserView
/// </summary>
internal BrowserView(int id)
internal BrowserView(int id)
{
Id = id;
@@ -94,4 +94,4 @@ namespace ElectronNET.API
NullValueHandling = NullValueHandling.Ignore
};
}
}
}

View File

@@ -9,6 +9,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ElectronNET.Common;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API;
@@ -96,8 +97,8 @@ public class BrowserWindow : ApiBase
/// </summary>
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 class BrowserWindow : ApiBase
{
x = x - 7;
}
this.CallMethod2(x, y);
}
@@ -769,6 +771,7 @@ public class BrowserWindow : ApiBase
{
x = x - 7;
}
this.CallMethod3(x, y, animate);
}
@@ -906,7 +909,14 @@ public class BrowserWindow : ApiBase
/// <value>
/// The menu items.
/// </value>
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
public IReadOnlyCollection<MenuItem> MenuItems
{
get
{
return _items.AsReadOnly();
}
}
private List<MenuItem> _items = new List<MenuItem>();
/// <summary>
@@ -981,7 +991,14 @@ public class BrowserWindow : ApiBase
/// <value>
/// The thumbar buttons.
/// </value>
public IReadOnlyCollection<ThumbarButton> ThumbarButtons { get { return _thumbarButtons.AsReadOnly(); } }
public IReadOnlyCollection<ThumbarButton> ThumbarButtons
{
get
{
return _thumbarButtons.AsReadOnly();
}
}
private List<ThumbarButton> _thumbarButtons = new List<ThumbarButton>();
/// <summary>

View File

@@ -14,7 +14,9 @@ namespace ElectronNET.API
private static Clipboard _clipboard;
private static object _syncRoot = new object();
internal Clipboard() { }
internal Clipboard()
{
}
internal static Clipboard Instance
{
@@ -253,14 +255,13 @@ namespace ElectronNET.API
var nativeImage = ((JObject)image).ToObject<NativeImage>();
taskCompletionSource.SetResult(nativeImage);
});
BridgeConnector.Socket.Emit("clipboard-readImage", type);
return taskCompletionSource.Task;
}
/// <summary>
/// Writes an image to the clipboard.
/// </summary>

View File

@@ -8,7 +8,9 @@ namespace ElectronNET.API
/// </summary>
public sealed class CommandLine
{
internal CommandLine() { }
internal CommandLine()
{
}
internal static CommandLine Instance
{
@@ -66,7 +68,7 @@ namespace ElectronNET.API
/// <param name="switchName">A command-line switch</param>
/// <param name="cancellationToken"></param>
/// <returns>Whether the command-line switch is present.</returns>
public async Task<bool> HasSwitchAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken))
public async Task<bool> HasSwitchAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
@@ -113,4 +115,4 @@ namespace ElectronNET.API
}
}
}
}
}

View File

@@ -44,6 +44,7 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("register-webContents-session-cookies-changed", Id);
}
_changed += value;
}
remove

View File

@@ -16,7 +16,9 @@ namespace ElectronNET.API
private static Dialog _dialog;
private static object _syncRoot = new object();
internal Dialog() { }
internal Dialog()
{
}
internal static Dialog Instance
{
@@ -26,7 +28,7 @@ namespace ElectronNET.API
{
lock (_syncRoot)
{
if(_dialog == null)
if (_dialog == null)
{
_dialog = new Dialog();
}
@@ -60,8 +62,8 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
});
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}
}

View File

@@ -60,7 +60,7 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
/// <value>
/// The menu items.
/// </value>
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
public IReadOnlyCollection<MenuItem> MenuItems
{
get
{
return _items.AsReadOnly();
}
}
private List<MenuItem> _items = new List<MenuItem>();
/// <summary>
@@ -183,11 +190,11 @@ namespace ElectronNET.API
_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();
});
}
/// <summary>

View File

@@ -8,62 +8,134 @@
/// <summary>
/// Communicate asynchronously from the main process to renderer processes.
/// </summary>
public static IpcMain IpcMain { get { return IpcMain.Instance; } }
public static IpcMain IpcMain
{
get
{
return IpcMain.Instance;
}
}
/// <summary>
/// Control your application's event lifecycle.
/// </summary>
public static App App { get { return App.Instance; } }
public static App App
{
get
{
return App.Instance;
}
}
/// <summary>
/// Enable apps to automatically update themselves. Based on electron-updater.
/// </summary>
public static AutoUpdater AutoUpdater { get { return AutoUpdater.Instance; } }
public static AutoUpdater AutoUpdater
{
get
{
return AutoUpdater.Instance;
}
}
/// <summary>
/// Control your windows.
/// </summary>
public static WindowManager WindowManager { get { return WindowManager.Instance; } }
public static WindowManager WindowManager
{
get
{
return WindowManager.Instance;
}
}
/// <summary>
/// Create native application menus and context menus.
/// </summary>
public static Menu Menu { get { return Menu.Instance; } }
public static Menu Menu
{
get
{
return Menu.Instance;
}
}
/// <summary>
/// Display native system dialogs for opening and saving files, alerting, etc.
/// </summary>
public static Dialog Dialog { get { return Dialog.Instance; } }
public static Dialog Dialog
{
get
{
return Dialog.Instance;
}
}
/// <summary>
/// Create OS desktop notifications
/// </summary>
public static Notification Notification { get { return Notification.Instance; } }
public static Notification Notification
{
get
{
return Notification.Instance;
}
}
/// <summary>
/// Add icons and context menus to the systems notification area.
/// </summary>
public static Tray Tray { get { return Tray.Instance; } }
public static Tray Tray
{
get
{
return Tray.Instance;
}
}
/// <summary>
/// Detect keyboard events when the application does not have keyboard focus.
/// </summary>
public static GlobalShortcut GlobalShortcut { get { return GlobalShortcut.Instance; } }
public static GlobalShortcut GlobalShortcut
{
get
{
return GlobalShortcut.Instance;
}
}
/// <summary>
/// Manage files and URLs using their default applications.
/// </summary>
public static Shell Shell { get { return Shell.Instance; } }
public static Shell Shell
{
get
{
return Shell.Instance;
}
}
/// <summary>
/// Retrieve information about screen size, displays, cursor position, etc.
/// </summary>
public static Screen Screen { get { return Screen.Instance; } }
public static Screen Screen
{
get
{
return Screen.Instance;
}
}
/// <summary>
/// Perform copy and paste operations on the system clipboard.
/// </summary>
public static Clipboard Clipboard { get { return Clipboard.Instance; } }
public static Clipboard Clipboard
{
get
{
return Clipboard.Instance;
}
}
/// <summary>
/// Allows you to execute native JavaScript/TypeScript code from the host process.
@@ -72,26 +144,56 @@
/// ElectronHostHook directory:
/// <c>electronize add HostHook</c>
/// </summary>
public static HostHook HostHook { get { return HostHook.Instance; } }
public static HostHook HostHook
{
get
{
return HostHook.Instance;
}
}
/// <summary>
/// Allows you to execute native Lock and Unlock process.
/// </summary>
public static PowerMonitor PowerMonitor { get { return PowerMonitor.Instance; } }
public static PowerMonitor PowerMonitor
{
get
{
return PowerMonitor.Instance;
}
}
/// <summary>
/// Read and respond to changes in Chromium's native color theme.
/// </summary>
public static NativeTheme NativeTheme { get { return NativeTheme.Instance; } }
public static NativeTheme NativeTheme
{
get
{
return NativeTheme.Instance;
}
}
/// <summary>
/// Control your app in the macOS dock.
/// </summary>
public static Dock Dock { get { return Dock.Instance; } }
public static Dock Dock
{
get
{
return Dock.Instance;
}
}
/// <summary>
/// Electeon extensions to the Nodejs process object.
/// </summary>
public static Process Process { get { return Process.Instance; } }
public static Process Process
{
get
{
return Process.Instance;
}
}
}
}

View File

@@ -28,6 +28,6 @@ namespace ElectronNET.API.Entities
/// <summary>
/// Gets or sets the dataURL
/// </summary>
public string DataUrl { get; set; }
public string DataUrl { get; set; }
}
}

View File

@@ -1,12 +1,13 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ElectronNET.API.Entities {
namespace ElectronNET.API.Entities
{
/// <summary>
/// The cause of the change
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum CookieChangedCause
public enum CookieChangedCause
{
/// <summary>
///The cookie was changed directly by a consumer's action.

View File

@@ -1,10 +1,12 @@
using System.ComponentModel;
namespace ElectronNET.API.Entities {
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class CookieDetails {
public class CookieDetails
{
/// <summary>
/// The URL to associate the cookie with. The callback will be rejected if the URL is invalid.
/// </summary>
@@ -19,7 +21,7 @@ namespace ElectronNET.API.Entities {
/// <summary>
/// (optional) - The value of the cookie. Empty by default if omitted.
/// </summary>
[DefaultValue("")]
[DefaultValue("")]
public string Value { get; set; }
/// <summary>
@@ -31,13 +33,13 @@ namespace ElectronNET.API.Entities {
/// <summary>
/// (optional) - The path of the cookie. Empty by default if omitted.
/// </summary>
[DefaultValue("")]
[DefaultValue("")]
public string Path { get; set; }
/// <summary>
/// (optional) - Whether the cookie is marked as secure. Defaults to false.
/// </summary>
[DefaultValue(false)]
[DefaultValue(false)]
public bool Secure { get; set; }
/// <summary>
@@ -53,4 +55,4 @@ namespace ElectronNET.API.Entities {
[DefaultValue(0)]
public long ExpirationDate { get; set; }
}
}
}

View File

@@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Text;
namespace ElectronNET.API.Entities
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class CookieFilter
public class CookieFilter
{
/// <summary>
/// (optional) - Retrieves cookies which are associated with url.Empty implies retrieving cookies of all URLs.
@@ -38,6 +38,5 @@ namespace ElectronNET.API.Entities
/// (optional) - Filters out session or persistent cookies.
/// </summary>
public bool Session { get; set; }
}
}
}

View File

@@ -9,10 +9,10 @@
/// Path for the pkcs12 file.
/// </summary>
public string Certificate { get; set; }
/// <summary>
/// Passphrase for the certificate.
/// </summary>
public string Password {get; set; }
public string Password { get; set; }
}
}
}

View File

@@ -9,26 +9,32 @@ public enum InputEventType
///
/// </summary>
undefined,
/// <summary>
///
/// </summary>
mouseDown,
/// <summary>
///
/// </summary>
mouseUp,
/// <summary>
///
/// </summary>
mouseMove,
/// <summary>
///
/// </summary>
mouseEnter,
/// <summary>
///
/// </summary>
mouseLeave,
/// <summary>
///
/// </summary>

View File

@@ -21,9 +21,9 @@ namespace ElectronNET.API.Entities
private static readonly Dictionary<string, float> ScaleFactorPairs = new Dictionary<string, float>
{
{"@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 @@ namespace ElectronNET.API.Entities
.Select(p => p.Value)
.FirstOrDefault();
}
private static Image BytesToImage(byte[] bytes)
{
var ms = new MemoryStream(bytes);
@@ -83,7 +84,7 @@ namespace ElectronNET.API.Entities
/// <param name="dataUrl">A data URL with a base64 encoded image.</param>
public static NativeImage CreateFromDataURL(string dataUrl)
{
var images = new Dictionary<float,Image>();
var images = new Dictionary<float, Image>();
var parsedDataUrl = Regex.Match(dataUrl, @"data:image/(?<type>.+?),(?<data>.+)");
var actualData = parsedDataUrl.Groups["data"].Value;
var binData = Convert.FromBase64String(actualData);
@@ -101,7 +102,7 @@ namespace ElectronNET.API.Entities
/// <param name="path">The path of the image</param>
public static NativeImage CreateFromPath(string path)
{
var images = new Dictionary<float,Image>();
var images = new Dictionary<float, Image>();
if (Regex.IsMatch(path, "(@.+?x)"))
{
var dpi = ExtractDpiFromFilePath(path);
@@ -164,7 +165,7 @@ namespace ElectronNET.API.Entities
/// </summary>
public NativeImage Crop(Rectangle rect)
{
var images = new Dictionary<float,Image>();
var images = new Dictionary<float, Image>();
foreach (var image in _images)
{
images.Add(image.Key, Crop(rect.X, rect.Y, rect.Width, rect.Height, image.Key));
@@ -196,7 +197,7 @@ namespace ElectronNET.API.Entities
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 @@ namespace ElectronNET.API.Entities
/// </summary>
public byte[] GetBitmap(BitmapOptions options)
{
return ToBitmap(new ToBitmapOptions{ ScaleFactor = options.ScaleFactor });
return ToBitmap(new ToBitmapOptions { ScaleFactor = options.ScaleFactor });
}
/// <summary>
@@ -419,12 +420,13 @@ namespace ElectronNET.API.Entities
return codec;
}
}
return null;
}
internal Dictionary<float,string> GetAllScaledImages()
internal Dictionary<float, string> GetAllScaledImages()
{
var dict = new Dictionary<float,string>();
var dict = new Dictionary<float, string>();
try
{
foreach (var (scale, image) in _images)
@@ -436,7 +438,7 @@ namespace ElectronNET.API.Entities
{
Console.WriteLine(ex);
}
return dict;
}
@@ -450,4 +452,4 @@ namespace ElectronNET.API.Entities
return null;
}
}
}
}

View File

@@ -26,9 +26,10 @@ namespace ElectronNET.API.Entities
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);
}
}
}

View File

@@ -67,7 +67,7 @@ namespace ElectronNET.API.Entities
/// true for landscape, false for portrait.
/// </summary>
public bool Landscape { get; set; }
/// <summary>
/// The scale factor of the web page
/// </summary>
@@ -102,6 +102,5 @@ namespace ElectronNET.API.Entities
/// Dpi
/// </summary>
public PrintDpi Dpi { get; set; }
}
}

View File

@@ -14,7 +14,7 @@ namespace ElectronNET.API.Entities
/// Name
/// </summary>
public string Description { get; set; }
/// <summary>
/// Status
/// </summary>
@@ -24,6 +24,5 @@ namespace ElectronNET.API.Entities
/// Is default
/// </summary>
public bool IsDefault { get; set; }
}
}

View File

@@ -8,35 +8,43 @@
/// <summary>
///
/// </summary>
public string Raw { get; set; }
public string Raw { get; set; }
/// <summary>
///
/// </summary>
public bool Loose { get; set; }
/// <summary>
///
/// </summary>
public SemVerOptions Options { get; set; }
/// <summary>
///
/// </summary>
public int Major { get; set; }
/// <summary>
///
/// </summary>
public int Minor { get; set; }
/// <summary>
///
/// </summary>
public int Patch { get; set; }
/// <summary>
///
/// </summary>
public string Version { get; set; }
/// <summary>
///
/// </summary>
public string[] Build { get; set; }
/// <summary>
///
/// </summary>
@@ -46,14 +54,16 @@
/// <summary>
///
/// </summary>
public class SemVerOptions {
public class SemVerOptions
{
/// <summary>
///
/// </summary>
public bool? Loose { get; set; }
/// <summary>
///
/// </summary>
public bool? IncludePrerelease { get; set; }
}
}
}

View File

@@ -15,7 +15,6 @@
/// </summary>
public void Cancel()
{
}
/// <summary>
@@ -23,7 +22,6 @@
/// </summary>
public void Dispose()
{
}
}
}
}

View File

@@ -9,7 +9,7 @@
/// The data is available as a Buffer, in the rawData field.
/// </summary>
public string Type { get; } = "rawData";
/// <summary>
/// The raw bytes of the post data in a Buffer.
/// </summary>

View File

@@ -27,8 +27,9 @@ namespace ElectronNET.API.Extensions
return ((DescriptionAttribute)attrs[0]).Description;
}
}
//If we have no description attribute, just return the ToString of the enum
return enumerationValue.ToString();
}
}
}
}

View File

@@ -56,7 +56,7 @@ namespace ElectronNET.API.Extensions
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 @@ namespace ElectronNET.API.Extensions
return menuItems;
}
}
}
}

View File

@@ -12,7 +12,9 @@ namespace ElectronNET.API
private static GlobalShortcut _globalShortcut;
private static object _syncRoot = new object();
internal GlobalShortcut() { }
internal GlobalShortcut()
{
}
internal static GlobalShortcut Instance
{

View File

@@ -17,9 +17,11 @@ namespace ElectronNET.API
{
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 @@ namespace ElectronNET.API
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}
}

View File

@@ -17,17 +17,19 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
{
await BridgeConnector.Socket.Emit("registerIpcMainChannel", channel).ConfigureAwait(false);
BridgeConnector.Socket.Off(channel);
BridgeConnector.Socket.On(channel, (args) =>
BridgeConnector.Socket.On(channel, (args) =>
{
List<object> objectArray = FormatArguments(args);
if(objectArray.Count == 1)
if (objectArray.Count == 1)
{
listener(objectArray.First());
}
@@ -91,7 +93,8 @@ namespace ElectronNET.API
public void OnSync(string channel, Func<object, object> listener)
{
BridgeConnector.Socket.Emit("registerSyncIpcMainChannel", channel);
BridgeConnector.Socket.On(channel, (args) => {
BridgeConnector.Socket.On(channel, (args) =>
{
List<object> objectArray = FormatArguments(args);
object parameter;
if (objectArray.Count == 1)
@@ -158,19 +161,21 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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());
}

View File

@@ -17,7 +17,9 @@ namespace ElectronNET.API
private static Menu _menu;
private static object _syncRoot = new object();
internal Menu() { }
internal Menu()
{
}
internal static Menu Instance
{
@@ -27,7 +29,7 @@ namespace ElectronNET.API
{
lock (_syncRoot)
{
if(_menu == null)
if (_menu == null)
{
_menu = new Menu();
}
@@ -44,7 +46,14 @@ namespace ElectronNET.API
/// <value>
/// The menu items.
/// </value>
public IReadOnlyCollection<MenuItem> MenuItems { get { return _menuItems.AsReadOnly(); } }
public IReadOnlyCollection<MenuItem> MenuItems
{
get
{
return _menuItems.AsReadOnly();
}
}
private List<MenuItem> _menuItems = new List<MenuItem>();
/// <summary>
@@ -62,7 +71,8 @@ namespace ElectronNET.API
_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 @@ 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>>();
/// <summary>
@@ -122,4 +133,4 @@ namespace ElectronNET.API
NullValueHandling = NullValueHandling.Ignore
};
}
}
}

View File

@@ -14,7 +14,9 @@ namespace ElectronNET.API
private static NativeTheme _nativeTheme;
private static object _syncRoot = new object();
internal NativeTheme() { }
internal NativeTheme()
{
}
internal static NativeTheme Instance
{
@@ -129,7 +131,8 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource<bool>();
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 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource<bool>();
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 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) => {
BridgeConnector.Socket.On("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) =>
{
BridgeConnector.Socket.Off("nativeTheme-shouldUseInvertedColorScheme-completed");
taskCompletionSource.SetResult((bool)shouldUseInvertedColorScheme);

View File

@@ -17,7 +17,9 @@ namespace ElectronNET.API
private static Notification _notification;
private static object _syncRoot = new object();
internal Notification() { }
internal Notification()
{
}
internal static Notification Instance
{
@@ -61,9 +63,7 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
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 @@ namespace ElectronNET.API
isActionDefined = true;
BridgeConnector.Socket.Off("NotificationEventReply");
BridgeConnector.Socket.On("NotificationEventReply", (args) => {
BridgeConnector.Socket.On("NotificationEventReply", (args) =>
{
var arguments = ((JArray)args).ToObject<string[]>();
_notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnReply(arguments[1].ToString());
});
@@ -106,7 +103,8 @@ namespace ElectronNET.API
isActionDefined = true;
BridgeConnector.Socket.Off("NotificationEventAction");
BridgeConnector.Socket.On("NotificationEventAction", (args) => {
BridgeConnector.Socket.On("NotificationEventAction", (args) =>
{
var arguments = ((JArray)args).ToObject<string[]>();
_notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnAction(arguments[1].ToString());
});
@@ -144,4 +142,4 @@ namespace ElectronNET.API
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using ElectronNET.Common;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API
@@ -75,7 +76,7 @@ namespace ElectronNET.API
}
private event Action _onBattery;
/// <summary>
/// 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 @@ namespace ElectronNET.API
private static PowerMonitor _powerMonitor;
private static object _syncRoot = new object();
internal PowerMonitor() { }
internal PowerMonitor()
{
}
internal static PowerMonitor Instance
{
@@ -114,4 +117,4 @@ namespace ElectronNET.API
}
}
}
}
}

View File

@@ -12,7 +12,9 @@ namespace ElectronNET.API
/// </summary>
public sealed class Process
{
internal Process() { }
internal Process()
{
}
internal static Process Instance
{
@@ -102,13 +104,13 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
}
/// <summary>
/// The process.versions property returns an object listing the version strings of
/// chrome and electron.
/// </summary>
public Task<ProcessVersions> VersionsAsync
public Task<ProcessVersions> VersionsAsync
{
get
{
@@ -124,8 +126,8 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
}
/// <summary>
/// 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 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
}
}
}
}

View File

@@ -51,7 +51,9 @@ namespace ElectronNET.API
private static Screen _screen;
private static object _syncRoot = new object();
internal Screen() { }
internal Screen()
{
}
internal static Screen Instance
{
@@ -76,7 +78,7 @@ namespace ElectronNET.API
/// The current absolute position of the mouse pointer.
/// </summary>
/// <returns></returns>
public Task<Point> GetCursorScreenPointAsync()
public Task<Point> GetCursorScreenPointAsync()
{
var taskCompletionSource = new TaskCompletionSource<Point>();

View File

@@ -460,4 +460,4 @@ namespace ElectronNET.API
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}
}

View File

@@ -15,7 +15,9 @@ namespace ElectronNET.API
private static Shell _shell;
private static object _syncRoot = new object();
internal Shell() { }
internal Shell()
{
}
internal static Shell Instance
{
@@ -44,10 +46,7 @@ namespace ElectronNET.API
{
var taskCompletionSource = new TaskCompletionSource<object>();
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 @@ namespace ElectronNET.API
{
BridgeConnector.Socket.Off("shell-openPathCompleted");
taskCompletionSource.SetResult((string) errorMessage);
taskCompletionSource.SetResult((string)errorMessage);
});
BridgeConnector.Socket.Emit("shell-openPath", path);
@@ -101,7 +100,7 @@ namespace ElectronNET.API
{
BridgeConnector.Socket.Off("shell-openExternalCompleted");
taskCompletionSource.SetResult((string) error);
taskCompletionSource.SetResult((string)error);
});
if (options == null)
@@ -129,7 +128,7 @@ namespace ElectronNET.API
{
BridgeConnector.Socket.Off("shell-trashItem-completed");
taskCompletionSource.SetResult((bool) success);
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Emit("shell-trashItem", fullPath);
@@ -160,7 +159,7 @@ namespace ElectronNET.API
{
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 @@ namespace ElectronNET.API
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}
}

View File

@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ElectronNET.Common;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API
@@ -88,7 +89,9 @@ namespace ElectronNET.API
private static Tray _tray;
private static readonly object _syncRoot = new();
internal Tray() { }
internal Tray()
{
}
internal static Tray Instance
{
@@ -239,6 +242,7 @@ namespace ElectronNET.API
};
private const string ModuleName = "tray";
/// <summary>
/// Subscribe to an unmapped event on the <see cref="Tray"/> module.
/// </summary>
@@ -246,6 +250,7 @@ namespace ElectronNET.API
/// <param name="action">The handler</param>
public void On(string eventName, Action action)
=> Events.Instance.On(ModuleName, eventName, action);
/// <summary>
/// Subscribe to an unmapped event on the <see cref="Tray"/> module.
/// </summary>
@@ -253,6 +258,7 @@ namespace ElectronNET.API
/// <param name="action">The handler</param>
public async Task On<T>(string eventName, Action<T> action)
=> await Events.Instance.On(ModuleName, eventName, action).ConfigureAwait(false);
/// <summary>
/// Subscribe to an unmapped event on the <see cref="Tray"/> module once.
/// </summary>
@@ -260,6 +266,7 @@ namespace ElectronNET.API
/// <param name="action">The handler</param>
public void Once(string eventName, Action action)
=> Events.Instance.Once(ModuleName, eventName, action);
/// <summary>
/// Subscribe to an unmapped event on the <see cref="Tray"/> module once.
/// </summary>
@@ -268,4 +275,4 @@ namespace ElectronNET.API
public async Task Once<T>(string eventName, Action<T> action)
=> await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false);
}
}
}

View File

@@ -5,6 +5,7 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Threading.Tasks;
using ElectronNET.Common;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API;
@@ -187,7 +188,7 @@ public class WebContents
taskCompletionSource.SetResult((bool)success);
});
if(options == null)
if (options == null)
{
BridgeConnector.Socket.Emit("webContents-print", Id, "");
}
@@ -218,7 +219,7 @@ public class WebContents
taskCompletionSource.SetResult((bool)success);
});
if(options == null)
if (options == null)
{
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path);
}

View File

@@ -8,6 +8,7 @@ namespace ElectronNET.API.Entities
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 @@ namespace ElectronNET.API.Entities
{
BridgeConnector.Socket.On($"webContents-session-webRequest-onBeforeRequest{Id}",
(args) =>
{
////var details = ((JObject)args[0]).ToObject<OnBeforeRequestDetails>();
////var callback = args.Length > 1 ? (Action<object>)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); }) : null;
var details = ((JObject)args).ToObject<OnBeforeRequestDetails>();
var callback = (Action<object>)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); });
{
////var details = ((JObject)args[0]).ToObject<OnBeforeRequestDetails>();
////var callback = args.Length > 1 ? (Action<object>)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); }) : null;
var details = ((JObject)args).ToObject<OnBeforeRequestDetails>();
var callback = (Action<object>)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); });
_onBeforeRequest?.Invoke(details, callback);
});
_onBeforeRequest?.Invoke(details, callback);
});
BridgeConnector.Socket.Emit("register-webContents-session-webRequest-onBeforeRequest", Id, JObject.FromObject(filter));
}

View File

@@ -19,7 +19,9 @@ namespace ElectronNET.API
private static WindowManager _windowManager;
private static readonly object SyncRoot = new();
internal WindowManager() { }
internal WindowManager()
{
}
internal static WindowManager Instance
{
@@ -55,6 +57,7 @@ namespace ElectronNET.API
_isQuitOnWindowAllClosed = value;
}
}
private bool _isQuitOnWindowAllClosed = true;
/// <summary>
@@ -214,4 +217,4 @@ namespace ElectronNET.API
NullValueHandling = NullValueHandling.Ignore
};
}
}
}

View File

@@ -16,7 +16,8 @@ namespace ElectronNET.API
private readonly TextInfo _textInfo = new CultureInfo("en-US", false).TextInfo;
private Events()
{ }
{
}
public static Events Instance
{
@@ -94,6 +95,5 @@ namespace ElectronNET.API
BridgeConnector.Socket.Once(listener, action);
await BridgeConnector.Socket.Emit(subscriber, eventName, listener).ConfigureAwait(false);
}
}
}
}

View File

@@ -33,10 +33,7 @@ internal class SocketIoFacade
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 @@ internal class SocketIoFacade
{
lock (_lockObj)
{
_socket.On(eventName, _ =>
{
Task.Run(action);
});
_socket.On(eventName, _ => { Task.Run(action); });
}
}
@@ -107,10 +101,10 @@ internal class SocketIoFacade
lock (_lockObj)
{
_socket.On(eventName, (socketIoResponse) =>
{
_socket.Off(eventName);
Task.Run(() => action(socketIoResponse.GetValue<T>()));
});
{
_socket.Off(eventName);
Task.Run(() => action(socketIoResponse.GetValue<T>()));
});
}
}

View File

@@ -14,15 +14,16 @@ internal static class ApiEventManager
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<T>(string eventName, object id, Action<T> callback, Action<T> value, Func<object, T> converter, string suffix = "")
{
if (callback == null)
@@ -34,9 +35,10 @@ internal static class ApiEventManager
});
BridgeConnector.Socket.Emit($"register-{eventName}{suffix}", id);
}
callback += value;
}
internal static void AddEvent<T>(string eventName, object id, Action<T> callback, Action<T> value)
{
if (callback == null)
@@ -44,15 +46,16 @@ internal static class ApiEventManager
BridgeConnector.Socket.On<T>(eventName + id, (args) => callback(args));
BridgeConnector.Socket.Emit($"register-{eventName}", id);
}
callback += value;
}
internal static void RemoveEvent<T>(string eventName, object id, Action<T> callback, Action<T> value)
{
callback -= value;
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
}
internal static void AddTrayEvent(string eventName, object id, Action<TrayClickEventArgs, Rectangle> callback, Action<TrayClickEventArgs, Rectangle> value)
{
if (callback == null)
@@ -74,7 +77,7 @@ internal static class ApiEventManager
callback -= value;
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
}
internal static void AddScreenEvent(string eventName, object id, Action<Display, string[]> callback, Action<Display, string[]> value)
{
if (callback == null)
@@ -89,11 +92,10 @@ internal static class ApiEventManager
callback += value;
}
}
internal static void RemoveScreenEvent(string eventName, object id, Action<Display, string[]> callback, Action<Display, string[]> value)
{
callback -= value;
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
}
}

View File

@@ -20,7 +20,6 @@
protected override Task StartCore()
{
return Task.CompletedTask;
}
@@ -28,6 +27,5 @@
{
return Task.CompletedTask;
}
}
}
}

View File

@@ -68,7 +68,6 @@
private void SocketBridge_Ready(object sender, EventArgs e)
{
this.TransitionState(LifetimeState.Ready);
}
private void SocketBridge_Stopped(object sender, EventArgs e)
@@ -102,6 +101,5 @@
this.electronProcess.Stop();
return Task.CompletedTask;
}
}
}
}

View File

@@ -103,6 +103,5 @@
this.socketBridge.Stop();
return Task.CompletedTask;
}
}
}
}

View File

@@ -14,7 +14,9 @@
private LifetimeState state = LifetimeState.Uninitialized;
protected LifetimeServiceBase() { }
protected LifetimeServiceBase()
{
}
public event EventHandler Starting;
@@ -132,4 +134,4 @@
}
}
}
}
}

View File

@@ -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 @@
this.TransitionState(LifetimeState.Ready);
}
}
}
}

View File

@@ -103,7 +103,7 @@
{
ElectronNetRuntime.ElectronProcessId = result;
Console.WriteLine("Electron Process ID: " + result);
Console.WriteLine("Electron Process ID: " + result);
}
}
}
@@ -122,7 +122,6 @@
}
ElectronNetRuntime.ElectronExecutable = executable;
}
private BuildInfo GatherBuildInfo()
@@ -166,4 +165,4 @@
return buildInfo;
}
}
}
}

View File

@@ -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 @@
return Task.CompletedTask;
}
}
}
}