mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 11:36:25 +08:00
feat: add infra code (#2718)
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
import type {
|
||||
DBHandlerManager,
|
||||
DebugHandlerManager,
|
||||
DialogHandlerManager,
|
||||
ExportHandlerManager,
|
||||
UIHandlerManager,
|
||||
UpdaterHandlerManager,
|
||||
WorkspaceHandlerManager,
|
||||
} from '@toeverything/infra';
|
||||
import type { HandlerManager, PrimitiveHandlers } from '@toeverything/infra';
|
||||
import { ipcMain } from 'electron';
|
||||
|
||||
import { dbHandlers } from './db';
|
||||
import { dialogHandlers } from './dialog';
|
||||
import { exportHandlers } from './export';
|
||||
import { getLogFilePath, logger, revealLogFile } from './logger';
|
||||
import type { NamespaceHandlers } from './type';
|
||||
import { uiHandlers } from './ui';
|
||||
import { updaterHandlers } from './updater';
|
||||
import { workspaceHandlers } from './workspace';
|
||||
@@ -18,6 +27,26 @@ export const debugHandlers = {
|
||||
},
|
||||
};
|
||||
|
||||
type UnwrapManagerHandler<
|
||||
Manager extends HandlerManager<string, Record<string, PrimitiveHandlers>>
|
||||
> = {
|
||||
[K in keyof Manager['handlers']]: Manager['handlers'][K] extends (
|
||||
...args: infer Args
|
||||
) => Promise<infer R>
|
||||
? (event: Electron.IpcMainInvokeEvent, ...args: Args) => Promise<R>
|
||||
: never;
|
||||
};
|
||||
|
||||
type AllHandlers = {
|
||||
db: UnwrapManagerHandler<DBHandlerManager>;
|
||||
debug: UnwrapManagerHandler<DebugHandlerManager>;
|
||||
dialog: UnwrapManagerHandler<DialogHandlerManager>;
|
||||
export: UnwrapManagerHandler<ExportHandlerManager>;
|
||||
ui: UnwrapManagerHandler<UIHandlerManager>;
|
||||
updater: UnwrapManagerHandler<UpdaterHandlerManager>;
|
||||
workspace: UnwrapManagerHandler<WorkspaceHandlerManager>;
|
||||
};
|
||||
|
||||
// Note: all of these handlers will be the single-source-of-truth for the apis exposed to the renderer process
|
||||
export const allHandlers = {
|
||||
db: dbHandlers,
|
||||
@@ -27,7 +56,7 @@ export const allHandlers = {
|
||||
export: exportHandlers,
|
||||
updater: updaterHandlers,
|
||||
workspace: workspaceHandlers,
|
||||
} satisfies Record<string, NamespaceHandlers>;
|
||||
} satisfies AllHandlers;
|
||||
|
||||
export const registerHandlers = () => {
|
||||
// TODO: listen to namespace instead of individual event types
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"@electron-forge/maker-zip": "^6.1.1",
|
||||
"@electron-forge/shared-types": "^6.1.1",
|
||||
"@electron/remote": "2.0.9",
|
||||
"@toeverything/infra": "workspace:*",
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"@types/uuid": "^9.0.1",
|
||||
"cross-env": "7.0.3",
|
||||
|
||||
@@ -46,7 +46,7 @@ export const config = () => {
|
||||
bundle: true,
|
||||
target: `node${NODE_MAJOR_VERSION}`,
|
||||
platform: 'node',
|
||||
external: ['electron', 'yjs', 'electron-updater'],
|
||||
external: ['electron', 'yjs', 'electron-updater', '@toeverything/infra'],
|
||||
define: define,
|
||||
format: 'cjs',
|
||||
loader: {
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
{
|
||||
"path": "../../packages/env"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/infra"
|
||||
},
|
||||
{ "path": "../../tests/kit" }
|
||||
],
|
||||
"ts-node": {
|
||||
|
||||
@@ -112,6 +112,7 @@ const nextConfig = {
|
||||
'@affine/copilot',
|
||||
'@toeverything/hooks',
|
||||
'@toeverything/y-indexeddb',
|
||||
'@toeverything/infra',
|
||||
'@toeverything/plugin-infra',
|
||||
],
|
||||
publicRuntimeConfig: {
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"@react-hookz/web": "^23.0.1",
|
||||
"@sentry/nextjs": "^7.54.0",
|
||||
"@toeverything/hooks": "workspace:*",
|
||||
"@toeverything/infra": "workspace:*",
|
||||
"@toeverything/plugin-infra": "workspace:*",
|
||||
"cmdk": "^0.2.0",
|
||||
"css-spring": "^4.1.0",
|
||||
|
||||
@@ -50,10 +50,8 @@ rootWorkspacesMetadataAtom.onMount = setAtom => {
|
||||
}, 0);
|
||||
|
||||
if (environment.isDesktop) {
|
||||
// @ts-expect-error
|
||||
window.apis?.workspace.list().then(workspaceIDs => {
|
||||
if (abortController.signal.aborted) return;
|
||||
// @ts-expect-error
|
||||
const newMetadata = workspaceIDs.map(w => ({
|
||||
id: w[0],
|
||||
flavour: WorkspaceFlavour.LOCAL,
|
||||
@@ -61,7 +59,6 @@ rootWorkspacesMetadataAtom.onMount = setAtom => {
|
||||
setAtom(metadata => {
|
||||
return [
|
||||
...metadata,
|
||||
// @ts-expect-error
|
||||
...newMetadata.filter(m => !metadata.find(m2 => m2.id === m.id)),
|
||||
];
|
||||
});
|
||||
|
||||
@@ -122,7 +122,6 @@ const useDefaultDBLocation = () => {
|
||||
const [defaultDBLocation, setDefaultDBLocation] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
// @ts-expect-error
|
||||
window.apis?.db.getDefaultStorageLocation().then(dir => {
|
||||
setDefaultDBLocation(dir);
|
||||
});
|
||||
|
||||
@@ -27,7 +27,6 @@ const useShowOpenDBFile = (workspaceId: string) => {
|
||||
const [show, setShow] = useState(false);
|
||||
useEffect(() => {
|
||||
if (window.apis && window.events && environment.isDesktop) {
|
||||
// @ts-expect-error
|
||||
window.apis.workspace.getMeta(workspaceId).then(meta => {
|
||||
setShow(!!meta.secondaryDBPath);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user