Skip to content

Commit 1ecd063

Browse files
committed
fix: Response1 naming, Handle is a callback it should not return a task
1 parent 09f2966 commit 1ecd063

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

src/ElectronNET.API/API/Protocol.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,34 @@ public Task RegisterSchemesAsPrivilegedAsync(params CustomScheme[] customSchemes
5656
/// </summary>
5757
/// <param name="scheme">scheme to handle, for example https or my-app. This is the bit before the : in a URL.</param>
5858
/// <param name="handler">Either a <see cref="Response" /> or a <see cref="Task{Response}"/> can be returned.</param>
59-
public Task HandleAsync(string scheme, Func<Request, Response> handler)
59+
public void Handle(string scheme, Func<Request, Response> handler)
6060
{
6161
if (string.IsNullOrWhiteSpace(scheme))
6262
throw new ArgumentException("Scheme must not be null or empty.", nameof(scheme));
6363

64-
return handler switch
65-
{
66-
null => throw new ArgumentNullException(nameof(handler)),
67-
_ => HandleAsync(scheme, req => Task.FromResult(handler(req)))
68-
};
64+
if (handler == null)
65+
throw new ArgumentNullException(nameof(handler));
66+
67+
Handle(scheme, req => Task.FromResult(handler(req)));
6968
}
7069

71-
public Task HandleAsync(string scheme, Func<Request, Task<Response>> handler)
70+
public void Handle(string scheme, Func<Request, Task<Response>> handler)
7271
{
7372
if (string.IsNullOrWhiteSpace(scheme))
7473
throw new ArgumentException("Scheme must not be null or empty.", nameof(scheme));
7574

7675
if (handler == null)
7776
throw new ArgumentNullException(nameof(handler));
7877

78+
var tsc = new TaskCompletionSource();
79+
7980
// Tell TS to register protocol.handle for this scheme.
8081
BridgeConnector.Socket.Emit("protocol-handle-register", new
8182
{
8283
scheme
8384
});
8485

8586
// Listen for incoming requests from TS
86-
// Note: If your BridgeConnector has generic On<T>, use that instead of object.
8787
BridgeConnector.Socket.On<Request>("protocol-handle-request", async (request) =>
8888
{
8989
try
@@ -133,9 +133,6 @@ public Task HandleAsync(string scheme, Func<Request, Task<Response>> handler)
133133
});
134134
}
135135
});
136-
137-
// There’s nothing async to wait for here: registration happens on JS side.
138-
return Task.CompletedTask;
139136
}
140137
}
141138

src/ElectronNET.Host/api/protocol.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { randomUUID } from "crypto"; // Node 14+; or a simple counter
44

55
let electronSocket: Socket;
66

7-
type Reques1 = {
7+
type Request1 = {
88
id: string;
99
scheme: string;
1010
url: string;
@@ -36,7 +36,7 @@ export = (socket: Socket) => {
3636
};
3737

3838
async function handle(scheme: string, request: Request): Promise<Response> {
39-
const id = randomUUID(); // or your own monotonically increasing counter
39+
const id = randomUUID();
4040

4141
const headers: Record<string, string[]> = {};
4242
for (const [value, key] of request.headers) {
@@ -49,7 +49,7 @@ async function handle(scheme: string, request: Request): Promise<Response> {
4949
body = buffer.toString("base64");
5050
}
5151

52-
const dto: Reques1 = {
52+
const dto: Request1 = {
5353
id,
5454
scheme,
5555
url: request.url,

0 commit comments

Comments
 (0)