[electron] A small note on the problems encountered in the first study

There are two ways for the rendering process IPC to communicate with the main process:

1. IpcRenderer.invoke is for synchronous or asynchronous operations that need to pass parameters.
const res = await IpcRenderer.invoke('EMAIL_AUTH_LOGIN', params);
The return value will wait for the main process to return the message before continuing to pass the execution.
2. IpcRenderer.send; For asynchronous communication operations that only require event triggering,
IpcRenderer.send('EMAIL_AUTH_SIGN_OUT');

There are two ways for the main process IPC to communicate with the rendering process:

// 登录
ipcMain.handle('EMAIL_AUTH_LOGIN', async (_, params) => {
    
    
    console.log('>>>>>>> EMAIL_AUTH_LOGIN ipcMain.on', params);
    const respInfo = await authProvider?.login();
    // ipcMain
    console.log('>>>>>>> EMAIL_AUTH_LOGIN respInfo', respInfo);
    return respInfo;
});
// 退出
ipcMain.on('EMAIL_AUTH_SIGN_OUT', () => {
    
    
    authProvider?.logout();
});

The main process only handles non-interactive things, such as calling the authorization interface of auth2 to return data to the rendering process, and then the rendering process performs UI interaction processing, such as opening a window Tab.
The main process on the desktop side console.logcan be printed in TERMINALthe window, but the rendering process (rendering main process, rendering auxiliary process) cannot, it needs to use Log (the log printing api that comes with electron) to print.

Guess you like

Origin blog.csdn.net/hzxOnlineOk/article/details/131484070