mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 12:43:45 +08:00
feat: Support drag and drop local files
This commit is contained in:
parent
bd6f02f6af
commit
7a3cc7d242
@ -37,7 +37,7 @@ serde = { version = "1.0", features = ["derive"] }
|
|||||||
reqwest = { version = "0.12", features = ["json", "rustls-tls"] }
|
reqwest = { version = "0.12", features = ["json", "rustls-tls"] }
|
||||||
sysproxy = { git="https://github.com/zzzgydi/sysproxy-rs", branch = "main" }
|
sysproxy = { git="https://github.com/zzzgydi/sysproxy-rs", branch = "main" }
|
||||||
auto-launch = { git="https://github.com/zzzgydi/auto-launch", branch = "main" }
|
auto-launch = { git="https://github.com/zzzgydi/auto-launch", branch = "main" }
|
||||||
tauri = { version = "1.6", features = [ "fs-exists", "path-all", "protocol-asset", "dialog-open", "notification-all", "icon-png", "icon-ico", "clipboard-all", "global-shortcut-all", "process-all", "shell-all", "system-tray", "updater", "window-all", "devtools"] }
|
tauri = { version = "1.6", features = [ "fs-read-file", "fs-exists", "path-all", "protocol-asset", "dialog-open", "notification-all", "icon-png", "icon-ico", "clipboard-all", "global-shortcut-all", "process-all", "shell-all", "system-tray", "updater", "window-all", "devtools"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
runas = "=1.2.0"
|
runas = "=1.2.0"
|
||||||
|
@ -69,7 +69,8 @@
|
|||||||
},
|
},
|
||||||
"fs": {
|
"fs": {
|
||||||
"exists": true,
|
"exists": true,
|
||||||
"scope": ["$APPDATA/**", "$RESOURCE/../**"]
|
"readFile": true,
|
||||||
|
"scope": ["$APPDATA/**", "$RESOURCE/../**", "**"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"windows": [],
|
"windows": [],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import useSWR, { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
import { useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { useSetRecoilState } from "recoil";
|
import { useSetRecoilState } from "recoil";
|
||||||
import { Box, Button, Grid, IconButton, Stack, Divider } from "@mui/material";
|
import { Box, Button, Grid, IconButton, Stack, Divider } from "@mui/material";
|
||||||
@ -33,6 +33,7 @@ import {
|
|||||||
deleteProfile,
|
deleteProfile,
|
||||||
updateProfile,
|
updateProfile,
|
||||||
reorderProfile,
|
reorderProfile,
|
||||||
|
createProfile,
|
||||||
} from "@/services/cmds";
|
} from "@/services/cmds";
|
||||||
import { atomLoadingCache } from "@/services/states";
|
import { atomLoadingCache } from "@/services/states";
|
||||||
import { closeAllConnections } from "@/services/api";
|
import { closeAllConnections } from "@/services/api";
|
||||||
@ -49,6 +50,8 @@ import { throttle } from "lodash-es";
|
|||||||
import { useRecoilState } from "recoil";
|
import { useRecoilState } from "recoil";
|
||||||
import { atomThemeMode } from "@/services/states";
|
import { atomThemeMode } from "@/services/states";
|
||||||
import { BaseStyledTextField } from "@/components/base/base-styled-text-field";
|
import { BaseStyledTextField } from "@/components/base/base-styled-text-field";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { readTextFile } from "@tauri-apps/api/fs";
|
||||||
|
|
||||||
const ProfilePage = () => {
|
const ProfilePage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -63,6 +66,35 @@ const ProfilePage = () => {
|
|||||||
coordinateGetter: sortableKeyboardCoordinates,
|
coordinateGetter: sortableKeyboardCoordinates,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const unlisten = listen("tauri://file-drop", async (event) => {
|
||||||
|
const fileList = event.payload as string[];
|
||||||
|
for (let file of fileList) {
|
||||||
|
if (!file.endsWith(".yaml") && !file.endsWith(".yml")) {
|
||||||
|
Notice.error("Only support YAML files.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const item = {
|
||||||
|
type: "local",
|
||||||
|
name: file.split(/\/|\\/).pop() ?? "New Profile",
|
||||||
|
desc: "",
|
||||||
|
url: "",
|
||||||
|
option: {
|
||||||
|
with_proxy: false,
|
||||||
|
self_proxy: false,
|
||||||
|
},
|
||||||
|
} as IProfileItem;
|
||||||
|
let data = await readTextFile(file);
|
||||||
|
await createProfile(item, data);
|
||||||
|
await mutateProfiles();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
unlisten.then((fn) => fn());
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
profiles = {},
|
profiles = {},
|
||||||
activateSelected,
|
activateSelected,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user