mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-31 04:54:06 +00:00
fix closed behaviour
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user