Skip to content

Commit b2c5b2b

Browse files
committed
browserWindowSetParentWindow: Support null parameter
1 parent a8a800e commit b2c5b2b

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/ElectronNET.API/API/BrowserWindow.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,17 @@ public Task<bool> SetThumbarButtonsAsync(ThumbarButton[] thumbarButtons)
11231123
/// passing null will turn current window into a top-level window.
11241124
/// </summary>
11251125
/// <param name="parent"></param>
1126-
public void SetParentWindow(BrowserWindow parent) => this.CallMethod1(JObject.FromObject(parent, _jsonSerializer));
1126+
public void SetParentWindow(BrowserWindow parent)
1127+
{
1128+
if (parent == null)
1129+
{
1130+
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, null);
1131+
}
1132+
else
1133+
{
1134+
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
1135+
}
1136+
}
11271137

11281138
/// <summary>
11291139
/// The parent window.

src/ElectronNET.Host/api/browserWindows.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,14 @@ export = (socket: Socket, app: Electron.App) => {
721721
});
722722

723723
socket.on('browserWindowSetParentWindow', (id, parent) => {
724+
const child = getWindowById(id);
725+
if (!parent) {
726+
// Clear parent: make this window top-level
727+
child.setParentWindow(null);
728+
return;
729+
}
724730
const browserWindow = BrowserWindow.fromId(parent.id);
725-
726-
getWindowById(id).setParentWindow(browserWindow);
731+
child.setParentWindow(browserWindow);
727732
});
728733

729734
socket.on('browserWindowGetParentWindow', (id) => {

0 commit comments

Comments
 (0)