()
| 20 | }; |
| 21 | |
| 22 | export const useInstallPlugin = () => { |
| 23 | const { t } = useTranslation('plugins'); |
| 24 | const loadPluginFromPath = usePluginStore((s) => s.loadPluginFromPath); |
| 25 | const enablePlugin = usePluginStore((s) => s.enablePlugin); |
| 26 | |
| 27 | return useMutation({ |
| 28 | mutationFn: async ({ plugin }: InstallPluginParams) => { |
| 29 | const release = await pluginMarketplaceApi.getLatestRelease(plugin.repo); |
| 30 | |
| 31 | const extractedPath = await downloadAndExtractPlugin({ |
| 32 | pluginId: plugin.id, |
| 33 | downloadUrl: release.downloadUrl, |
| 34 | }); |
| 35 | |
| 36 | try { |
| 37 | const now = new Date().toISOString(); |
| 38 | await upsertRegistryEntry({ |
| 39 | id: plugin.id, |
| 40 | version: release.version, |
| 41 | path: extractedPath, |
| 42 | installationMethod: 'store', |
| 43 | enabled: false, |
| 44 | installedAt: now, |
| 45 | lastUpdatedAt: now, |
| 46 | }); |
| 47 | |
| 48 | await loadPluginFromPath(extractedPath); |
| 49 | await enablePlugin(plugin.id); |
| 50 | } finally { |
| 51 | await cleanupDownload(plugin.id); |
| 52 | } |
| 53 | |
| 54 | return { plugin, version: release.version }; |
| 55 | }, |
| 56 | onError: (error, { plugin }) => { |
| 57 | const message = resolveErrorMessage(error); |
| 58 | toast.error(t('store.installError.title', { name: plugin.name }), { |
| 59 | description: message, |
| 60 | }); |
| 61 | }, |
| 62 | }); |
| 63 | }; |
no test coverage detected