From ed7cc434eafd273f500de4fe73b81f43582b7d33 Mon Sep 17 00:00:00 2001 From: softworkz Date: Sun, 9 Nov 2025 02:25:33 +0100 Subject: [PATCH] browserWindowSetParentWindow: Support null parameter --- src/ElectronNET.API/API/BrowserWindow.cs | 12 +++++++++++- src/ElectronNET.Host/api/browserWindows.ts | 9 +++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ElectronNET.API/API/BrowserWindow.cs b/src/ElectronNET.API/API/BrowserWindow.cs index d74b82c..012cbfb 100644 --- a/src/ElectronNET.API/API/BrowserWindow.cs +++ b/src/ElectronNET.API/API/BrowserWindow.cs @@ -1140,7 +1140,17 @@ public class BrowserWindow : ApiBase /// passing null will turn current window into a top-level window. /// /// - public void SetParentWindow(BrowserWindow parent) => this.CallMethod1(JObject.FromObject(parent, _jsonSerializer)); + public void SetParentWindow(BrowserWindow parent) + { + if (parent == null) + { + BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, null); + } + else + { + BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer)); + } + } /// /// The parent window. diff --git a/src/ElectronNET.Host/api/browserWindows.ts b/src/ElectronNET.Host/api/browserWindows.ts index a6a56a5..b231742 100644 --- a/src/ElectronNET.Host/api/browserWindows.ts +++ b/src/ElectronNET.Host/api/browserWindows.ts @@ -721,9 +721,14 @@ export = (socket: Socket, app: Electron.App) => { }); socket.on('browserWindowSetParentWindow', (id, parent) => { + const child = getWindowById(id); + if (!parent) { + // Clear parent: make this window top-level + child.setParentWindow(null); + return; + } const browserWindow = BrowserWindow.fromId(parent.id); - - getWindowById(id).setParentWindow(browserWindow); + child.setParentWindow(browserWindow); }); socket.on('browserWindowGetParentWindow', (id) => {