mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 07:06:28 +08:00
34 lines
1010 B
TypeScript
34 lines
1010 B
TypeScript
import { ipcRenderer } from 'electron';
|
|
|
|
export function listenWorkerApis() {
|
|
ipcRenderer.on('worker-connect', (ev, data) => {
|
|
const portForRenderer = ev.ports[0];
|
|
|
|
// @ts-expect-error this function should only be evaluated in the renderer process
|
|
if (document.readyState === 'complete') {
|
|
// @ts-expect-error this function should only be evaluated in the renderer process
|
|
window.postMessage(
|
|
{
|
|
type: 'electron:worker-connect',
|
|
portId: data.portId,
|
|
},
|
|
'*',
|
|
[portForRenderer]
|
|
);
|
|
} else {
|
|
// @ts-expect-error this function should only be evaluated in the renderer process
|
|
window.addEventListener('load', () => {
|
|
// @ts-expect-error this function should only be evaluated in the renderer process
|
|
window.postMessage(
|
|
{
|
|
type: 'electron:worker-connect',
|
|
portId: data.portId,
|
|
},
|
|
'*',
|
|
[portForRenderer]
|
|
);
|
|
});
|
|
}
|
|
});
|
|
}
|