From ae3f7556485b671c24d434e66286bd87d59830f0 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Mon, 22 Dec 2025 12:32:52 +0100 Subject: [PATCH 1/3] Fixed center handling --- Changelog.md | 6 ++++++ docs/GettingStarted/Console-App.md | 2 +- src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs | 4 ++-- src/ElectronNET.API/API/WindowManager.cs | 5 +---- src/ElectronNET.ConsoleApp/ElectronNET.ConsoleApp.csproj | 2 +- .../ElectronNET.Samples.ElectronHostHook.csproj | 4 ++-- src/ElectronNET.WebApp/ElectronNET.WebApp.csproj | 4 ++-- src/common.props | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Changelog.md b/Changelog.md index 18871751..8205fdaa 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +# 0.4.1 + +## ElectronNET.Core + +- Fixed handling of `Center` property for windows (#1001) + # 0.4.0 ## ElectronNET.Core diff --git a/docs/GettingStarted/Console-App.md b/docs/GettingStarted/Console-App.md index ec8a6043..cd091efe 100644 --- a/docs/GettingStarted/Console-App.md +++ b/docs/GettingStarted/Console-App.md @@ -54,7 +54,7 @@ Add the Electron.NET configuration to your `.csproj` file: - + ``` diff --git a/src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs b/src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs index dec474e0..fc44edf7 100644 --- a/src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs +++ b/src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs @@ -24,13 +24,13 @@ public class BrowserWindowOptions /// ( if y is used) Window's left offset from screen. Default is to center the /// window. /// - public int X { get; set; } = -1; + public int? X { get; set; } /// /// ( if x is used) Window's top offset from screen. Default is to center the /// window. /// - public int Y { get; set; } = -1; + public int? Y { get; set; } /// /// The width and height would be used as web page's size, which means the actual diff --git a/src/ElectronNET.API/API/WindowManager.cs b/src/ElectronNET.API/API/WindowManager.cs index 20a6b193..9b1ffd62 100644 --- a/src/ElectronNET.API/API/WindowManager.cs +++ b/src/ElectronNET.API/API/WindowManager.cs @@ -130,11 +130,8 @@ public async Task CreateWindowAsync(BrowserWindowOptions options, options.Height += 7; } - if (options.X == -1 && options.Y == -1) + if (!options.X.HasValue && !options.Y.HasValue) { - options.X = 0; - options.Y = 0; - await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false); } else diff --git a/src/ElectronNET.ConsoleApp/ElectronNET.ConsoleApp.csproj b/src/ElectronNET.ConsoleApp/ElectronNET.ConsoleApp.csproj index f0cb290c..fa0346fc 100644 --- a/src/ElectronNET.ConsoleApp/ElectronNET.ConsoleApp.csproj +++ b/src/ElectronNET.ConsoleApp/ElectronNET.ConsoleApp.csproj @@ -70,7 +70,7 @@ - + diff --git a/src/ElectronNET.Samples.ElectronHostHook/ElectronNET.Samples.ElectronHostHook.csproj b/src/ElectronNET.Samples.ElectronHostHook/ElectronNET.Samples.ElectronHostHook.csproj index 802cdab6..e9ff77b0 100644 --- a/src/ElectronNET.Samples.ElectronHostHook/ElectronNET.Samples.ElectronHostHook.csproj +++ b/src/ElectronNET.Samples.ElectronHostHook/ElectronNET.Samples.ElectronHostHook.csproj @@ -27,8 +27,8 @@ - - + + diff --git a/src/ElectronNET.WebApp/ElectronNET.WebApp.csproj b/src/ElectronNET.WebApp/ElectronNET.WebApp.csproj index 4d37bd91..b4547bb9 100644 --- a/src/ElectronNET.WebApp/ElectronNET.WebApp.csproj +++ b/src/ElectronNET.WebApp/ElectronNET.WebApp.csproj @@ -76,8 +76,8 @@ - - + + diff --git a/src/common.props b/src/common.props index aaaae347..6fce141e 100644 --- a/src/common.props +++ b/src/common.props @@ -1,6 +1,6 @@ - 0.4.0 + 0.4.1 ElectronNET.Core Gregor Biswanger, Florian Rappl, softworkz Electron.NET From 809b0a6be76c8f0ec18606a7e7449ab57bc86408 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 23 Dec 2025 00:38:37 +0100 Subject: [PATCH 2/3] Added missing methods --- Changelog.md | 1 + src/ElectronNET.API/API/Cookies.cs | 70 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/Changelog.md b/Changelog.md index 8205fdaa..9cb75861 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ ## ElectronNET.Core - Fixed handling of `Center` property for windows (#1001) +- Added missing methods on `Cookies` (#1000) # 0.4.0 diff --git a/src/ElectronNET.API/API/Cookies.cs b/src/ElectronNET.API/API/Cookies.cs index dac0d2d0..17ac7eee 100644 --- a/src/ElectronNET.API/API/Cookies.cs +++ b/src/ElectronNET.API/API/Cookies.cs @@ -2,6 +2,7 @@ using ElectronNET.API.Serialization; using System; using System.Text.Json; +using System.Threading.Tasks; namespace ElectronNET.API { @@ -54,10 +55,79 @@ public event Action OnChanged _changed -= value; if (_changed == null) + { BridgeConnector.Socket.Off("webContents-session-cookies-changed" + Id); + } } } private event Action _changed; + + + + /// + /// Sends a request to get all cookies matching filter, and resolves a callack with the response. + /// + /// + /// + /// A task which resolves an array of cookie objects. + public Task GetAsync(CookieFilter filter) + { + var tcs = new TaskCompletionSource(); + var guid = Guid.NewGuid().ToString(); + + BridgeConnector.Socket.Once("webContents-session-cookies-get-completed" + guid, tcs.SetResult); + BridgeConnector.Socket.Emit("webContents-session-cookies-get", Id, filter, guid); + + return tcs.Task; + } + + /// + /// + /// + /// + /// + public Task SetAsync(CookieDetails details) + { + var tcs = new TaskCompletionSource(); + var guid = Guid.NewGuid().ToString(); + + BridgeConnector.Socket.Once("webContents-session-cookies-set-completed" + guid, tcs.SetResult); + BridgeConnector.Socket.Emit("webContents-session-cookies-set", Id, details, guid); + + return tcs.Task; + } + + /// + /// Removes the cookies matching url and name + /// + /// The URL associated with the cookie. + /// The name of cookie to remove. + /// A task which resolves when the cookie has been removed + public Task RemoveAsync(string url, string name) + { + var tcs = new TaskCompletionSource(); + var guid = Guid.NewGuid().ToString(); + + BridgeConnector.Socket.Once("webContents-session-cookies-remove-completed" + guid, tcs.SetResult); + BridgeConnector.Socket.Emit("webContents-session-cookies-remove", Id, url, name, guid); + + return tcs.Task; + } + + /// + /// Writes any unwritten cookies data to disk. + /// + /// A task which resolves when the cookie store has been flushed + public Task FlushStoreAsync() + { + var tcs = new TaskCompletionSource(); + var guid = Guid.NewGuid().ToString(); + + BridgeConnector.Socket.Once("webContents-session-cookies-flushStore-completed" + guid, tcs.SetResult); + BridgeConnector.Socket.Emit("webContents-session-cookies-flushStore", Id, guid); + + return tcs.Task; + } } } \ No newline at end of file From 682a1c38edd3a9259f8b44523c5a27ae83a913dd Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 23 Dec 2025 21:10:57 +0100 Subject: [PATCH 3/3] Optional --- src/ElectronNET.API/API/Entities/Cookie.cs | 10 +++++----- src/ElectronNET.API/API/Entities/CookieFilter.cs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ElectronNET.API/API/Entities/Cookie.cs b/src/ElectronNET.API/API/Entities/Cookie.cs index 815c2865..96eae3ec 100644 --- a/src/ElectronNET.API/API/Entities/Cookie.cs +++ b/src/ElectronNET.API/API/Entities/Cookie.cs @@ -24,7 +24,7 @@ public class Cookie /// /// Gets or sets a value indicating whether the cookie is a host-only cookie; this will only be true if no domain was passed. /// - public bool HostOnly { get; set; } + public bool? HostOnly { get; set; } /// /// Gets or sets the path of the cookie. @@ -34,22 +34,22 @@ public class Cookie /// /// Gets or sets a value indicating whether the cookie is marked as secure. /// - public bool Secure { get; set; } + public bool? Secure { get; set; } /// /// Gets or sets a value indicating whether the cookie is marked as HTTP only. /// - public bool HttpOnly { get; set; } + public bool? HttpOnly { get; set; } /// /// Gets or sets a value indicating whether the cookie is a session cookie or a persistent cookie with an expiration date. /// - public bool Session { get; set; } + public bool? Session { get; set; } /// /// Gets or sets the expiration date of the cookie as the number of seconds since the UNIX epoch. Not provided for session cookies. /// - public double ExpirationDate { get; set; } + public double? ExpirationDate { get; set; } /// /// Gets or sets the SameSite policy applied to this cookie. Can be "unspecified", "no_restriction", "lax" or "strict". diff --git a/src/ElectronNET.API/API/Entities/CookieFilter.cs b/src/ElectronNET.API/API/Entities/CookieFilter.cs index 7914fe80..dd1d84c5 100644 --- a/src/ElectronNET.API/API/Entities/CookieFilter.cs +++ b/src/ElectronNET.API/API/Entities/CookieFilter.cs @@ -29,16 +29,16 @@ public class CookieFilter /// /// (optional) - Filters cookies by their Secure property. /// - public bool Secure { get; set; } + public bool? Secure { get; set; } /// /// (optional) - Filters out session or persistent cookies. /// - public bool Session { get; set; } + public bool? Session { get; set; } /// /// (optional) - Filters cookies by httpOnly. /// - public bool HttpOnly { get; set; } + public bool? HttpOnly { get; set; } } } \ No newline at end of file