refactor(electron): reduce the number of listeners for ipc (#7740)

previously there are quite a lot of api/events handlers registered on ipcMain/ipcRenderer. After this PR, the number should be significantly reduced, which will benefit performance.
This commit is contained in:
pengx17
2024-08-05 13:33:31 +00:00
parent 0acc1bd9e8
commit 0d7de67e01
5 changed files with 104 additions and 58 deletions
@@ -1,15 +1,19 @@
import { MemoryMemento } from '@toeverything/infra';
import { ipcRenderer } from 'electron';
import { AFFINE_API_CHANNEL_NAME } from '../shared/type';
const initialGlobalState = ipcRenderer.sendSync(
AFFINE_API_CHANNEL_NAME,
'sharedStorage:getAllGlobalState'
);
const initialGlobalCache = ipcRenderer.sendSync(
AFFINE_API_CHANNEL_NAME,
'sharedStorage:getAllGlobalCache'
);
function invokeWithCatch(key: string, ...args: any[]) {
ipcRenderer.invoke(key, ...args).catch(err => {
ipcRenderer.invoke(AFFINE_API_CHANNEL_NAME, key, ...args).catch(err => {
console.error(`Failed to invoke ${key}`, err);
});
}