Desktop: Fixes #4570: Prevents plugin from causing an error when the app closes

pull/4849/head
Laurent Cozic 2021-04-11 11:58:45 +02:00
parent 7518ac00fc
commit 170f587f28
1 changed files with 19 additions and 10 deletions

View File

@ -189,18 +189,27 @@ export default class ElectronAppWrapper {
// This handler receives IPC messages from a plugin or from the main window,
// and forwards it to the main window or the plugin window.
ipcMain.on('pluginMessage', (_event: any, message: PluginMessage) => {
if (message.target === 'mainWindow') {
this.win_.webContents.send('pluginMessage', message);
}
if (message.target === 'plugin') {
const win = this.pluginWindows_[message.pluginId];
if (!win) {
this.logger().error(`Trying to send IPC message to non-existing plugin window: ${message.pluginId}`);
return;
try {
if (message.target === 'mainWindow') {
this.win_.webContents.send('pluginMessage', message);
}
win.webContents.send('pluginMessage', message);
if (message.target === 'plugin') {
const win = this.pluginWindows_[message.pluginId];
if (!win) {
this.logger().error(`Trying to send IPC message to non-existing plugin window: ${message.pluginId}`);
return;
}
win.webContents.send('pluginMessage', message);
}
} catch (error) {
// An error might happen when the app is closing and a plugin
// sends a message. In which case, the above code would try to
// access a destroyed webview.
// https://github.com/laurent22/joplin/issues/4570
console.error('Could not process plugin message:', message);
console.error(error);
}
});