在 Electron 中, ipcRenderer.invoke() 在实例已经创建的情况下打开应用程序后不起作用。这是我的代码:
// 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();
}
是否有另一种方法可以在不使用 ipcRenderer.invoke() 和 ipcMain.handle() 的情况下将信息从渲染器发送到主程序?或者有没有办法继续使用 ipcRenderer.invoke()?
我的渲染器代码示例适用于第一个实例但不适用于第二个实例
while (
(await ipcRenderer.invoke(
"getVariableValue",
"storageEncrypted"
)) == false
) {