import { Capacitor, registerPlugin } from '@capacitor/core'; export type PluginHostListItem = { id: string; name: string; version?: string; description?: string; author?: string; repository?: string; thumbnail?: string; homepage?: string; tags?: string[]; installedDate: string; path: string; }; export type PluginHostResult = { success: boolean; data?: T; error?: string; }; export interface PluginHostAPI { getPath: () => Promise>; download: ( pluginId: string, downloadUrl: string, name: string ) => Promise>; list: () => Promise>; uninstall: (pluginId: string) => Promise>; readPluginCode: (pluginId: string) => Promise>; } interface PluginStoragePlugin { getPath(): Promise>; download(options: { pluginId: string; downloadUrl: string; name: string; }): Promise>; list(): Promise>; uninstall(options: { pluginId: string }): Promise>; readPluginCode(options: { pluginId: string }): Promise>; } const PluginStorage = registerPlugin('PluginStorage'); const androidPluginHost: PluginHostAPI = { getPath: () => PluginStorage.getPath(), download: (pluginId, downloadUrl, name) => PluginStorage.download({ pluginId, downloadUrl, name }), list: () => PluginStorage.list(), uninstall: (pluginId) => PluginStorage.uninstall({ pluginId }), readPluginCode: (pluginId) => PluginStorage.readPluginCode({ pluginId }), }; /** Returns true when a native plugin filesystem host is available. */ export const isPluginHostSupported = (): boolean => getPluginHost() !== null; /** Returns the active plugin host for Electron or Android. */ export const getPluginHost = (): PluginHostAPI | null => { if (window.electron?.plugins) { return window.electron.plugins; } if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'android') { return androidPluginHost; } return null; };