Skip to content

Commit 87cc6f9

Browse files
authored
Merge pull request #1109 from ElectronNET/develop
Release 0.6.0
2 parents dcf4585 + a0c0523 commit 87cc6f9

83 files changed

Lines changed: 2590 additions & 214 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Changelog.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
# 0.6.0
2+
3+
## ElectronNET.Core
4+
5+
- Updated dependencies
6+
- Updated `WebContents` zoom level APIs to use `double` instead of `int` (#956)
7+
- Improved migration checks to honor custom output paths and to detect `ProjectGuid` in publish profiles (#946)
8+
- Fixed single instance handling on macOS (#1040)
9+
- Fixed slow socket bridge startup by binding to an explicit loopback address (#1103)
10+
- Fixed socket bridge connection when a system proxy is configured (#1105)
11+
- Fixed electron-builder using the host RID instead of the target RID (#1097)
12+
- Fixed cross-compilation behavior on same platform (#1098) @epsnm
13+
- Fixed resolution of unrelated target (#1099) @epsnm
14+
- Fixed false alarm for `ELECTRON001` on a root `package-lock.json` (#946)
15+
- Added `ElectronNET.Core.Templates` package with a `dotnet new electron-blazor` template (#414)
16+
- Added `WebContents.OnZoomChanged` event (#956)
17+
- Added `WebContents` page loading APIs `LoadFileAsync`, `IsLoadingAsync`, `IsLoadingMainFrameAsync`, `IsWaitingForResponseAsync`, `Reload`, `ReloadIgnoringCache` and `Stop` (#956)
18+
- Added `WebContents.InsertCSSAsync` and `WebContents.RemoveInsertedCSSAsync` for dynamic CSS (#956)
19+
- Added `WebContents` editing and selection APIs (undo, redo, cut, copy, paste, insert text, select, ...) (#956)
20+
- Added `WebContents.FindInPageAsync`, `WebContents.StopFindInPage` and the `OnFoundInPage` event (#956)
21+
- Added `WebContents` audio events `OnAudioStateChanged`, `OnMediaStartedPlaying` and `OnMediaPaused` (#956)
22+
- Added `WebContents.ScrollToTop` and `WebContents.ScrollToBottom` (#956)
23+
- Added target framework customization (#1095) @epsnm
24+
- Added configurable Electron root directory for custom packaging layouts (#1106) @DYH1319
25+
- Added ability for `custom_main.js` to modify command line switches (#1029) @AeonSake
26+
- Added migration checks for incomplete `ElectronHostHook` folders (`ELECTRON010`, `ELECTRON011`) (#946)
27+
- Added `ElectronExecutableName` to separate the product name from the executable name (#1003) @AeonSake
28+
- Added build extensibility properties `ElectronSkipExecCommands` and `ElectronIntermediatePublishDir` (#1106) @DYH1319
29+
130
# 0.5.2
231

332
## ElectronNET.Core

‎Directory.Build.props‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@
55
<!-- Uncomment to include parent Directory.Build.props file -->
66
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />-->
77

8+
<PropertyGroup>
9+
<ElectronNetBuildProps>$([MSBuild]::GetPathOfFileAbove('ElectronNet.Build.props', '$(MSBuildThisFileDirectory)../'))</ElectronNetBuildProps>
10+
</PropertyGroup>
11+
12+
<!-- Only import specific project related MSBuild file -->
13+
<Import Project="$(ElectronNetBuildProps)" Condition=" '$(ElectronNetBuildProps)' != '' " />
14+
815
</Project>

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ While the classic Electron.NET setup (using an ASP.NET host run by the Electron
2323
* ElectronNET.Core: [![NuGet](https://img.shields.io/nuget/v/ElectronNET.Core.svg?style=flat-square)](https://www.nuget.org/packages/ElectronNET.Core.API/)
2424
* ElectronNET.Core.API: [![NuGet](https://img.shields.io/nuget/v/ElectronNET.Core.API.svg?style=flat-square)](https://www.nuget.org/packages/ElectronNET.Core.API/)
2525
* ElectronNET.Core.AspNet: [![NuGet](https://img.shields.io/nuget/v/ElectronNET.Core.AspNet.svg?style=flat-square)](https://www.nuget.org/packages/ElectronNET.Core.AspNet/)
26+
* ElectronNET.Core.Templates: [![NuGet](https://img.shields.io/nuget/v/ElectronNET.Core.Templates.svg?style=flat-square)](https://www.nuget.org/packages/ElectronNET.Core.Templates/)
2627

2728
## 🛠 Requirements to Run
2829

2930
You should have installed:
3031

31-
* .NET 6/8 or later.
32-
* The minimum base OS is the same as [.NET 6](https://github.com/dotnet/core/blob/main/release-notes/6.0/supported-os.md) / [.NET 8](https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md).
32+
* .NET 8/10 or later.
33+
* The minimum base OS is the same as [.NET 8](https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md) / [.NET 10](https://github.com/dotnet/core/blob/main/release-notes/10.0/supported-os.md).
3334
* Node.JS using at least [Version 22.x](https://nodejs.org).
3435

3536
## 👩‍🏫 Usage with ASP.NET
@@ -202,6 +203,8 @@ Alternatively, consider using a GitHub sponsorship for the core maintainers:
202203
- [Gregor Biswanger](https://github.com/sponsors/GregorBiswanger)
203204
- [Florian Rappl](https://github.com/sponsors/FlorianRappl)
204205

206+
Or just [buy Florian a coffee](https://buymeacoffee.com/florianrappl) :coffee:.
207+
205208
Any support appreciated! 🍻
206209

207210
## 🎉 License

‎docs/API/WebContents.md‎

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ Works for both BrowserWindows and BrowserViews.
5858
- `isBrowserWindow` - Whether the webContents belong to a BrowserWindow or not (the other option is a BrowserView)
5959
- `path` - Absolute path to the CSS file location
6060

61+
#### 🧊 `Task<string> InsertCSSAsync(string css, string cssOrigin = null)`
62+
Injects CSS into the current web page and returns a unique key for the inserted style sheet.
63+
64+
**Parameters:**
65+
- `css` - The style sheet to inject
66+
- `cssOrigin` - Can be either `user` or `author`, defaults to `author`
67+
68+
**Returns:**
69+
70+
The key of the inserted style sheet, to be used with `RemoveInsertedCSSAsync`.
71+
72+
#### 🧊 `Task RemoveInsertedCSSAsync(string key)`
73+
Removes a previously inserted style sheet from the current web page.
74+
75+
**Parameters:**
76+
- `key` - The key returned by `InsertCSSAsync`
77+
6178
#### 🧊 `Task LoadURLAsync(string url)`
6279
Loads the url in the window. The url must contain the protocol prefix.
6380

@@ -113,6 +130,106 @@ Prints window's web page as PDF with Chromium's preview printing custom settings
113130

114131
Whether the PDF generation succeeded.
115132

133+
#### 🧊 `Task<double> GetZoomFactorAsync()`
134+
Returns the current zoom factor. A factor of `1.0` means 100%.
135+
136+
#### 🧊 `void SetZoomFactor(double factor)`
137+
Changes the zoom factor to the specified factor. The zoom factor is the zoom percent divided by 100, so 300% = `3.0`. The factor must be greater than `0.0`.
138+
139+
**Parameters:**
140+
- `factor` - The zoom factor
141+
142+
#### 🧊 `Task<double> GetZoomLevelAsync()`
143+
Returns the current zoom level.
144+
145+
#### 🧊 `void SetZoomLevel(double level)`
146+
Changes the zoom level to the specified level. The original size is `0` and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of the original size, respectively.
147+
148+
**Parameters:**
149+
- `level` - The zoom level
150+
151+
#### 🧊 `Task SetVisualZoomLevelLimitsAsync(double minimumLevel, double maximumLevel)`
152+
Sets the maximum and minimum pinch-to-zoom level.
153+
154+
**Parameters:**
155+
- `minimumLevel` - The minimum pinch-to-zoom level
156+
- `maximumLevel` - The maximum pinch-to-zoom level
157+
158+
#### 🧊 `Task LoadFileAsync(string filePath, LoadFileOptions options = null)`
159+
Loads the given HTML file, relative to the root of the application.
160+
161+
**Parameters:**
162+
- `filePath` - Path to the HTML file
163+
- `options` - Optional `Query`, `Search` and `Hash` parts of the resulting URL
164+
165+
#### 🧊 `void SetAudioMuted(bool muted)`
166+
Mutes or unmutes the audio on the current web page.
167+
168+
#### 🧊 `Task<bool> IsAudioMutedAsync()`
169+
Whether this page has been muted.
170+
171+
#### 🧊 `Task<bool> IsCurrentlyAudibleAsync()`
172+
Whether audio is currently playing.
173+
174+
#### 🧊 `Task<string> GetUserAgentAsync()` / `void SetUserAgent(string userAgent)`
175+
Gets or overrides the user agent for this web page.
176+
177+
#### 🧊 `Task<bool> IsLoadingAsync()`
178+
Whether the web page is still loading resources.
179+
180+
#### 🧊 `Task<bool> IsLoadingMainFrameAsync()`
181+
Whether the main frame (and not just iframes or frames within it) is still loading.
182+
183+
#### 🧊 `Task<bool> IsWaitingForResponseAsync()`
184+
Whether the web page is waiting for a first response from the main resource of the page.
185+
186+
#### 🧊 `void Reload()`
187+
Reloads the current web page.
188+
189+
#### 🧊 `void ReloadIgnoringCache()`
190+
Reloads the current web page and ignores the cache.
191+
192+
#### 🧊 `void Stop()`
193+
Stops any pending navigation.
194+
195+
#### 🧊 `void Undo()` / `void Redo()`
196+
Executes the `undo` / `redo` editing command in the web page.
197+
198+
#### 🧊 `void Cut()` / `void Copy()` / `void Paste()` / `void PasteAndMatchStyle()` / `void Delete()`
199+
Executes the corresponding editing command in the web page.
200+
201+
#### 🧊 `void CopyImageAt(int x, int y)`
202+
Copies the image at the given position to the clipboard.
203+
204+
#### 🧊 `void SelectAll()` / `void Unselect()` / `void CenterSelection()`
205+
Selects all content, clears the selection, or scrolls to the current selection.
206+
207+
#### 🧊 `void ScrollToTop()` / `void ScrollToBottom()`
208+
Scrolls to the top or the bottom of the current web page.
209+
210+
#### 🧊 `void AdjustSelection(AdjustSelectionOptions options)`
211+
Adjusts the start and end points of the current text selection by the given amounts. Negative amounts move towards the beginning of the document.
212+
213+
#### 🧊 `Task InsertTextAsync(string text)`
214+
Inserts text into the focused element.
215+
216+
#### 🧊 `void Replace(string text)` / `void ReplaceMisspelling(string text)`
217+
Replaces the current selection, or the currently misspelled word, with the given text.
218+
219+
#### 🧊 `Task<int> FindInPageAsync(string text, FindInPageOptions options = null)`
220+
Starts a request to find all matches for the text in the web page. Results are reported via the `OnFoundInPage` event.
221+
222+
**Parameters:**
223+
- `text` - Content to be searched, must not be empty
224+
- `options` - Optional `Forward`, `FindNext` and `MatchCase` flags
225+
226+
**Returns:**
227+
228+
The request id of the find request.
229+
230+
#### 🧊 `void StopFindInPage(StopFindInPageAction action)`
231+
Stops any `FindInPageAsync` request with the given action (`ClearSelection`, `KeepSelection` or `ActivateSelection`).
232+
116233
## Events
117234

118235
#### ⚡ `InputEvent`
@@ -142,6 +259,21 @@ Emitted when the document in the top-level frame is loaded.
142259
#### ⚡ `OnWillRedirect`
143260
Emitted when a server side redirect occurs during navigation.
144261

262+
#### ⚡ `OnZoomChanged`
263+
Emitted when the user changes the zoom level using the mouse wheel or the keyboard. The handler receives the `ZoomDirection` (`In` or `Out`).
264+
265+
#### ⚡ `OnFoundInPage`
266+
Emitted when a result is available for a `FindInPageAsync` request. The handler receives a `FoundInPageResult`.
267+
268+
#### ⚡ `OnAudioStateChanged`
269+
Emitted when media becomes audible or inaudible. The handler receives `true` if one or more frames or child web contents are emitting audio.
270+
271+
#### ⚡ `OnMediaStartedPlaying`
272+
Emitted when media starts playing.
273+
274+
#### ⚡ `OnMediaPaused`
275+
Emitted when media is paused or done playing.
276+
145277
## Usage Examples
146278

147279
### Page Loading
@@ -279,6 +411,82 @@ webContents.OnCrashed += (killed) =>
279411
};
280412
```
281413

414+
### Zoom Control
415+
416+
```csharp
417+
// Set the zoom to 150%
418+
webContents.SetZoomFactor(1.5);
419+
420+
var factor = await webContents.GetZoomFactorAsync();
421+
Console.WriteLine($"Current zoom: {factor * 100}%");
422+
423+
// Zoom levels are relative: each step is 20% larger/smaller, 0 is the original size
424+
webContents.SetZoomLevel(2);
425+
426+
// Restrict pinch-to-zoom
427+
await webContents.SetVisualZoomLevelLimitsAsync(1, 3);
428+
429+
// React to zoom changes triggered by the user
430+
webContents.OnZoomChanged += (direction) =>
431+
{
432+
Console.WriteLine($"User zoomed {direction}");
433+
};
434+
```
435+
436+
> **Note:** The zoom factor is shared by all windows using the same session partition. Assign a unique `WebPreferences.Partition` per window if each window should keep its own zoom.
437+
438+
### Dynamic CSS
439+
440+
```csharp
441+
var key = await webContents.InsertCSSAsync("body { background-color: #202020; }");
442+
443+
// ... later
444+
await webContents.RemoveInsertedCSSAsync(key);
445+
```
446+
447+
### Editing and Selection
448+
449+
```csharp
450+
await webContents.InsertTextAsync("Hello from .NET");
451+
452+
webContents.SelectAll();
453+
webContents.Copy();
454+
webContents.Unselect();
455+
```
456+
457+
### Find in Page
458+
459+
```csharp
460+
webContents.OnFoundInPage += (result) =>
461+
{
462+
Console.WriteLine($"{result.ActiveMatchOrdinal}/{result.Matches} matches");
463+
464+
if (result.FinalUpdate)
465+
{
466+
webContents.StopFindInPage(StopFindInPageAction.ClearSelection);
467+
}
468+
};
469+
470+
var requestId = await webContents.FindInPageAsync("electron", new FindInPageOptions { MatchCase = false });
471+
```
472+
473+
### Audio
474+
475+
```csharp
476+
webContents.SetAudioMuted(true);
477+
478+
var muted = await webContents.IsAudioMutedAsync();
479+
var audible = await webContents.IsCurrentlyAudibleAsync();
480+
481+
webContents.OnAudioStateChanged += (isAudible) =>
482+
{
483+
Console.WriteLine(isAudible ? "Page started emitting audio" : "Page went silent");
484+
};
485+
486+
webContents.OnMediaStartedPlaying += () => Console.WriteLine("Media playing");
487+
webContents.OnMediaPaused += () => Console.WriteLine("Media paused");
488+
```
489+
282490
## Related APIs
283491

284492
- [Electron.WindowManager](WindowManager.md) - Windows containing web contents

0 commit comments

Comments
 (0)