mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
32 lines
696 B
TypeScript
32 lines
696 B
TypeScript
import type {
|
|
HelperToMain,
|
|
MainToHelper,
|
|
} from '@toeverything/infra/preload/electron';
|
|
import { AsyncCall } from 'async-call-rpc';
|
|
|
|
import { getExposedMeta } from './exposed';
|
|
|
|
const helperToMainServer: HelperToMain = {
|
|
getMeta: () => getExposedMeta(),
|
|
};
|
|
|
|
export const mainRPC = AsyncCall<MainToHelper>(helperToMainServer, {
|
|
strict: {
|
|
unknownMessage: false,
|
|
},
|
|
channel: {
|
|
on(listener) {
|
|
const f = (e: Electron.MessageEvent) => {
|
|
listener(e.data);
|
|
};
|
|
process.parentPort.on('message', f);
|
|
return () => {
|
|
process.parentPort.off('message', f);
|
|
};
|
|
},
|
|
send(data) {
|
|
process.parentPort.postMessage(data);
|
|
},
|
|
},
|
|
});
|