mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:23:44 +08:00
fix: file drag and drop import cannot be used
This commit is contained in:
parent
184b588f20
commit
17a8dfb58a
@ -16,6 +16,12 @@
|
|||||||
"identifier": "fs:scope",
|
"identifier": "fs:scope",
|
||||||
"allow": ["$APPDATA/**", "$RESOURCE/../**", "**"]
|
"allow": ["$APPDATA/**", "$RESOURCE/../**", "**"]
|
||||||
},
|
},
|
||||||
|
"fs:allow-app-read",
|
||||||
|
"fs:allow-app-read-recursive",
|
||||||
|
"fs:allow-appcache-read",
|
||||||
|
"fs:allow-appcache-read-recursive",
|
||||||
|
"fs:allow-appconfig-read",
|
||||||
|
"fs:allow-appconfig-read-recursive",
|
||||||
"core:window:allow-create",
|
"core:window:allow-create",
|
||||||
"core:window:allow-center",
|
"core:window:allow-center",
|
||||||
"core:window:allow-request-user-attention",
|
"core:window:allow-request-user-attention",
|
||||||
|
@ -2,6 +2,7 @@ import useSWR, { mutate } from "swr";
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { Box, Button, IconButton, Stack, Divider, Grid2 } from "@mui/material";
|
import { Box, Button, IconButton, Stack, Divider, Grid2 } from "@mui/material";
|
||||||
|
import { FileDropEvent, getCurrent } from "@tauri-apps/plugin-window";
|
||||||
import {
|
import {
|
||||||
DndContext,
|
DndContext,
|
||||||
closestCenter,
|
closestCenter,
|
||||||
@ -25,7 +26,6 @@ import {
|
|||||||
} from "@mui/icons-material";
|
} from "@mui/icons-material";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
getProfiles,
|
|
||||||
importProfile,
|
importProfile,
|
||||||
enhanceProfiles,
|
enhanceProfiles,
|
||||||
getRuntimeLogs,
|
getRuntimeLogs,
|
||||||
@ -45,12 +45,14 @@ import { ProfileMore } from "@/components/profile/profile-more";
|
|||||||
import { ProfileItem } from "@/components/profile/profile-item";
|
import { ProfileItem } from "@/components/profile/profile-item";
|
||||||
import { useProfiles } from "@/hooks/use-profiles";
|
import { useProfiles } from "@/hooks/use-profiles";
|
||||||
import { ConfigViewer } from "@/components/setting/mods/config-viewer";
|
import { ConfigViewer } from "@/components/setting/mods/config-viewer";
|
||||||
import { throttle } from "lodash-es";
|
import { add, throttle } from "lodash-es";
|
||||||
import { BaseStyledTextField } from "@/components/base/base-styled-text-field";
|
import { BaseStyledTextField } from "@/components/base/base-styled-text-field";
|
||||||
import { readTextFile } from "@tauri-apps/plugin-fs";
|
import { readTextFile } from "@tauri-apps/plugin-fs";
|
||||||
import { readText } from "@tauri-apps/plugin-clipboard-manager";
|
import { readText } from "@tauri-apps/plugin-clipboard-manager";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import { useListen } from "@/hooks/use-listen";
|
import { useListen } from "@/hooks/use-listen";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { TauriEvent } from "@tauri-apps/api/event";
|
||||||
|
|
||||||
const ProfilePage = () => {
|
const ProfilePage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -69,9 +71,14 @@ const ProfilePage = () => {
|
|||||||
const { current } = location.state || {};
|
const { current } = location.state || {};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unlisten = addListener("tauri://file-drop", async (event) => {
|
const handleFileDrop = async () => {
|
||||||
const fileList = event.payload as string[];
|
const unlisten = await addListener(
|
||||||
for (let file of fileList) {
|
TauriEvent.DRAG_DROP,
|
||||||
|
async (event: any) => {
|
||||||
|
console.log("文件拖放事件:", event);
|
||||||
|
const paths = event.payload.paths;
|
||||||
|
|
||||||
|
for (let file of paths) {
|
||||||
if (!file.endsWith(".yaml") && !file.endsWith(".yml")) {
|
if (!file.endsWith(".yaml") && !file.endsWith(".yml")) {
|
||||||
Notice.error(t("Only YAML Files Supported"));
|
Notice.error(t("Only YAML Files Supported"));
|
||||||
continue;
|
continue;
|
||||||
@ -90,9 +97,16 @@ const ProfilePage = () => {
|
|||||||
await createProfile(item, data);
|
await createProfile(item, data);
|
||||||
await mutateProfiles();
|
await mutateProfiles();
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return unlisten;
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsubscribe = handleFileDrop();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unlisten.then((fn) => fn());
|
unsubscribe.then((cleanup) => cleanup());
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user