Skip to content

Commit 464eaca

Browse files
committed
Merge branch 'main' of https://github.com/ElectronNET/Electron.NET into develop
2 parents eabcc3a + df3bd12 commit 464eaca

File tree

11 files changed

+422
-21
lines changed

11 files changed

+422
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ using ElectronNET.API.Entities;
5353
var builder = WebApplication.CreateBuilder(args);
5454
builder.WebHost.UseElectron(args);
5555

56-
// Is optional, but you can use the Electron.NET API-Classes directly with DI (relevant if you wont more encoupled code)
56+
// Is optional, but you can use the Electron.NET API-Classes directly with DI (relevant if you want more encoupled code)
5757
builder.Services.AddElectron();
5858

5959
var app = builder.Build();

src/ElectronNET.API/Entities/Display.cs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,54 @@
55
/// </summary>
66
public class Display
77
{
8+
/// <summary>
9+
/// Can be available, unavailable, unknown.
10+
/// </summary>
11+
public string AccelerometerSupport { get; set; }
12+
813
/// <summary>
914
/// Gets or sets the bounds.
1015
/// </summary>
1116
/// <value>
12-
/// The bounds.
17+
/// The bounds of the display in DIP points.
1318
/// </value>
1419
public Rectangle Bounds { get; set; }
1520

21+
/// <summary>
22+
/// The number of bits per pixel.
23+
/// </summary>
24+
public int ColorDepth { get; set; }
25+
26+
/// <summary>
27+
/// Represent a color space (three-dimensional object which contains all realizable color combinations) for the purpose of color conversions.
28+
/// </summary>
29+
public string ColorSpace { get; set; }
30+
31+
/// <summary>
32+
/// The number of bits per color component.
33+
/// </summary>
34+
public int DepthPerComponent { get; set; }
35+
36+
/// <summary>
37+
/// The display refresh rate.
38+
/// </summary>
39+
public int DisplayFrequency { get; set; }
40+
1641
/// <summary>
1742
/// Unique identifier associated with the display.
1843
/// </summary>
1944
public string Id { get; set; }
2045

46+
/// <summary>
47+
/// true for an internal display and false for an external display.
48+
/// </summary>
49+
public bool Internal { get; set; }
50+
51+
/// <summary>
52+
/// User-friendly label, determined by the platform.
53+
/// </summary>
54+
public string Label { get; set; }
55+
2156
/// <summary>
2257
/// Can be 0, 90, 180, 270, represents screen rotation in clock-wise degrees.
2358
/// </summary>
@@ -28,6 +63,16 @@ public class Display
2863
/// </summary>
2964
public int ScaleFactor { get; set; }
3065

66+
/// <summary>
67+
/// Can be available, unavailable, unknown.
68+
/// </summary>
69+
public string TouchSupport { get; set; }
70+
71+
/// <summary>
72+
/// Whether or not the display is a monochrome display.
73+
/// </summary>
74+
public bool Monochrome { get; set; }
75+
3176
/// <summary>
3277
/// Gets or sets the size.
3378
/// </summary>
@@ -36,11 +81,6 @@ public class Display
3681
/// </value>
3782
public Size Size { get; set; }
3883

39-
/// <summary>
40-
/// Can be available, unavailable, unknown.
41-
/// </summary>
42-
public string TouchSupport { get; set; }
43-
4484
/// <summary>
4585
/// Gets or sets the work area.
4686
/// </summary>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace ElectronNET.API.Entities;
2+
3+
/// <summary>
4+
/// 'OnDidFailLoad' event details.
5+
/// </summary>
6+
public class OnDidFailLoadInfo
7+
{
8+
/// <summary>
9+
/// The full list of error codes and their meaning is available here
10+
/// https://source.chromium.org/chromium/chromium/src/+/main:net/base/net_error_list.h
11+
/// </summary>
12+
public int ErrorCode { get; set; }
13+
14+
/// <summary>
15+
/// Validated URL.
16+
/// </summary>
17+
public string ValidatedUrl { get; set; }
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace ElectronNET.API.Entities;
2+
3+
/// <summary>
4+
/// 'OnDidNavigate' event details.
5+
/// </summary>
6+
public class OnDidNavigateInfo
7+
{
8+
/// <summary>
9+
/// Navigated URL.
10+
/// </summary>
11+
public string Url { get; set; }
12+
13+
/// <summary>
14+
/// HTTP response code.
15+
/// </summary>
16+
public int HttpResponseCode { get; set; }
17+
}

src/ElectronNET.API/IpcMain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void OnSync(string channel, Func<object, object> listener)
117117
public void Once(string channel, Action<object> listener)
118118
{
119119
BridgeConnector.Socket.Emit("registerOnceIpcMainChannel", channel);
120-
BridgeConnector.Socket.On(channel, (args) =>
120+
BridgeConnector.Socket.Once<object>(channel, (args) =>
121121
{
122122
List<object> objectArray = FormatArguments(args);
123123

src/ElectronNET.API/WebContents.cs

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,154 @@ public event Action OnDidFinishLoad
8484

8585
private event Action _didFinishLoad;
8686

87+
/// <summary>
88+
/// Emitted when any frame (including main) starts navigating.
89+
/// </summary>
90+
public event Action<string> OnDidStartNavigation
91+
{
92+
add
93+
{
94+
if (_didStartNavigation == null)
95+
{
96+
BridgeConnector.Socket.On<string>("webContents-didStartNavigation" + Id, (url) =>
97+
{
98+
_didStartNavigation(url);
99+
});
100+
101+
BridgeConnector.Socket.Emit("register-webContents-didStartNavigation", Id);
102+
}
103+
_didStartNavigation += value;
104+
}
105+
remove
106+
{
107+
_didStartNavigation -= value;
108+
109+
if (_didStartNavigation == null)
110+
BridgeConnector.Socket.Off("webContents-didStartNavigation" + Id);
111+
}
112+
}
113+
114+
private event Action<string> _didStartNavigation;
115+
116+
/// <summary>
117+
/// Emitted when a main frame navigation is done.
118+
/// This event is not emitted for in-page navigations, such as clicking anchor links or updating the window.location.hash. Use did-navigate-in-page event for this purpose.
119+
/// </summary>
120+
public event Action<OnDidNavigateInfo> OnDidNavigate
121+
{
122+
add
123+
{
124+
if (_didNavigate == null)
125+
{
126+
BridgeConnector.Socket.On<OnDidNavigateInfo>("webContents-didNavigate" + Id, (data) =>
127+
{
128+
_didNavigate(data);
129+
});
130+
131+
BridgeConnector.Socket.Emit("register-webContents-didNavigate", Id);
132+
}
133+
_didNavigate += value;
134+
}
135+
remove
136+
{
137+
_didNavigate -= value;
138+
139+
if (_didNavigate == null)
140+
BridgeConnector.Socket.Off("webContents-didNavigate" + Id);
141+
}
142+
}
143+
144+
private event Action<OnDidNavigateInfo> _didNavigate;
145+
146+
/// <summary>
147+
/// Emitted when a server side redirect occurs during navigation. For example a 302 redirect.
148+
/// This event will be emitted after OnDidStartNavigation and always before the OnDidRedirectNavigation event for the same navigation.
149+
/// </summary>
150+
public event Action<string> OnWillRedirect
151+
{
152+
add
153+
{
154+
if (_willRedirect == null)
155+
{
156+
BridgeConnector.Socket.On<string>("webContents-willRedirect" + Id, (url) =>
157+
{
158+
_willRedirect(url);
159+
});
160+
161+
BridgeConnector.Socket.Emit("register-webContents-willRedirect", Id);
162+
}
163+
_willRedirect += value;
164+
}
165+
remove
166+
{
167+
_willRedirect -= value;
168+
169+
if (_willRedirect == null)
170+
BridgeConnector.Socket.Off("webContents-willRedirect" + Id);
171+
}
172+
}
173+
174+
private event Action<string> _willRedirect;
175+
176+
/// <summary>
177+
/// Emitted after a server side redirect occurs during navigation. For example a 302 redirect.
178+
/// </summary>
179+
public event Action<string> OnDidRedirectNavigation
180+
{
181+
add
182+
{
183+
if (_didRedirectNavigation == null)
184+
{
185+
BridgeConnector.Socket.On("webContents-didRedirectNavigation" + Id, (url) =>
186+
{
187+
_didRedirectNavigation(url?.ToString());
188+
});
189+
190+
BridgeConnector.Socket.Emit("register-webContents-didRedirectNavigation", Id);
191+
}
192+
_didRedirectNavigation += value;
193+
}
194+
remove
195+
{
196+
_didRedirectNavigation -= value;
197+
198+
if (_didRedirectNavigation == null)
199+
BridgeConnector.Socket.Off("webContents-didRedirectNavigation" + Id);
200+
}
201+
}
202+
203+
private event Action<string> _didRedirectNavigation;
204+
205+
206+
/// <summary>
207+
/// This event is like OnDidFinishLoad but emitted when the load failed.
208+
/// </summary>
209+
public event Action<OnDidFailLoadInfo> OnDidFailLoad
210+
{
211+
add
212+
{
213+
if (_didFailLoad == null)
214+
{
215+
BridgeConnector.Socket.On("webContents-willRedirect" + Id, (data) =>
216+
{
217+
_didFailLoad(((JObject) data).ToObject<OnDidFailLoadInfo>());
218+
});
219+
220+
BridgeConnector.Socket.Emit("register-webContents-willRedirect", Id);
221+
}
222+
_didFailLoad += value;
223+
}
224+
remove
225+
{
226+
_didFailLoad -= value;
227+
228+
if (_didFailLoad == null)
229+
BridgeConnector.Socket.Off("webContents-willRedirect" + Id);
230+
}
231+
}
232+
233+
private event Action<OnDidFailLoadInfo> _didFailLoad;
234+
87235
/// <summary>
88236
/// Emitted when an input event is sent to the WebContents.
89237
/// </summary>
@@ -114,6 +262,35 @@ public event Action<InputEvent> InputEvent
114262

115263
private event Action<InputEvent> _inputEvent;
116264

265+
/// <summary>
266+
/// Emitted when the document in the top-level frame is loaded.
267+
/// </summary>
268+
public event Action OnDomReady
269+
{
270+
add
271+
{
272+
if (_domReady == null)
273+
{
274+
BridgeConnector.Socket.On("webContents-domReady" + Id, () =>
275+
{
276+
_domReady();
277+
});
278+
279+
BridgeConnector.Socket.Emit("register-webContents-domReady", Id);
280+
}
281+
_domReady += value;
282+
}
283+
remove
284+
{
285+
_domReady -= value;
286+
287+
if (_domReady == null)
288+
BridgeConnector.Socket.Off("webContents-domReady" + Id);
289+
}
290+
}
291+
292+
private event Action _domReady;
293+
117294
internal WebContents(int id)
118295
{
119296
Id = id;
@@ -215,6 +392,37 @@ public Task<bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null)
215392
return taskCompletionSource.Task;
216393
}
217394

395+
/// <summary>
396+
/// Evaluates script code in page.
397+
/// </summary>
398+
/// <param name="code">The code to execute.</param>
399+
/// <param name="userGesture">if set to <c>true</c> simulate a user gesture.</param>
400+
/// <returns>The result of the executed code.</returns>
401+
/// <remarks>
402+
/// <para>
403+
/// In the browser window some HTML APIs like `requestFullScreen` can only be
404+
/// invoked by a gesture from the user. Setting `userGesture` to `true` will remove
405+
/// this limitation.
406+
/// </para>
407+
/// <para>
408+
/// Code execution will be suspended until web page stop loading.
409+
/// </para>
410+
/// </remarks>
411+
public Task<object> ExecuteJavaScriptAsync(string code, bool userGesture = false)
412+
{
413+
var taskCompletionSource = new TaskCompletionSource<object>();
414+
415+
BridgeConnector.Socket.On("webContents-executeJavaScript-completed", (result) =>
416+
{
417+
BridgeConnector.Socket.Off("webContents-executeJavaScript-completed");
418+
taskCompletionSource.SetResult(result);
419+
});
420+
421+
BridgeConnector.Socket.Emit("webContents-executeJavaScript", Id, code, userGesture);
422+
423+
return taskCompletionSource.Task;
424+
}
425+
218426
/// <summary>
219427
/// Is used to get the Url of the loaded page.
220428
/// It's usefull if a web-server redirects you and you need to know where it redirects. For instance, It's useful in case of Implicit Authorization.

src/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
4848
}
4949
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
5050
{
51-
netCorePublishRid = "osx-x64";
51+
netCorePublishRid = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? "osx-arm64" : "osx-x64";
5252
electronPackerPlatform = "mac";
5353
}
5454
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))

0 commit comments

Comments
 (0)