refactor(electron): create electron api package (#5334)

This commit is contained in:
EYHN
2023-12-27 06:38:37 +00:00
parent ce17daba42
commit 4e861d8118
53 changed files with 307 additions and 690 deletions
@@ -0,0 +1,14 @@
{
"name": "@affine/electron-api",
"version": "0.10.3-canary.2",
"type": "module",
"private": true,
"main": "./src/index.ts",
"exports": {
".": "./src/index.ts"
},
"devDependencies": {
"@toeverything/infra": "workspace:*",
"electron": "^27.1.0"
}
}
@@ -0,0 +1,37 @@
import type {
events as helperEvents,
handlers as helperHandlers,
} from '@affine/electron/helper/exposed';
import type {
events as mainEvents,
handlers as mainHandlers,
} from '@affine/electron/main/exposed';
import type {
affine as exposedAffineGlobal,
appInfo as exposedAppInfo,
} from '@affine/electron/preload/electron-api';
type MainHandlers = typeof mainHandlers;
type HelperHandlers = typeof helperHandlers;
type HelperEvents = typeof helperEvents;
type MainEvents = typeof mainEvents;
type ClientHandler = {
[namespace in keyof MainHandlers]: {
[method in keyof MainHandlers[namespace]]: MainHandlers[namespace][method] extends (
arg0: any,
...rest: infer A
) => any
? (...args: A) => Promise<ReturnType<MainHandlers[namespace][method]>>
: never;
};
} & HelperHandlers;
type ClientEvents = MainEvents & HelperEvents;
export const appInfo = (window as any).appInfo as typeof exposedAppInfo | null;
export const apis = (window as any).apis as ClientHandler | null;
export const events = (window as any).events as ClientEvents | null;
export const affine = (window as any).affine as
| typeof exposedAffineGlobal
| null;
export type { UpdateMeta } from '@affine/electron/main/updater/event';
@@ -0,0 +1,17 @@
{
"extends": "../../../tsconfig.json",
"include": ["./src"],
"compilerOptions": {
"composite": true,
"noEmit": false,
"outDir": "lib"
},
"references": [
{
"path": "../../common/infra"
},
{
"path": "../../frontend/electron"
}
]
}