In Electron, ipcRenderer.invoke() Does not work after app is opened while an instance is already created. Here is my code:
// Force Single Instance Application
const gotTheLock = app.requestSingleInstanceLock()
if (gotTheLock) {
app.on('second-instance', (e, argv) => {
// Someone tried to run a second instance, we should focus our window.
// Protocol handler for win32
// argv: An array of the second instance’s (command line / deep linked) arguments
if (process.platform == 'win32') {
// Keep only command line / deep linked arguments
deeplinkingUrl = argv.slice(1);
}
if (deeplinkingUrl.length > 0) {
mainWindow.webContents.send('url', deeplinkingUrl);
}
logEverywhere('app.makeSingleInstance# ' + deeplinkingUrl);
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.focus();
}
app.whenReady().then(() => {
mainWindow = createWindow()
})
})
} else {
app.quit();
}
Is there another way of sending information from the renderer to the main without using ipcRenderer.invoke() and ipcMain.handle()? Or is there a way to continue using ipcRenderer.invoke()?
An example of my renderer code that works on the first instance but not on the second
while (
(await ipcRenderer.invoke(
"getVariableValue",
"storageEncrypted"
)) == false
) {