diff --git a/src/controller/language/pack/zh-cn.json b/src/controller/language/pack/zh-cn.json index 04bb40c..2d1a345 100644 --- a/src/controller/language/pack/zh-cn.json +++ b/src/controller/language/pack/zh-cn.json @@ -18,11 +18,13 @@ "user": "用户", "pass": "密码", "save": "保存", + "save_successfully": "保存成功", "step_back": "返回", "step_next": "下一步", "storage_introduce": "存储介绍", "show_advanced_options": "显示高级选项", "please_input": "请输入", + "optional": "可选", "Input_and_press_enter": "输入并回车", "missing_parameter": "缺少参数", "StorageName": "存储名称", diff --git a/src/controller/storage/mount/mount.ts b/src/controller/storage/mount/mount.ts index e936d89..b930da6 100644 --- a/src/controller/storage/mount/mount.ts +++ b/src/controller/storage/mount/mount.ts @@ -7,6 +7,7 @@ import { ParametersType } from "../../../type/defaults" import { rclone_api_post } from "../../../utils/rclone/request" import { fs_exist_dir, fs_make_dir } from "../../../utils/utils" import { convertStoragePath, formatPathRclone } from "../storage" +import { MountOptions, VfsOptions } from "../../../type/rclone/storage/mount/parameters" //列举存储 @@ -17,11 +18,11 @@ async function reupMount(noRefreshUI?: boolean) { )).mountPoints || [] rcloneInfo.mountList = []; - + mountPoints.forEach((tiem: any) => { const name = tiem.Fs rcloneInfo.mountList.push({ - storageName:name, //name.substring(0, name.length - 1) + storageName: name, //name.substring(0, name.length - 1) mountPath: tiem.MountPoint, mountedTime: new Date(tiem.MountedOn), }) @@ -37,7 +38,7 @@ function isMounted(mountPath: string): boolean { return rcloneInfo.mountList.findIndex((item) => item.mountPath === mountPath) !== -1 } -async function addMountStorage(storageName: string, mountPath: string, parameters: ParametersType, autoMount?: boolean) { +async function addMountStorage(storageName: string, mountPath: string, parameters: { vfsOpt: VfsOptions, mountOpt: MountOptions }, autoMount?: boolean) { if (getMountStorage(mountPath)) { return false } @@ -71,7 +72,7 @@ async function delMountStorage(mountPath: string) { async function editMountStorage(mountInfo: MountListItem) { - await reupMount() + //await reupMount() //觉得这里是不必要的,就注释了 /*rcloneInfo.mountList.forEach((item) => { if (item.mountPath === mountInfo.mountPath) { @@ -79,12 +80,15 @@ async function editMountStorage(mountInfo: MountListItem) { } }) */ - const index = nmConfig.mount.lists.findIndex((item) => item.mountPath === mountInfo.mountPath) - if (index !== -1) { - nmConfig.mount.lists[index] = mountInfo + for (let i = 0; i < nmConfig.mount.lists.length; i++) { + if (nmConfig.mount.lists[i].mountPath === mountInfo.mountPath) { + nmConfig.mount.lists[i] = mountInfo + break + } } + await saveNmConfig() } @@ -94,7 +98,7 @@ async function mountStorage(mountInfo: MountListItem) { } const back = await rclone_api_post('/mount/mount', { - fs:convertStoragePath( mountInfo.storageName )|| mountInfo.storageName, + fs: convertStoragePath(mountInfo.storageName) || mountInfo.storageName, mountPoint: mountInfo.mountPath, ...(mountInfo.parameters) }) diff --git a/src/controller/storage/mount/parameters/defaults.ts b/src/controller/storage/mount/parameters/defaults.ts index cde11e1..bd989e7 100644 --- a/src/controller/storage/mount/parameters/defaults.ts +++ b/src/controller/storage/mount/parameters/defaults.ts @@ -6,7 +6,7 @@ const vfsCacheModeParam: StorageParamItemType = { name: 'CacheMode', description: 'CacheMode', type: 'string', - default: 'full', + default: 'minimal', required: false, advanced: false, isPassword: false, diff --git a/src/page/mount/add.tsx b/src/page/mount/add.tsx index 925a7db..79af8d1 100644 --- a/src/page/mount/add.tsx +++ b/src/page/mount/add.tsx @@ -6,16 +6,18 @@ import { ParametersType } from '../../type/defaults'; import { formatPath, getProperties, getURLSearchParam, getWinFspInstallState, showPathInExplorer } from '../../utils/utils'; import { defaultMountConfig, defaultVfsConfig, vfsCacheModeParam } from '../../controller/storage/mount/parameters/defaults'; import { rcloneInfo } from '../../services/rclone'; -import { addMountStorage, getAvailableDriveLetter, getMountStorage, mountStorage } from '../../controller/storage/mount/mount'; +import { addMountStorage, editMountStorage, getAvailableDriveLetter, getMountStorage, mountStorage } from '../../controller/storage/mount/mount'; import { osInfo } from '../../services/config'; import { homeDir } from '@tauri-apps/api/path'; import { InputForm_module, paramsType2FormItems } from '../other/InputForm'; import { filterHideStorage } from '../../controller/storage/storage'; +import { MountOptions, VfsOptions } from '../../type/rclone/storage/mount/parameters'; const FormItem = Form.Item; const CollapseItem = Collapse.Item; + export default function AddMount_page() { const { t } = useTranslation() const navigate = useNavigate(); @@ -25,15 +27,17 @@ export default function AddMount_page() { const [autoMount, setAutoMount] = useState(true) //const [autoMountPath, setAutoMountPath] = useState(true)//自动分配盘符 //const [notification, contextHolder] = Notification.useNotification(); + const [parameters, setParameters] = useState<{ vfsOpt: VfsOptions, mountOpt: MountOptions }>({ mountOpt: defaultMountConfig, vfsOpt: defaultVfsConfig }) const [vfsOptFormHook, setVfsOptFormHook] = useState();//表单实例 const [mountOptFormHook, setMountOptFormHook] = useState();//表单实例 - const RadioGroup = Radio.Group; - const storageList=filterHideStorage(rcloneInfo.storageList) + const RadioGroup = Radio.Group; + const storageList = filterHideStorage(rcloneInfo.storageList) + const isEditMode = (getURLSearchParam('edit') === 'true') const isWindows = rcloneInfo.version.os.toLowerCase().includes('windows'); - let parameters: ParametersType = { mountOpt: {}, vfsOpt: {} } - + const isMountPathCustom = mountPath !== '*' && !mountPath.startsWith('~/Desktop/'); + const mountPathuIsDriveLetter = isWindows && (mountPath === '*' || mountPath.endsWith(':') || mountPath.endsWith(':/')); const checkWinFspState = async () => { @@ -50,8 +54,22 @@ export default function AddMount_page() { } } + const editMode = () => { + let mountPathTemp = getURLSearchParam('mountPath') + const mount = getMountStorage(mountPathTemp) + if (mount) { + setStorageName(mount.storageName) + setMountPath(mount.mountPath) + setAutoMount(mount.autoMount) + setParameters(mount.parameters as { vfsOpt: VfsOptions, mountOpt: MountOptions }) + } + } + useEffect(() => { setMountPath(mountPath.replace(/\\/g, '/').replace(/\/+/g, '/')) + /* if (mountPathuIsDriveLetter) { + mountOptFormHook && mountOptFormHook.setFieldsValue({ VolumeName: storageName }) + } */ }, [mountPath]) useEffect(() => { @@ -70,6 +88,10 @@ export default function AddMount_page() { } else if (!storageName) { setStorageName(storageList[0].name) } + + if (isEditMode) { + editMode() + } }, []) useEffect(() => { @@ -77,6 +99,8 @@ export default function AddMount_page() { if (isWindows) { //setMountPath('*') setMountPath('~/Desktop/' + storageName) + + } else { if (storageName) { if (rcloneInfo.version.os.toLowerCase().includes('darwin')) { @@ -88,7 +112,10 @@ export default function AddMount_page() { } }, [storageName]) - const isMountPathCustom = mountPath !== '*' && !mountPath.startsWith('~/Desktop/'); + useEffect(() => { + vfsOptFormHook && vfsOptFormHook.setFieldsValue(parameters.vfsOpt); + mountOptFormHook && mountOptFormHook.setFieldsValue(parameters.mountOpt) + }, [vfsOptFormHook, mountOptFormHook]) return ( @@ -110,8 +137,7 @@ export default function AddMount_page() { - - +