Skip to content

Commit d17e113

Browse files
committed
ApiBase: fix event names for App
1 parent 36c5d49 commit d17e113

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/ElectronNET.API/API/ApiBase.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
public abstract class ApiBase
1111
{
12+
protected enum SocketEventNameTypes
13+
{
14+
DashesLowerFirst,
15+
NoDashUpperFirst,
16+
}
17+
1218
internal const int PropertyTimeout = 1000;
1319

1420
private readonly string objectName;
@@ -31,7 +37,7 @@ protected set
3137
}
3238
}
3339

34-
protected abstract string SocketEventCompleteSuffix { get; }
40+
protected abstract SocketEventNameTypes SocketEventNameType { get; }
3541

3642
protected ApiBase()
3743
{
@@ -128,7 +134,20 @@ public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs)
128134
this.tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
129135
this.tcsTask = this.tcs.Task;
130136

131-
var eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}{apiBase.SocketEventCompleteSuffix}");
137+
string eventName;
138+
139+
switch (apiBase.SocketEventNameType)
140+
{
141+
case SocketEventNameTypes.DashesLowerFirst:
142+
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}-completed");
143+
break;
144+
case SocketEventNameTypes.NoDashUpperFirst:
145+
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}{s.StripAsync()}Completed");
146+
break;
147+
default:
148+
throw new ArgumentOutOfRangeException();
149+
}
150+
132151
var messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => apiBase.objectName + s.StripAsync());
133152

134153
BridgeConnector.Socket.On<T>(eventName, (result) =>

src/ElectronNET.API/API/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace ElectronNET.API
1818
/// </summary>
1919
public sealed class App : ApiBase
2020
{
21-
protected override string SocketEventCompleteSuffix => "Completed";
21+
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.NoDashUpperFirst;
2222

2323
/// <summary>
2424
/// Emitted when all windows have been closed.

src/ElectronNET.API/API/BrowserWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace ElectronNET.API;
2323
/// </summary>
2424
public class BrowserWindow : ApiBase
2525
{
26-
protected override string SocketEventCompleteSuffix => "-completed";
26+
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashesLowerFirst;
2727

2828
/// <summary>
2929
/// Gets the identifier.

0 commit comments

Comments
 (0)