MCPcopy
hub / github.com/nukeop/nuclear / useInstallPlugin

Function useInstallPlugin

packages/player/src/hooks/useInstallPlugin.ts:22–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20};
21
22export 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};

Callers 1

PluginStoreFunction · 0.90

Calls 6

downloadAndExtractPluginFunction · 0.90
upsertRegistryEntryFunction · 0.90
cleanupDownloadFunction · 0.90
resolveErrorMessageFunction · 0.90
errorMethod · 0.80
getLatestReleaseMethod · 0.45

Tested by

no test coverage detected