mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
chore: standardize tsconfig (#9568)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// Please add modules to `external` in `rollupOptions` to avoid wrong bundling.
|
||||
import type { MessagePort } from 'node:worker_threads';
|
||||
|
||||
import type { EventBasedChannel } from 'async-call-rpc';
|
||||
import { AsyncCall } from 'async-call-rpc';
|
||||
import { ipcRenderer } from 'electron';
|
||||
@@ -135,12 +137,13 @@ const helperPort = new Promise<MessagePort>(resolve =>
|
||||
const createMessagePortChannel = (port: MessagePort): EventBasedChannel => {
|
||||
return {
|
||||
on(listener) {
|
||||
port.onmessage = e => {
|
||||
const listen = (e: MessageEvent) => {
|
||||
listener(e.data);
|
||||
};
|
||||
port.addEventListener('message', listen as any);
|
||||
port.start();
|
||||
return () => {
|
||||
port.onmessage = null;
|
||||
port.removeEventListener('message', listen as any);
|
||||
try {
|
||||
port.close();
|
||||
} catch (err) {
|
||||
@@ -246,10 +249,15 @@ export const events = {
|
||||
...helperAPIs.events,
|
||||
};
|
||||
|
||||
// Create MessagePort that can be used by web workers
|
||||
/**
|
||||
* Create MessagePort that can be used by web workers
|
||||
*
|
||||
* !!!
|
||||
* SHOULD ONLY BE USED IN RENDERER PROCESS
|
||||
* !!!
|
||||
*/
|
||||
export function requestWebWorkerPort() {
|
||||
const ch = new MessageChannel();
|
||||
|
||||
const localPort = ch.port1;
|
||||
const remotePort = ch.port2;
|
||||
|
||||
@@ -274,6 +282,7 @@ export function requestWebWorkerPort() {
|
||||
const portId = crypto.randomUUID();
|
||||
|
||||
setTimeout(() => {
|
||||
// @ts-expect-error this function should only be evaluated in the renderer process
|
||||
window.postMessage(
|
||||
{
|
||||
type: 'electron:request-api-port',
|
||||
|
||||
Reference in New Issue
Block a user