diff --git a/src/components/setting/setting-verge.tsx b/src/components/setting/setting-verge.tsx index 004e43ef08..e5e2cd4ff9 100644 --- a/src/components/setting/setting-verge.tsx +++ b/src/components/setting/setting-verge.tsx @@ -1,5 +1,5 @@ import { DialogRef } from "@/components/base"; -import { useMessage } from "@/hooks/use-notification"; +import { useMessage, useNotification } from "@/hooks/use-notification"; import { useVerge } from "@/hooks/use-verge"; import { collectLogs, @@ -9,6 +9,7 @@ import { openLogsDir, setCustomAppDir, } from "@/services/cmds"; +import { sleep } from "@/utils"; import getSystem from "@/utils/get-system"; import { ArrowForward, IosShare, Settings } from "@mui/icons-material"; import { @@ -22,6 +23,7 @@ import { } from "@mui/material"; import { version } from "@root/package.json"; import { open } from "@tauri-apps/api/dialog"; +import { relaunch } from "@tauri-apps/api/process"; import { checkUpdate } from "@tauri-apps/api/updater"; import { useAsyncEffect, useLockFn } from "ahooks"; import { useRef, useState } from "react"; @@ -116,6 +118,12 @@ const SettingVerge = ({ onError }: Props) => { return; } await setCustomAppDir(selected); + useNotification({ + title: t("Success"), + body: t("App directory changed successfully"), + }); + await sleep(1000); + await relaunch(); } catch (err: any) { useMessage(err.message || err.toString(), { title: t("Error"), diff --git a/src/services/cmds.ts b/src/services/cmds.ts index f67c061447..fd882a9562 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -261,6 +261,6 @@ export async function getCustomAppDir() { return invoke("get_custom_app_dir"); } -export async function setCustomAppDir(dir: string) { - return invoke("set_custom_app_dir", { dir }); +export async function setCustomAppDir(path: string) { + return invoke("set_custom_app_dir", { path }); } diff --git a/src/utils/index.ts b/src/utils/index.ts index 2bd973471b..1953c6d459 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -7,3 +7,7 @@ export function classNames(...classes: any[]) { return classes.filter(Boolean).join(" "); } + +export async function sleep(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); +}