fix(electron): fix electron global state sync (#7793)

This commit is contained in:
EYHN 2024-08-08 12:02:10 +00:00
parent 3d4fbcaebc
commit ffc12176c9
No known key found for this signature in database
GPG Key ID: 46C9E26A75AB276C

View File

@ -1,7 +1,10 @@
import { MemoryMemento } from '@toeverything/infra'; import { MemoryMemento } from '@toeverything/infra';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { AFFINE_API_CHANNEL_NAME } from '../shared/type'; import {
AFFINE_API_CHANNEL_NAME,
AFFINE_EVENT_CHANNEL_NAME,
} from '../shared/type';
const initialGlobalState = ipcRenderer.sendSync( const initialGlobalState = ipcRenderer.sendSync(
AFFINE_API_CHANNEL_NAME, AFFINE_API_CHANNEL_NAME,
@ -29,12 +32,14 @@ function createSharedStorageApi(
) { ) {
const memory = new MemoryMemento(); const memory = new MemoryMemento();
memory.setAll(init); memory.setAll(init);
ipcRenderer.on(`sharedStorage:${event}`, (_event, updates) => { ipcRenderer.on(AFFINE_EVENT_CHANNEL_NAME, (_event, channel, updates) => {
for (const [key, value] of Object.entries(updates)) { if (channel === `sharedStorage:${event}`) {
if (value === undefined) { for (const [key, value] of Object.entries(updates)) {
memory.del(key); if (value === undefined) {
} else { memory.del(key);
memory.set(key, value); } else {
memory.set(key, value);
}
} }
} }
}); });