From 374d92f3b114e91c650ea0848c86e3799cd9ea75 Mon Sep 17 00:00:00 2001 From: rafael-aero Date: Fri, 3 Sep 2021 15:28:32 +0200 Subject: [PATCH] don't throw in case the tray was destroyed between calls --- ElectronNET.Host/api/tray.js | 28 +++++++++---------- .../AppSysInformationController.cs | 6 ++-- ElectronNET.WebApp/Program.cs | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ElectronNET.Host/api/tray.js b/ElectronNET.Host/api/tray.js index 0f3a9c9..d82650c 100644 --- a/ElectronNET.Host/api/tray.js +++ b/ElectronNET.Host/api/tray.js @@ -5,42 +5,42 @@ let electronSocket; module.exports = (socket) => { electronSocket = socket; socket.on('register-tray-click', (id) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.on('click', (event, bounds) => { electronSocket.emit('tray-click-event' + id, { eventArgs: event.__proto__, bounds: bounds }); }); } }); socket.on('register-tray-right-click', (id) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.on('right-click', (event, bounds) => { electronSocket.emit('tray-right-click-event' + id, { eventArgs: event.__proto__, bounds: bounds }); }); } }); socket.on('register-tray-double-click', (id) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.on('double-click', (event, bounds) => { electronSocket.emit('tray-double-click-event' + id, { eventArgs: event.__proto__, bounds: bounds }); }); } }); socket.on('register-tray-balloon-show', (id) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.on('balloon-show', () => { electronSocket.emit('tray-balloon-show-event' + id); }); } }); socket.on('register-tray-balloon-click', (id) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.on('balloon-click', () => { electronSocket.emit('tray-balloon-click-event' + id); }); } }); socket.on('register-tray-balloon-closed', (id) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.on('balloon-closed', () => { electronSocket.emit('tray-balloon-closed-event' + id); }); @@ -58,33 +58,33 @@ module.exports = (socket) => { } }); socket.on('tray-destroy', () => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.destroy(); } }); socket.on('tray-setImage', (image) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.setImage(image); } }); socket.on('tray-setPressedImage', (image) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { const img = electron_1.nativeImage.createFromPath(image); tray.value.setPressedImage(img); } }); socket.on('tray-setToolTip', (toolTip) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.setToolTip(toolTip); } }); socket.on('tray-setTitle', (title) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.setTitle(title); } }); socket.on('tray-displayBalloon', (options) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.displayBalloon(options); } }); @@ -95,7 +95,7 @@ module.exports = (socket) => { } }); socket.on('register-tray-on-event', (eventName, listenerName) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.on(eventName, (...args) => { if (args.length > 1) { electronSocket.emit(listenerName, args[1]); @@ -107,7 +107,7 @@ module.exports = (socket) => { } }); socket.on('register-tray-once-event', (eventName, listenerName) => { - if (tray.value) { + if (tray.value && !tray.value.isDestroyed()) { tray.value.once(eventName, (...args) => { if (args.length > 1) { electronSocket.emit(listenerName, args[1]); diff --git a/ElectronNET.WebApp/Controllers/AppSysInformationController.cs b/ElectronNET.WebApp/Controllers/AppSysInformationController.cs index f184e14..57082c6 100644 --- a/ElectronNET.WebApp/Controllers/AppSysInformationController.cs +++ b/ElectronNET.WebApp/Controllers/AppSysInformationController.cs @@ -11,7 +11,7 @@ namespace ElectronNET.WebApp.Controllers { if(HybridSupport.IsElectronActive) { - Electron.IpcMain.On("app-info", async (args) => + Electron.IpcMain.OnWithId("app-info", async (id, args) => { string appPath = await Electron.App.GetAppPathAsync(); @@ -19,7 +19,7 @@ namespace ElectronNET.WebApp.Controllers Electron.IpcMain.Send(mainWindow, "got-app-path", appPath); }); - Electron.IpcMain.On("sys-info", async (args) => + Electron.IpcMain.OnWithId("sys-info", async (id, args) => { string homePath = await Electron.App.GetPathAsync(PathName.Home); @@ -27,7 +27,7 @@ namespace ElectronNET.WebApp.Controllers Electron.IpcMain.Send(mainWindow, "got-sys-info", homePath); }); - Electron.IpcMain.On("screen-info", async (args) => + Electron.IpcMain.OnWithId("screen-info", async (id, args) => { var display = await Electron.Screen.GetPrimaryDisplayAsync(); diff --git a/ElectronNET.WebApp/Program.cs b/ElectronNET.WebApp/Program.cs index 54512d2..c79b260 100644 --- a/ElectronNET.WebApp/Program.cs +++ b/ElectronNET.WebApp/Program.cs @@ -10,7 +10,7 @@ namespace ElectronNET.WebApp { public static void Main(string[] args) { - //Debugger.Launch(); + Debugger.Launch(); CreateWebHostBuilder(args).Build().Run(); }