ApiBase: fix event names for App

This commit is contained in:
softworkz
2025-11-09 02:28:39 +01:00
parent 402147b8ef
commit 95fd7aa665
3 changed files with 23 additions and 4 deletions

View File

@@ -9,6 +9,12 @@
public abstract class ApiBase
{
protected enum SocketEventNameTypes
{
DashesLowerFirst,
NoDashUpperFirst,
}
internal const int PropertyTimeout = 1000;
private readonly string objectName;
@@ -31,7 +37,7 @@
}
}
protected abstract string SocketEventCompleteSuffix { get; }
protected abstract SocketEventNameTypes SocketEventNameType { get; }
protected ApiBase()
{
@@ -128,7 +134,20 @@
this.tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
this.tcsTask = this.tcs.Task;
var eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}{apiBase.SocketEventCompleteSuffix}");
string eventName;
switch (apiBase.SocketEventNameType)
{
case SocketEventNameTypes.DashesLowerFirst:
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}-completed");
break;
case SocketEventNameTypes.NoDashUpperFirst:
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}{s.StripAsync()}Completed");
break;
default:
throw new ArgumentOutOfRangeException();
}
var messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => apiBase.objectName + s.StripAsync());
BridgeConnector.Socket.On<T>(eventName, (result) =>

View File

@@ -18,7 +18,7 @@ namespace ElectronNET.API
/// </summary>
public sealed class App : ApiBase
{
protected override string SocketEventCompleteSuffix => "Completed";
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.NoDashUpperFirst;
/// <summary>
/// Emitted when all windows have been closed.

View File

@@ -24,7 +24,7 @@ using ElectronNET.Common;
/// </summary>
public class BrowserWindow : ApiBase
{
protected override string SocketEventCompleteSuffix => "-completed";
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashesLowerFirst;
/// <summary>
/// Gets the identifier.