mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 15:03:11 +02:00
Install plugins from Yaak plugin registry (#230)
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { BootResponse } from '@yaakapp-internal/plugins';
|
||||
import type { Plugin } from '@yaakapp-internal/models';
|
||||
import { pluginsAtom } from '@yaakapp-internal/models';
|
||||
import type { PluginMetadata } from '@yaakapp-internal/plugins';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { queryClient } from '../lib/queryClient';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
function pluginInfoKey(id: string) {
|
||||
return ['plugin_info', id];
|
||||
function pluginInfoKey(id: string, plugin: Plugin | null) {
|
||||
return ['plugin_info', id, plugin?.updatedAt ?? 'n/a'];
|
||||
}
|
||||
|
||||
export function usePluginInfo(id: string) {
|
||||
const plugins = useAtomValue(pluginsAtom);
|
||||
// Get the plugin so we can refetch whenever it's updated
|
||||
const plugin = plugins.find((p) => p.id === id);
|
||||
return useQuery({
|
||||
queryKey: pluginInfoKey(id),
|
||||
queryFn: () => invokeCmd<BootResponse>('cmd_plugin_info', { id }),
|
||||
queryKey: pluginInfoKey(id, plugin ?? null),
|
||||
placeholderData: (prev) => prev, // Keep previous data on refetch
|
||||
queryFn: () => invokeCmd<PluginMetadata>('cmd_plugin_info', { id }),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useUninstallPlugin() {
|
||||
return useFastMutation({
|
||||
mutationKey: ['uninstall_plugin'],
|
||||
mutationFn: async (pluginId: string) => {
|
||||
return invokeCmd('cmd_uninstall_plugin', { pluginId });
|
||||
},
|
||||
});
|
||||
}
|
||||
25
src-web/hooks/useUninstallPlugin.tsx
Normal file
25
src-web/hooks/useUninstallPlugin.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import React from 'react';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { showConfirmDelete } from '../lib/confirm';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useUninstallPlugin() {
|
||||
return useFastMutation({
|
||||
mutationKey: ['uninstall_plugin'],
|
||||
mutationFn: async ({ pluginId, name }: { pluginId: string; name: string }) => {
|
||||
const confirmed = await showConfirmDelete({
|
||||
id: 'uninstall-plugin-' + name,
|
||||
title: 'Uninstall Plugin',
|
||||
description: (
|
||||
<>
|
||||
Permanently uninstall <InlineCode>{name}</InlineCode>?
|
||||
</>
|
||||
),
|
||||
});
|
||||
if (confirmed) {
|
||||
await invokeCmd('cmd_uninstall_plugin', { pluginId });
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user