Skip to content

Commit c8268fa

Browse files
authored
Merge pull request #1034 from ElectronNET/develop
Release 0.4.1
2 parents 456135a + 8eead56 commit c8268fa

File tree

86 files changed

+3184
-3911
lines changed

Some content is hidden

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

86 files changed

+3184
-3911
lines changed

Changelog.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# 0.4.1
2+
3+
## ElectronNET.Core
4+
5+
- Updated documentation for preload scripts (#1031) @AeonSake
6+
- Updated timeout for electron-builder (#1013) @softworkz
7+
- Updated disposal avoiding exceptions on teardown (#1026) @softworkz
8+
- Updated migration guide (#1015) @hilin
9+
- Fixed handling of `Center` property for windows (#1001)
10+
- Fixed false alarm for `ELECTRON001`, `ELECTRON008`, and `ELECTRON009` (#1012) @softworkz
11+
- Added missing methods on `Cookies` (#1000)
12+
- Added overload for `GetAllDisplaysAsync` with timeout (#1033) @softworkz
13+
- Added `OnBoundsChanged` event (#1014) @softworkz
14+
- Added new events for `ipcMain` (#1019) @DYH1319
15+
116
# 0.4.0
217

318
## ElectronNET.Core

docs/Core/Migration-Checks.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ When you build an Electron.NET project, the following validation checks are perf
88

99
| Code | Check | Description |
1010
|------|-------|-------------|
11-
| [ELECTRON001](#1-packagejson-not-allowed) | package.json not allowed | Ensures no package.json exists outside ElectronHostHook |
11+
| [ELECTRON001](#1-packagejson-rules) | package.json location rules | Ensures `package.json`/`package-lock.json` aren’t present in unsupported locations (root `package.json` handled separately) |
12+
| [ELECTRON008](#1-packagejson-rules) | root package.json contains electron | Warns when root `package.json` contains the word `electron` (case-insensitive) |
13+
| [ELECTRON009](#1-packagejson-rules) | root package.json copied to output | Warns when root `package.json` is configured to be copied to output/publish |
1214
| [ELECTRON002](#2-electron-manifestjson-not-allowed) | electron-manifest.json not allowed | Detects deprecated manifest files |
1315
| [ELECTRON003](#3-electron-builderjson-location) | electron-builder.json location | Verifies electron-builder.json exists in Properties folder |
1416
| [ELECTRON004](#3-electron-builderjson-location) | electron-builder.json wrong location | Warns if electron-builder.json is found in incorrect locations |
@@ -18,24 +20,38 @@ When you build an Electron.NET project, the following validation checks are perf
1820

1921
---
2022

21-
## 1. package.json not allowed
23+
## 1. package.json rules
2224

23-
**Warning Code:** `ELECTRON001`
25+
**Warning Codes:** `ELECTRON001`, `ELECTRON008`, `ELECTRON009`
2426

2527
### What is checked
2628

27-
The build system scans for `package.json` and `package-lock.json` files in your project directory. These files should not exist in the project root or subdirectories (with one exception).
29+
The build system scans for `package.json` and `package-lock.json` files in your project directory.
30+
31+
Rules:
32+
33+
- **ELECTRON001**: `package.json` / `package-lock.json` must not exist in the project directory or subdirectories
34+
- Exception: `ElectronHostHook` folder is allowed
35+
- Note: a **root** `package.json` is **excluded** from `ELECTRON001` and validated by `ELECTRON008` / `ELECTRON009`
36+
37+
- **ELECTRON008**: If a root `package.json` exists, it must **not** contain electron-related dependencies or configuration.
38+
39+
- **ELECTRON009**: If a root `package.json` exists, it must **not** be configured to be copied to output/publish (for example via `CopyToOutputDirectory` / `CopyToPublishDirectory` metadata)
2840

2941
### Why this matters
3042

31-
In previous versions of Electron.NET, a `package.json` file was required in the project. The new version generates this file automatically from MSBuild properties defined in your `.csproj` file.
43+
Electron.NET generates its Electron-related `package.json` during publishing based on MSBuild properties. A user-maintained Electron-related `package.json` can conflict with that process.
44+
45+
Also, ensuring the root `package.json` is not copied prevents accidentally shipping it with the published app.
3246

3347
### Exception
3448

35-
A `package.json` file **is allowed** in the `ElectronHostHook` folder if you're using custom host hooks. This is the only valid location for a manually maintained package.json.
49+
A `package.json` / `package-lock.json` file **is allowed** in the `ElectronHostHook` folder if you're using custom host hooks.
3650

3751
### How to fix
3852

53+
If you have an Electron-related `package.json` from older Electron.NET versions:
54+
3955
1. **Open your project's `.csproj` file**
4056
2. **Add the required properties** to a PropertyGroup with the label `ElectronNetCommon`:
4157

@@ -51,7 +67,12 @@ A `package.json` file **is allowed** in the `ElectronHostHook` folder if you're
5167
</PropertyGroup>
5268
```
5369

54-
3. **Delete the old `package.json`** file from your project root
70+
3. **Delete** Electron-related `package.json` / `package-lock.json` files (except those under `ElectronHostHook` if applicable)
71+
72+
If you keep a root `package.json` for non-Electron reasons:
73+
74+
- Ensure it does **not** contain electron dependencies or configuration (fixes `ELECTRON008`)
75+
- Ensure it is **not** copied to output/publish (fixes `ELECTRON009`)
5576

5677
> **See also:** [Migration Guide](Migration-Guide.md) for complete migration instructions.
5778

docs/GettingStarted/Console-App.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Add the Electron.NET configuration to your `.csproj` file:
5454
</PropertyGroup>
5555

5656
<ItemGroup>
57-
<PackageReference Include="ElectronNET.Core" Version="0.4.0" />
57+
<PackageReference Include="ElectronNET.Core" Version="0.4.1" />
5858
</ItemGroup>
5959
```
6060

docs/Using/Configuration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions
8585
```
8686

8787

88+
### Preload Script
89+
90+
If you require the use of a [preload script](https://www.electronjs.org/docs/latest/tutorial/tutorial-preload), you can specify the file path of the script when creating a new window like so:
91+
92+
```csharp
93+
WebPreferences wp = new WebPreferences();
94+
wp.Preload = "path/to/preload.js";
95+
BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions
96+
{
97+
WebPreferences = wp
98+
};
99+
```
100+
101+
> [!IMPORTANT]
102+
> When using a preload script _AND_ running a Blazor app, `IsRunningBlazor` must be set to `false` (or removed) and the following lines must be added to the preload script:
103+
> ```js
104+
> global.process = undefined;
105+
> global.module = undefined;
106+
> ```
107+
88108
89109
## 🚀 Next Steps
90110

src/ElectronNET.API/API/ApiBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ public Invocator(ApiBase apiBase, string callerName, TimeSpan timeout, object ar
314314
{
315315
if (this.tcs != null)
316316
{
317-
var ex = new TimeoutException($"No response after {timeout:D}ms trying to retrieve value {apiBase.objectName}.{callerName}()");
317+
var ex = new TimeoutException(
318+
$"No response after {(long)timeout.TotalMilliseconds}ms trying to retrieve value {apiBase.objectName}.{callerName}()"
319+
);
318320
this.tcs.TrySetException(ex);
319321
this.tcs = null;
320322
}

src/ElectronNET.API/API/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public void Exit(int exitCode = 0)
427427

428428
public void DisposeSocket()
429429
{
430-
BridgeConnector.Socket.DisposeSocket();
430+
BridgeConnector.Socket.Dispose();
431431
}
432432

433433
/// <summary>

src/ElectronNET.API/API/BrowserWindow.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ public event Action OnMove
186186
remove => RemoveEvent(value, Id);
187187
}
188188

189+
/// <summary>
190+
/// Emitted when the window is moved or resized.
191+
/// </summary>
192+
/// <remarks>
193+
/// While not being an original Electron event, this one includes the bounds values,
194+
/// saving the additional roundtrip for calling <see cref="GetBoundsAsync"/>.
195+
/// </remarks>
196+
public event Action<Rectangle> OnBoundsChanged
197+
{
198+
add => AddEvent(value, Id);
199+
remove => RemoveEvent(value, Id);
200+
}
201+
189202
/// <summary>
190203
/// macOS: Emitted once when the window is moved to a new position.
191204
/// </summary>

src/ElectronNET.API/API/Cookies.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ElectronNET.API.Serialization;
33
using System;
44
using System.Text.Json;
5+
using System.Threading.Tasks;
56

67
namespace ElectronNET.API
78
{
@@ -54,10 +55,79 @@ public event Action<Cookie, CookieChangedCause, bool> OnChanged
5455
_changed -= value;
5556

5657
if (_changed == null)
58+
{
5759
BridgeConnector.Socket.Off("webContents-session-cookies-changed" + Id);
60+
}
5861
}
5962
}
6063

6164
private event Action<Cookie, CookieChangedCause, bool> _changed;
65+
66+
67+
68+
/// <summary>
69+
/// Sends a request to get all cookies matching filter, and resolves a callack with the response.
70+
/// </summary>
71+
/// <param name="filter">
72+
/// </param>
73+
/// <returns>A task which resolves an array of cookie objects.</returns>
74+
public Task<Cookie[]> GetAsync(CookieFilter filter)
75+
{
76+
var tcs = new TaskCompletionSource<Cookie[]>();
77+
var guid = Guid.NewGuid().ToString();
78+
79+
BridgeConnector.Socket.Once<Cookie[]>("webContents-session-cookies-get-completed" + guid, tcs.SetResult);
80+
BridgeConnector.Socket.Emit("webContents-session-cookies-get", Id, filter, guid);
81+
82+
return tcs.Task;
83+
}
84+
85+
/// <summary>
86+
///
87+
/// </summary>
88+
/// <param name="details"></param>
89+
/// <returns></returns>
90+
public Task SetAsync(CookieDetails details)
91+
{
92+
var tcs = new TaskCompletionSource<object>();
93+
var guid = Guid.NewGuid().ToString();
94+
95+
BridgeConnector.Socket.Once<object>("webContents-session-cookies-set-completed" + guid, tcs.SetResult);
96+
BridgeConnector.Socket.Emit("webContents-session-cookies-set", Id, details, guid);
97+
98+
return tcs.Task;
99+
}
100+
101+
/// <summary>
102+
/// Removes the cookies matching url and name
103+
/// </summary>
104+
/// <param name="url">The URL associated with the cookie.</param>
105+
/// <param name="name">The name of cookie to remove.</param>
106+
/// <returns>A task which resolves when the cookie has been removed</returns>
107+
public Task RemoveAsync(string url, string name)
108+
{
109+
var tcs = new TaskCompletionSource<object>();
110+
var guid = Guid.NewGuid().ToString();
111+
112+
BridgeConnector.Socket.Once<object>("webContents-session-cookies-remove-completed" + guid, tcs.SetResult);
113+
BridgeConnector.Socket.Emit("webContents-session-cookies-remove", Id, url, name, guid);
114+
115+
return tcs.Task;
116+
}
117+
118+
/// <summary>
119+
/// Writes any unwritten cookies data to disk.
120+
/// </summary>
121+
/// <returns>A task which resolves when the cookie store has been flushed</returns>
122+
public Task FlushStoreAsync()
123+
{
124+
var tcs = new TaskCompletionSource<object>();
125+
var guid = Guid.NewGuid().ToString();
126+
127+
BridgeConnector.Socket.Once<object>("webContents-session-cookies-flushStore-completed" + guid, tcs.SetResult);
128+
BridgeConnector.Socket.Emit("webContents-session-cookies-flushStore", Id, guid);
129+
130+
return tcs.Task;
131+
}
62132
}
63133
}

src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public class BrowserWindowOptions
2424
/// ( if y is used) Window's left offset from screen. Default is to center the
2525
/// window.
2626
/// </summary>
27-
public int X { get; set; } = -1;
27+
public int? X { get; set; }
2828

2929
/// <summary>
3030
/// ( if x is used) Window's top offset from screen. Default is to center the
3131
/// window.
3232
/// </summary>
33-
public int Y { get; set; } = -1;
33+
public int? Y { get; set; }
3434

3535
/// <summary>
3636
/// The width and height would be used as web page's size, which means the actual

src/ElectronNET.API/API/Entities/Cookie.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Cookie
2424
/// <summary>
2525
/// Gets or sets a value indicating whether the cookie is a host-only cookie; this will only be true if no domain was passed.
2626
/// </summary>
27-
public bool HostOnly { get; set; }
27+
public bool? HostOnly { get; set; }
2828

2929
/// <summary>
3030
/// Gets or sets the path of the cookie.
@@ -34,22 +34,22 @@ public class Cookie
3434
/// <summary>
3535
/// Gets or sets a value indicating whether the cookie is marked as secure.
3636
/// </summary>
37-
public bool Secure { get; set; }
37+
public bool? Secure { get; set; }
3838

3939
/// <summary>
4040
/// Gets or sets a value indicating whether the cookie is marked as HTTP only.
4141
/// </summary>
42-
public bool HttpOnly { get; set; }
42+
public bool? HttpOnly { get; set; }
4343

4444
/// <summary>
4545
/// Gets or sets a value indicating whether the cookie is a session cookie or a persistent cookie with an expiration date.
4646
/// </summary>
47-
public bool Session { get; set; }
47+
public bool? Session { get; set; }
4848

4949
/// <summary>
5050
/// Gets or sets the expiration date of the cookie as the number of seconds since the UNIX epoch. Not provided for session cookies.
5151
/// </summary>
52-
public double ExpirationDate { get; set; }
52+
public double? ExpirationDate { get; set; }
5353

5454
/// <summary>
5555
/// Gets or sets the SameSite policy applied to this cookie. Can be "unspecified", "no_restriction", "lax" or "strict".

0 commit comments

Comments
 (0)