-
-
Notifications
You must be signed in to change notification settings - Fork 745
Expand file tree
/
Copy pathWebRequest.cs
More file actions
62 lines (51 loc) · 2.06 KB
/
WebRequest.cs
File metadata and controls
62 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using ElectronNET.API.Serialization;
using System;
using System.Text.Json;
namespace ElectronNET.API.Entities
{
public class OnBeforeRequestDetails
{
public int Id { get; set; }
public string Url { get; set; }
public string Method { get; set; }
public int? WebContentsId { get; set; }
// Ensure all necessary properties are included as per Electron documentation
}
public class WebRequestFilter
{
public string[] Urls { get; set; }
}
public class WebRequest
{
public int Id { get; private set; }
internal WebRequest(int id)
{
Id = id;
}
private event Action<OnBeforeRequestDetails, Action<object>> _onBeforeRequest;
public void OnBeforeRequest(WebRequestFilter filter, Action<OnBeforeRequestDetails, Action<object>> listener)
{
if (_onBeforeRequest == null)
{
BridgeConnector.Socket.On<JsonElement>($"webContents-session-webRequest-onBeforeRequest{Id}",
(args) =>
{
//// var details0 = args[0].Deserialize<OnBeforeRequestDetails>(ElectronNET.ElectronJson.Options);
var details = args.Deserialize<OnBeforeRequestDetails>(ElectronJson.Options);
var callback = (Action<object>)((response) => { BridgeConnector.Socket.Emit($"webContents-session-webRequest-onBeforeRequest-response{Id}", response); });
_onBeforeRequest?.Invoke(details, callback);
});
BridgeConnector.Socket.Emit("register-webContents-session-webRequest-onBeforeRequest", Id, filter);
}
_onBeforeRequest += listener;
}
public void RemoveListener(Action<OnBeforeRequestDetails, Action<object>> listener)
{
_onBeforeRequest -= listener;
if (_onBeforeRequest == null)
{
BridgeConnector.Socket.Off($"webContents-session-webRequest-onBeforeRequest{Id}");
}
}
}
}