feat: 插件卸载

pull/13/head
moonrailgun 4 years ago
parent f08b122322
commit 33a43db935

@ -1,8 +1,9 @@
import { Avatar } from '@/components/Avatar'; import { Avatar } from '@/components/Avatar';
import { Button } from 'antd'; import { Button } from 'antd';
import React, { useState } from 'react'; import React, { useCallback, useState } from 'react';
import { import {
PluginManifest, PluginManifest,
showAlert,
showToasts, showToasts,
t, t,
useAsyncRequest, useAsyncRequest,
@ -30,6 +31,16 @@ export const PluginStoreItem: React.FC<{
setInstalled(true); setInstalled(true);
}, [manifest]); }, [manifest]);
const handleUninstallPlugin = useCallback(() => {
showAlert({
message: t('是否要卸载插件'),
onConfirm: async () => {
await pluginManager.uninstallPlugin(manifest.name);
showToasts(t('插件卸载成功, 需要重启后生效'), 'success');
},
});
}, [manifest]);
return ( return (
<div className="rounded-md flex w-80 h-36 bg-black bg-opacity-40 py-2 px-3"> <div className="rounded-md flex w-80 h-36 bg-black bg-opacity-40 py-2 px-3">
<div className="flex w-full"> <div className="flex w-full">
@ -49,10 +60,12 @@ export const PluginStoreItem: React.FC<{
<div className="mt-1 text-right"> <div className="mt-1 text-right">
{builtin ? ( {builtin ? (
<Button type="primary" disabled={true}> <Button type="primary" disabled={true}>
{t('已安装')} {t('内置插件')}
</Button> </Button>
) : installed ? ( ) : installed ? (
<Button type="primary">{t('已安装')}</Button> <Button type="primary" onClick={handleUninstallPlugin}>
{t('已安装')}
</Button>
) : ( ) : (
<Button <Button
type="primary" type="primary"

@ -73,6 +73,20 @@ class PluginManager {
url: manifest.url, url: manifest.url,
}); });
} }
/**
*
*/
async uninstallPlugin(pluginName: string) {
const plugins: PluginManifest[] = await getStorage().get(
PluginManager.STORE_KEY
);
const index = plugins.findIndex((plugin) => plugin.name === pluginName);
if (index >= 0) {
plugins.splice(index, 1);
await getStorage().save(PluginManager.STORE_KEY, plugins);
}
}
} }
export const pluginManager = new PluginManager(); export const pluginManager = new PluginManager();

Loading…
Cancel
Save