export interface WorkspaceMeta { id: string; mainDBPath: string; secondaryDBPath?: string; // assume there will be only one } export type PrimitiveHandlers = (...args: any[]) => Promise; type TODO = any; export abstract class HandlerManager< Namespace extends string, Handlers extends Record > { abstract readonly app: TODO; abstract readonly namespace: Namespace; abstract readonly handlers: Handlers; } type DBHandlers = { getDocAsUpdates: (id: string) => Promise; applyDocUpdate: (id: string, update: Uint8Array) => Promise; addBlob: ( workspaceId: string, key: string, data: Uint8Array ) => Promise; getBlob: (workspaceId: string, key: string) => Promise; deleteBlob: (workspaceId: string, key: string) => Promise; getBlobKeys: (workspaceId: string) => Promise; getDefaultStorageLocation: () => Promise; }; export abstract class DBHandlerManager extends HandlerManager< 'db', DBHandlers > {} type DebugHandlers = { revealLogFile: () => Promise; logFilePath: () => Promise; }; export abstract class DebugHandlerManager extends HandlerManager< 'debug', DebugHandlers > {} type DialogHandlers = { revealDBFile: (workspaceId: string) => Promise; loadDBFile: () => Promise; saveDBFileAs: (workspaceId: string) => Promise; moveDBFile: (workspaceId: string, dbFileLocation?: string) => Promise; selectDBFileLocation: () => Promise; setFakeDialogResult: (result: any) => Promise; }; export abstract class DialogHandlerManager extends HandlerManager< 'dialog', DialogHandlers > {} type UIHandlers = { handleThemeChange: (theme: 'system' | 'light' | 'dark') => Promise; handleSidebarVisibilityChange: (visible: boolean) => Promise; handleMinimizeApp: () => Promise; handleMaximizeApp: () => Promise; handleCloseApp: () => Promise; getGoogleOauthCode: () => Promise; }; export abstract class UIHandlerManager extends HandlerManager< 'ui', UIHandlers > {} type ExportHandlers = { savePDFFileAs: (title: string) => Promise; }; export abstract class ExportHandlerManager extends HandlerManager< 'export', ExportHandlers > {} type UpdaterHandlers = { currentVersion: () => Promise; quitAndInstall: () => Promise; checkForUpdatesAndNotify: () => Promise; }; export abstract class UpdaterHandlerManager extends HandlerManager< 'updater', UpdaterHandlers > {} type WorkspaceHandlers = { list: () => Promise<[workspaceId: string, meta: WorkspaceMeta][]>; delete: (id: string) => Promise; getMeta: (id: string) => Promise; }; export abstract class WorkspaceHandlerManager extends HandlerManager< 'workspace', WorkspaceHandlers > {} export type UnwrapManagerHandlerToServerSide< ElectronEvent extends { frameId: number; processId: number; }, Manager extends HandlerManager> > = { [K in keyof Manager['handlers']]: Manager['handlers'][K] extends ( ...args: infer Args ) => Promise ? (event: ElectronEvent, ...args: Args) => Promise : never; }; export type UnwrapManagerHandlerToClientSide< Manager extends HandlerManager> > = { [K in keyof Manager['handlers']]: Manager['handlers'][K] extends ( ...args: infer Args ) => Promise ? (...args: Args) => Promise : never; };