Skip to content

Commit

Permalink
feat: Uninstall Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Sep 3, 2023
1 parent db314f5 commit 0fedea5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ pub fn install_plugin(path_list: Vec<String>, plugin_type: &str) -> Result<i32,
_ => return Err(Error::Error("Unknown OS".into())),
};
for path in path_list {
if !path.ends_with("zip") {
if !path.ends_with("potext") {
continue;
}
let path = std::path::Path::new(&path);
let file_name = path.file_name().unwrap().to_str().unwrap();
let file_name = file_name.replace(".zip", "");
let file_name = file_name.replace(".potext", "");
if !file_name.starts_with("[plugin]") {
return Err(Error::Error(
"Invalid Plugin: file name must start with [plugin]".into(),
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"add_external_service": "Add Extension",
"add_service": "Add Service",
"test_failed": "Test Failed",
"install_plugin": "Install Plugin"
"install_plugin": "Install Plugin",
"uninstall_success": "Plugin Uninstall Successfully"
},
"history": {
"label": "History",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"add_external_service": "添加外部插件",
"add_service": "添加服务",
"test_failed": "测试失败",
"install_plugin": "安装外部插件"
"install_plugin": "安装外部插件",
"uninstall_success": "插件卸载成功"
},
"history": {
"label": "历史记录",
Expand Down
2 changes: 1 addition & 1 deletion src/window/Config/pages/Backup/WebDavModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function WebDavModal(props) {
scrollBehavior='inside'
>
<Toaster />
<ModalContent>
<ModalContent className='max-h-[80vh]'>
{(onClose) => (
<>
<ModalHeader>{t('config.backup.list')}</ModalHeader>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Button } from '@nextui-org/react';
import { removeDir, BaseDirectory } from '@tauri-apps/api/fs';
import toast, { Toaster } from 'react-hot-toast';
import { MdDeleteOutline } from 'react-icons/md';
import { useTranslation } from 'react-i18next';
import { open } from '@tauri-apps/api/dialog';
import { invoke } from '@tauri-apps/api';
import React, { useState } from 'react';
import { useAtomValue } from 'jotai';
import React from 'react';

import { useToastStyle } from '../../../../../../hooks';
import { pluginListAtom } from '..';

export default function SelectPluginModal(props) {
const { isOpen, onOpenChange, setConfigName, onConfigOpen } = props;
const { isOpen, onOpenChange, setConfigName, onConfigOpen, getPluginList } = props;
const [installing, setInstalling] = useState(false);
const pluginList = useAtomValue(pluginListAtom);
const { t } = useTranslation();
const toastStyle = useToastStyle();
Expand All @@ -29,32 +32,61 @@ export default function SelectPluginModal(props) {
<ModalBody>
{Object.keys(pluginList).map((x) => {
return (
<div key={x}>
<div
className='flex justify-between'
key={x}
>
<Button
fullWidth
className='mr-[8px]'
onPress={() => {
setConfigName(x);
onConfigOpen();
}}
>
<div className='w-full'>{pluginList[x].display}</div>
</Button>
<Button
isIconOnly
color='danger'
variant='flat'
onPress={() => {
removeDir(`plugins/translate/${x}`, {
dir: BaseDirectory.AppConfig,
recursive: true,
}).then(
(v) => {
toast.success(t('config.service.delete_success'), {
style: toastStyle,
});
getPluginList();
},
(e) => {
toast.error(e.toString(), { style: toastStyle });
}
);
}}
>
<MdDeleteOutline className='text-xl' />
</Button>
</div>
);
})}
<div>
<Button
fullWidth
isLoading={installing}
color='secondary'
variant='flat'
onPress={async () => {
setInstalling(true);
const selected = await open({
multiple: true,
directory: false,
filters: [
{
name: 'Plugin',
extensions: ['zip'],
name: '*.potext',
extensions: ['potext'],
},
],
});
Expand All @@ -64,14 +96,19 @@ export default function SelectPluginModal(props) {
pluginType: 'translate',
}).then(
(count) => {
setInstalling(false);
toast.success('Installed ' + count + ' plugins', {
style: toastStyle,
});
getPluginList();
},
(e) => {
setInstalling(false);
toast.error(e.toString(), { style: toastStyle });
}
);
} else {
setInstalling(false);
}
}}
>
Expand Down
8 changes: 7 additions & 1 deletion src/window/Config/pages/Service/Translate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export default function Translate() {
setTranslateServiceList(newList);
}
};
useEffect(() => {

const getPluginList = () => {
readDir('plugins/translate', { dir: BaseDirectory.AppConfig }).then((plugins) => {
let temp = {};
for (const plugin of plugins) {
Expand All @@ -75,6 +76,10 @@ export default function Translate() {
}
setPluginList(temp);
});
};

useEffect(() => {
getPluginList();
}, []);

return (
Expand Down Expand Up @@ -147,6 +152,7 @@ export default function Translate() {
onOpenChange={onSelectPluginOpenChange}
setConfigName={setOpenConfigName}
onConfigOpen={onConfigOpen}
getPluginList={getPluginList}
/>
<SelectModal
isOpen={isSelectOpen}
Expand Down

0 comments on commit 0fedea5

Please sign in to comment.