fix: simplified add/remove of socket listener through usage of "Once"

This commit is contained in:
Denny09310
2025-11-10 10:40:51 +01:00
parent d8062aae00
commit adc1e81743
23 changed files with 310 additions and 750 deletions

View File

@@ -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;
}