Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions src/ElectronNET.API/API/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public event Action WindowAllClosed

BridgeConnector.Socket.Emit("register-app-window-all-closed", GetHashCode());
}

_windowAllClosed += value;
}
remove
{
_windowAllClosed -= value;

if(_windowAllClosed == null)
if (_windowAllClosed == null)
BridgeConnector.Socket.Off("app-window-all-closed" + GetHashCode());
}
}
Expand Down Expand Up @@ -117,6 +118,7 @@ public event Func<QuitEventArgs, Task> BeforeQuit

BridgeConnector.Socket.Emit("register-app-before-quit", GetHashCode());
}

_beforeQuit += value;
}
remove
Expand Down Expand Up @@ -168,6 +170,7 @@ public event Func<QuitEventArgs, Task> WillQuit

BridgeConnector.Socket.Emit("register-app-will-quit", GetHashCode());
}

_willQuit += value;
}
remove
Expand All @@ -194,7 +197,7 @@ public event Func<Task> Quitting
{
BridgeConnector.Socket.On("app-will-quit" + GetHashCode() + "quitting", async () =>
{
if(_willQuit == null)
if (_willQuit == null)
{
await this._quitting().ConfigureAwait(false);
Exit();
Expand All @@ -203,6 +206,7 @@ public event Func<Task> Quitting

BridgeConnector.Socket.Emit("register-app-will-quit", GetHashCode() + "quitting");
}

_quitting += value;
}
remove
Expand Down Expand Up @@ -276,11 +280,11 @@ public event Action<bool> AccessibilitySupportChanged
/// <summary>
/// Emitted when the application has finished basic startup.
/// </summary>
public event Action Ready
public event Action Ready
{
add
{
if(IsReady)
if (IsReady)
{
value();
}
Expand All @@ -298,19 +302,23 @@ public event Action Ready
/// <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>
Expand Down Expand Up @@ -379,7 +387,7 @@ public Task<string> NameAsync
}


internal App()
internal App()
{
CommandLine = new CommandLine();
}
Expand All @@ -392,7 +400,7 @@ internal static App Instance
{
lock (_syncRoot)
{
if(_app == null)
if (_app == null)
{
_app = new App();
}
Expand Down Expand Up @@ -541,7 +549,7 @@ public async Task<string> GetPathAsync(PathName pathName, CancellationToken canc
cancellationToken.ThrowIfCancellationRequested();

var taskCompletionSource = new TaskCompletionSource<string>();
using(cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
{
BridgeConnector.Socket.On("appGetPathCompleted", (path) =>
{
Expand All @@ -554,7 +562,7 @@ public async Task<string> GetPathAsync(PathName pathName, CancellationToken canc

return await taskCompletionSource.Task
.ConfigureAwait(false);
}
}
}

/// <summary>
Expand Down Expand Up @@ -715,7 +723,7 @@ public async Task<bool> SetAsDefaultProtocolClientAsync(string protocol, string
BridgeConnector.Socket.On("appSetAsDefaultProtocolClientCompleted", (success) =>
{
BridgeConnector.Socket.Off("appSetAsDefaultProtocolClientCompleted");
taskCompletionSource.SetResult((bool) success);
taskCompletionSource.SetResult((bool)success);
});

BridgeConnector.Socket.Emit("appSetAsDefaultProtocolClient", protocol, path, args);
Expand Down Expand Up @@ -760,7 +768,7 @@ public async Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, stri
/// <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>();
Expand All @@ -769,7 +777,7 @@ public async Task<bool> RemoveAsDefaultProtocolClientAsync(string protocol, stri
BridgeConnector.Socket.On("appRemoveAsDefaultProtocolClientCompleted", (success) =>
{
BridgeConnector.Socket.Off("appRemoveAsDefaultProtocolClientCompleted");
taskCompletionSource.SetResult((bool) success);
taskCompletionSource.SetResult((bool)success);
});

BridgeConnector.Socket.Emit("appRemoveAsDefaultProtocolClient", protocol, path, args);
Expand Down Expand Up @@ -841,7 +849,7 @@ public async Task<bool> IsDefaultProtocolClientAsync(string protocol, string pat
BridgeConnector.Socket.On("appIsDefaultProtocolClientCompleted", (success) =>
{
BridgeConnector.Socket.Off("appIsDefaultProtocolClientCompleted");
taskCompletionSource.SetResult((bool) success);
taskCompletionSource.SetResult((bool)success);
});

BridgeConnector.Socket.Emit("appIsDefaultProtocolClient", protocol, path, args);
Expand Down Expand Up @@ -869,7 +877,7 @@ public async Task<bool> SetUserTasksAsync(UserTask[] userTasks, CancellationToke
BridgeConnector.Socket.On("appSetUserTasksCompleted", (success) =>
{
BridgeConnector.Socket.Off("appSetUserTasksCompleted");
taskCompletionSource.SetResult((bool) success);
taskCompletionSource.SetResult((bool)success);
});

BridgeConnector.Socket.Emit("appSetUserTasks", JArray.FromObject(userTasks, _jsonSerializer));
Expand Down Expand Up @@ -1066,7 +1074,7 @@ public async Task<int> ImportCertificateAsync(ImportCertificateOptions options,
BridgeConnector.Socket.On("appImportCertificateCompleted", (result) =>
{
BridgeConnector.Socket.Off("appImportCertificateCompleted");
taskCompletionSource.SetResult((int) result);
taskCompletionSource.SetResult((int)result);
});

BridgeConnector.Socket.Emit("appImportCertificate", JObject.FromObject(options, _jsonSerializer));
Expand Down Expand Up @@ -1122,7 +1130,7 @@ public async Task<bool> SetBadgeCountAsync(int count, CancellationToken cancella
BridgeConnector.Socket.On("appSetBadgeCountCompleted", (success) =>
{
BridgeConnector.Socket.Off("appSetBadgeCountCompleted");
taskCompletionSource.SetResult((bool) success);
taskCompletionSource.SetResult((bool)success);
});

BridgeConnector.Socket.Emit("appSetBadgeCount", count);
Expand Down Expand Up @@ -1183,7 +1191,7 @@ public async Task<LoginItemSettings> GetLoginItemSettingsAsync(LoginItemSettings
{
BridgeConnector.Socket.Off("appGetLoginItemSettingsCompleted");

var result = ((JObject) loginItemSettings).ToObject<LoginItemSettings>();
var result = ((JObject)loginItemSettings).ToObject<LoginItemSettings>();

taskCompletionSource.SetResult(result);
});
Expand Down Expand Up @@ -1310,27 +1318,31 @@ internal void PreventQuit()
private bool _preventQuit = false;

private const string ModuleName = "app";

/// <summary>
/// Subscribe to an unmapped event on the <see cref="App"/> module.
/// </summary>
/// <param name="eventName">The event name</param>
/// <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>
/// <param name="eventName">The event name</param>
/// <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>
/// <param name="eventName">The event name</param>
/// <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>
Expand All @@ -1339,4 +1351,4 @@ public void Once(string eventName, Action action)
public async Task Once(string eventName, Action<object> action)
=> await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false);
}
}
}
8 changes: 5 additions & 3 deletions src/ElectronNET.API/API/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using ElectronNET.Common;

// ReSharper disable InconsistentNaming

namespace ElectronNET.API
Expand Down Expand Up @@ -249,7 +250,6 @@ public Task<string> ChannelAsync
}



/// <summary>
/// The request headers.
/// </summary>
Expand Down Expand Up @@ -353,7 +353,9 @@ public event Action<UpdateInfo> OnUpdateDownloaded
private static AutoUpdater _autoUpdater;
private static object _syncRoot = new object();

internal AutoUpdater() { }
internal AutoUpdater()
{
}

internal static AutoUpdater Instance
{
Expand Down Expand Up @@ -512,4 +514,4 @@ public Task<string> GetFeedURLAsync()
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
}
}
}
4 changes: 2 additions & 2 deletions src/ElectronNET.API/API/BrowserView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Rectangle Bounds
/// <summary>
/// BrowserView
/// </summary>
internal BrowserView(int id)
internal BrowserView(int id)
{
Id = id;

Expand Down Expand Up @@ -94,4 +94,4 @@ public void SetBackgroundColor(string color)
NullValueHandling = NullValueHandling.Ignore
};
}
}
}
25 changes: 21 additions & 4 deletions src/ElectronNET.API/API/BrowserWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ElectronNET.Common;

// ReSharper disable InconsistentNaming

namespace ElectronNET.API;
Expand Down Expand Up @@ -96,8 +97,8 @@ public event Action OnSessionEnd
/// </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;
Expand Down Expand Up @@ -752,6 +753,7 @@ public void SetPosition(int x, int y)
{
x = x - 7;
}

this.CallMethod2(x, y);
}

Expand All @@ -769,6 +771,7 @@ public void SetPosition(int x, int y, bool animate)
{
x = x - 7;
}

this.CallMethod3(x, y, animate);
}

Expand Down Expand Up @@ -906,7 +909,14 @@ private bool isWindows10()
/// <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>
Expand Down Expand Up @@ -981,7 +991,14 @@ public void SetProgressBar(double progress, ProgressBarOptions progressBarOption
/// <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>
Expand Down
9 changes: 5 additions & 4 deletions src/ElectronNET.API/API/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public sealed class Clipboard
private static Clipboard _clipboard;
private static object _syncRoot = new object();

internal Clipboard() { }
internal Clipboard()
{
}

internal static Clipboard Instance
{
Expand Down Expand Up @@ -253,14 +255,13 @@ public Task<NativeImage> ReadImageAsync(string type = "")
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>
Expand Down
Loading
Loading