mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-04-24 23:20:52 +00:00
Add method to destroy all windows manually
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -64,7 +64,6 @@ app.on('before-quit-for-update', () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const manifestJsonFile = require(manifestJsonFilePath);
|
||||
|
||||
Reference in New Issue
Block a user