|
@@ -1,5 +1,5 @@
|
|
|
import useSWR, { mutate } from "swr";
|
|
|
-import { useMemo, useRef, useState } from "react";
|
|
|
+import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
import { useLockFn } from "ahooks";
|
|
|
import { useSetRecoilState } from "recoil";
|
|
|
import { Box, Button, Grid, IconButton, Stack, Divider } from "@mui/material";
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
deleteProfile,
|
|
|
updateProfile,
|
|
|
reorderProfile,
|
|
|
+ createProfile,
|
|
|
} from "@/services/cmds";
|
|
|
import { atomLoadingCache } from "@/services/states";
|
|
|
import { closeAllConnections } from "@/services/api";
|
|
@@ -49,6 +50,8 @@ import { throttle } from "lodash-es";
|
|
|
import { useRecoilState } from "recoil";
|
|
|
import { atomThemeMode } from "@/services/states";
|
|
|
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 { t } = useTranslation();
|
|
@@ -63,6 +66,35 @@ const ProfilePage = () => {
|
|
|
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 {
|
|
|
profiles = {},
|
|
|
activateSelected,
|