mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 05:34:48 +00:00
fix: simplified add/remove of socket listener through usage of "Once"
This commit is contained in:
@@ -62,7 +62,7 @@ namespace ElectronNET.API
|
||||
isActionDefined = true;
|
||||
|
||||
BridgeConnector.Socket.Off("NotificationEventShow");
|
||||
BridgeConnector.Socket.On<string>("NotificationEventShow", (id) => { _notificationOptions.Single(x => x.ShowID == id).OnShow(); });
|
||||
BridgeConnector.Socket.Once<string>("NotificationEventShow", (id) => { _notificationOptions.Single(x => x.ShowID == id).OnShow(); });
|
||||
}
|
||||
|
||||
if (notificationOptions.OnClick != null)
|
||||
@@ -119,17 +119,12 @@ namespace ElectronNET.API
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsSupportedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On<bool>("notificationIsSupportedComplete", (isSupported) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("notificationIsSupportedComplete");
|
||||
taskCompletionSource.SetResult(isSupported);
|
||||
});
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.Once<bool>("notificationIsSupportedComplete", tcs.SetResult);
|
||||
BridgeConnector.Socket.Emit("notificationIsSupported");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user