mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-04 05:34:51 +00:00
ApiBase: fix event names for App
This commit is contained in:
@@ -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) =>
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user