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

@@ -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();
});