diff --git a/core/src/api/index.ts b/core/src/api/index.ts index 828ae43b91..490d9e5e7e 100644 --- a/core/src/api/index.ts +++ b/core/src/api/index.ts @@ -85,9 +85,17 @@ export type FileSystemRouteFunctions = { [K in FileSystemRoute]: ApiFunction } -export type APIRoutes = AppRouteFunctions & +export type APIFunctions = AppRouteFunctions & AppEventFunctions & DownloadRouteFunctions & DownloadEventFunctions & ExtensionRouteFunctions & FileSystemRouteFunctions + +export const APIRoutes = [ + ...Object.values(AppRoute), + ...Object.values(DownloadRoute), + ...Object.values(ExtensionRoute), + ...Object.values(FileSystemRoute), +] +export const APIEvents = [...Object.values(AppEvent), ...Object.values(DownloadEvent)] diff --git a/electron/package.json b/electron/package.json index 627f5ad541..623071e38d 100644 --- a/electron/package.json +++ b/electron/package.json @@ -67,6 +67,7 @@ "build:publish:linux": "tsc -p . && electron-builder -p onTagOrDraft -l deb" }, "dependencies": { + "@janhq/core": "link:./core", "@npmcli/arborist": "^7.1.0", "@types/request": "^2.48.12", "@uiball/loaders": "^1.3.0", diff --git a/electron/preload.ts b/electron/preload.ts index b13976f71a..ff45fbf023 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -3,33 +3,18 @@ * @module preload */ -import { - AppEvent, - AppRoute, - DownloadEvent, - DownloadRoute, - ExtensionRoute, - FileSystemRoute, -} from '@janhq/core' +import { APIEvents, APIRoutes, AppEvent, DownloadEvent } from '@janhq/core' const { contextBridge } = require('electron') const { ipcRenderer } = require('electron') -const ipcMethods = [ - ...Object.values(AppRoute), - ...Object.values(DownloadRoute), - ...Object.values(ExtensionRoute), - ...Object.values(FileSystemRoute), -] - -const ipcEvents = [...Object.values(AppEvent), ...Object.values(DownloadEvent)] const interfaces: { [key: string]: (...args: any[]) => any } = {} -ipcMethods.forEach((method) => { +APIRoutes.forEach((method) => { interfaces[method] = (...args: any[]) => ipcRenderer.invoke(method, ...args) }) -ipcEvents.forEach((method) => { +APIEvents.forEach((method) => { interfaces[method] = (handler: any) => ipcRenderer.on(method, handler) }) diff --git a/web/types/index.d.ts b/web/types/index.d.ts index 8208f128bf..ddb608a7aa 100644 --- a/web/types/index.d.ts +++ b/web/types/index.d.ts @@ -1,4 +1,4 @@ -import { APIRoutes } from '@janhq/core' +import { APIFunctions } from '@janhq/core' /* eslint-disable @typescript-eslint/no-explicit-any */ export {} @@ -7,7 +7,7 @@ declare global { declare const PLUGIN_CATALOG: string declare const VERSION: string interface Core { - api: APIRoutes + api: APIFunctions events: EventEmitter } interface Window {