why is ipcRenderer.sendSync() causing crashing the application?

94 views Asked by At

In the onbeforeunload-Event, I use in my renderer-process ipcRenderer.sendSync() to notify the main-process to show a dialog:

window.onbeforeunload = (e) => {
    const response = ipcRenderer.sendSync('askForSavingChanges');
    if (response == 0) {
        // save ...
    } else if (response == 2) {
        e.returnValue = false;
    }
}

Here is the code in the main-process:

app.whenReady().then(() => {
    initSettings().then(() => {
        ipcMain.on('askForSavingChanges', (event) => event.returnValue = require('electron').dialog.showMessageBoxSync(this,
            {
            type: 'question',
            buttons: ['Yes', 'No', 'Cancel'],
            title: 'Closing',
            message: 'Do you want to save changes?'
            }));
    })
    createWindow();
});

Now, when I close the window, the event onbeforeunload will be called, but when calling ipcRenderer.sendSync() the window will be closed immediately. Do I something wrong?

0

There are 0 answers