Skip to content

Commit

Permalink
fix(cmds): path in changing app dir call (#591)
Browse files Browse the repository at this point in the history
* fix(cmds): change app dir call path

* fix(cmds): relauch after changed app dir
  • Loading branch information
greenhat616 authored Mar 10, 2024
1 parent d9a5417 commit 82865bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/components/setting/setting-verge.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand All @@ -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";
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions src/services/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,6 @@ export async function getCustomAppDir() {
return invoke<string | null>("get_custom_app_dir");
}

export async function setCustomAppDir(dir: string) {
return invoke<void>("set_custom_app_dir", { dir });
export async function setCustomAppDir(path: string) {
return invoke<void>("set_custom_app_dir", { path });
}
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 82865bb

Please sign in to comment.