fix closed behaviour

This commit is contained in:
rafael-aero
2021-09-01 22:10:44 +02:00
parent ec74c7989a
commit 4e7cebe519
2 changed files with 14 additions and 25 deletions

View File

@@ -195,6 +195,9 @@ module.exports = (socket, app) => {
else {
window = new electron_1.BrowserWindow(options);
}
let window_id = window.id; //save here for future use
if (options.proxy) {
window.webContents.session.setProxy({ proxyRules: options.proxy });
}
@@ -219,19 +222,11 @@ module.exports = (socket, app) => {
}
});
window.on('closed', (sender) => {
for (let index = 0; index < windows.length; index++) {
const windowItem = windows[index];
try {
windowItem.id;
}
catch (error) {
if (error.message === 'Object has been destroyed') {
windows.splice(index, 1);
const ids = [];
windows.forEach(x => ids.push(x.id));
electronSocket.emit('BrowserWindowClosed', ids);
}
}
electronSocket.emit('BrowserWindowClosed', [window_id]);
const toRemove = windows.findIndex(w => w === window);
if (toRemove >= 0) {
windows.splice(toRemove, 1);
}
});
if (loadUrl) {

View File

@@ -229,6 +229,8 @@ export = (socket: Socket, app: Electron.App) => {
window = new BrowserWindow(options);
}
let window_id = window.id; //save here for future use
if (options.proxy) {
window.webContents.session.setProxy({proxyRules: options.proxy});
}
@@ -246,19 +248,11 @@ export = (socket: Socket, app: Electron.App) => {
});
window.on('closed', (sender) => {
for (let index = 0; index < windows.length; index++) {
const windowItem = windows[index];
try {
windowItem.id;
} catch (error) {
if (error.message === 'Object has been destroyed') {
windows.splice(index, 1);
electronSocket.emit('BrowserWindowClosed', [window_id]);
const toRemove = windows.findIndex(w => w === window);
const ids = [];
windows.forEach(x => ids.push(x.id));
electronSocket.emit('BrowserWindowClosed', ids);
}
}
if (toRemove >= 0) {
windows.splice(toRemove, 1);
}
});