Add method to destroy all windows manually

This commit is contained in:
theolivenbaum
2021-09-08 08:57:05 +02:00
parent 5559fc61b1
commit 8604b50224
4 changed files with 50 additions and 1 deletions

View File

@@ -218,6 +218,19 @@ namespace ElectronNET.API
return await taskCompletionSource.Task;
}
/// <summary>
/// Destroy all windows.
/// </summary>
/// <returns>Number of windows destroyed</returns>
public async Task<int> DestroyAllWindows()
{
var destroyed = await BridgeConnector.OnResult<int>("browserWindowDestroyAll", "browserWindowDestroyAll-completed");
_browserViews.Clear();
_browserWindows.Clear();
return destroyed;
}
private static JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),

View File

@@ -262,6 +262,25 @@ module.exports = (socket, app) => {
socket.on('browserWindowDestroy', (id) => {
getWindowById(id)?.destroy();
});
socket.on('browserWindowDestroyAll', () => {
const windows = electron_1.BrowserWindow.getAllWindows();
let count = 0;
if (windows.length) {
windows.forEach(w => {
try {
w.hide();
w.destroy();
count++;
}
catch {
//ignore, probably already destroyed
}
});
}
electronSocket.emit('browserWindowDestroyAll-completed', count);
});
socket.on('browserWindowClose', (id) => {
getWindowById(id)?.close();
});

View File

@@ -288,6 +288,24 @@ export = (socket: Socket, app: Electron.App) => {
getWindowById(id)?.destroy();
});
socket.on('browserWindowDestroyAll', () => {
const windows = BrowserWindow.getAllWindows();
let count = 0;
if (windows.length) {
windows.forEach(w => {
try {
w.hide();
w.destroy();
count++;
}
catch {
//ignore, probably already destroyed
}
});
}
electronSocket.emit('browserWindowDestroyAll-completed', count);
});
socket.on('browserWindowClose', (id) => {
getWindowById(id)?.close();
});

View File

@@ -64,7 +64,6 @@ app.on('before-quit-for-update', () => {
}
});
}
});
const manifestJsonFile = require(manifestJsonFilePath);