2024-07-13 01:03:46 +08:00
|
|
|
import { useCallback, useRef } from "react";
|
2022-03-12 23:07:45 +08:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-09-02 19:33:17 +08:00
|
|
|
import { open } from "@tauri-apps/plugin-dialog";
|
2025-02-28 23:15:31 +08:00
|
|
|
import { Button, MenuItem, Select, Input } from "@mui/material";
|
|
|
|
|
import { copyClashEnv } from "@/services/cmds";
|
2022-11-20 20:12:58 +08:00
|
|
|
import { useVerge } from "@/hooks/use-verge";
|
2023-09-10 14:30:31 +08:00
|
|
|
import { DialogRef, Notice } from "@/components/base";
|
2022-11-20 21:48:39 +08:00
|
|
|
import { SettingList, SettingItem } from "./mods/setting-comp";
|
|
|
|
|
import { ThemeModeSwitch } from "./mods/theme-mode-switch";
|
|
|
|
|
import { ConfigViewer } from "./mods/config-viewer";
|
|
|
|
|
import { HotkeyViewer } from "./mods/hotkey-viewer";
|
|
|
|
|
import { MiscViewer } from "./mods/misc-viewer";
|
|
|
|
|
import { ThemeViewer } from "./mods/theme-viewer";
|
|
|
|
|
import { GuardState } from "./mods/guard-state";
|
2023-08-05 19:40:23 +08:00
|
|
|
import { LayoutViewer } from "./mods/layout-viewer";
|
2023-09-10 14:30:31 +08:00
|
|
|
import { UpdateViewer } from "./mods/update-viewer";
|
2024-11-08 21:46:15 +08:00
|
|
|
import { BackupViewer } from "./mods/backup-viewer";
|
2023-09-10 14:30:31 +08:00
|
|
|
import getSystem from "@/utils/get-system";
|
2024-01-18 15:36:44 +08:00
|
|
|
import { routers } from "@/pages/_routers";
|
2024-07-13 01:03:46 +08:00
|
|
|
import { TooltipIcon } from "@/components/base/base-tooltip-icon";
|
|
|
|
|
import { ContentCopyRounded } from "@mui/icons-material";
|
2024-12-28 13:57:30 +03:00
|
|
|
import { languages } from "@/services/i18n";
|
2024-03-21 20:51:33 +08:00
|
|
|
|
2021-12-20 00:01:32 +08:00
|
|
|
interface Props {
|
|
|
|
|
onError?: (err: Error) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 14:30:31 +08:00
|
|
|
const OS = getSystem();
|
|
|
|
|
|
2024-12-28 13:57:30 +03:00
|
|
|
const languageOptions = Object.entries(languages).map(([code, _]) => {
|
|
|
|
|
const labels: { [key: string]: string } = {
|
|
|
|
|
en: "English",
|
|
|
|
|
ru: "Русский",
|
|
|
|
|
zh: "中文",
|
|
|
|
|
fa: "فارسی",
|
|
|
|
|
tt: "Татар",
|
|
|
|
|
id: "Bahasa Indonesia",
|
|
|
|
|
ar: "العربية",
|
|
|
|
|
};
|
|
|
|
|
return { code, label: labels[code] };
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-28 23:15:31 +08:00
|
|
|
const SettingVergeBasic = ({ onError }: Props) => {
|
2022-03-12 23:07:45 +08:00
|
|
|
const { t } = useTranslation();
|
2021-12-20 00:01:32 +08:00
|
|
|
|
2022-11-20 20:12:58 +08:00
|
|
|
const { verge, patchVerge, mutateVerge } = useVerge();
|
2024-01-18 15:36:44 +08:00
|
|
|
const {
|
|
|
|
|
theme_mode,
|
|
|
|
|
language,
|
|
|
|
|
tray_event,
|
|
|
|
|
env_type,
|
|
|
|
|
startup_script,
|
|
|
|
|
start_page,
|
|
|
|
|
} = verge ?? {};
|
2022-11-20 21:48:39 +08:00
|
|
|
const configRef = useRef<DialogRef>(null);
|
|
|
|
|
const hotkeyRef = useRef<DialogRef>(null);
|
|
|
|
|
const miscRef = useRef<DialogRef>(null);
|
|
|
|
|
const themeRef = useRef<DialogRef>(null);
|
2023-08-05 19:40:23 +08:00
|
|
|
const layoutRef = useRef<DialogRef>(null);
|
2023-09-10 14:30:31 +08:00
|
|
|
const updateRef = useRef<DialogRef>(null);
|
2024-11-08 21:46:15 +08:00
|
|
|
const backupRef = useRef<DialogRef>(null);
|
2022-03-31 23:38:00 +08:00
|
|
|
|
2025-02-13 02:18:17 +08:00
|
|
|
const onChangeData = (patch: any) => {
|
2022-11-20 20:12:58 +08:00
|
|
|
mutateVerge({ ...verge, ...patch }, false);
|
2021-12-20 00:01:32 +08:00
|
|
|
};
|
|
|
|
|
|
2024-07-13 01:03:46 +08:00
|
|
|
const onCopyClashEnv = useCallback(async () => {
|
|
|
|
|
await copyClashEnv();
|
|
|
|
|
Notice.success(t("Copy Success"), 1000);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2021-12-20 00:01:32 +08:00
|
|
|
return (
|
2025-02-28 23:15:31 +08:00
|
|
|
<SettingList title={t("Verge Basic Setting")}>
|
2022-11-20 21:48:39 +08:00
|
|
|
<ThemeViewer ref={themeRef} />
|
|
|
|
|
<ConfigViewer ref={configRef} />
|
|
|
|
|
<HotkeyViewer ref={hotkeyRef} />
|
|
|
|
|
<MiscViewer ref={miscRef} />
|
2023-08-05 19:40:23 +08:00
|
|
|
<LayoutViewer ref={layoutRef} />
|
2023-09-10 14:30:31 +08:00
|
|
|
<UpdateViewer ref={updateRef} />
|
2024-11-08 21:46:15 +08:00
|
|
|
<BackupViewer ref={backupRef} />
|
2022-09-18 15:52:53 +08:00
|
|
|
|
2022-08-06 03:48:03 +08:00
|
|
|
<SettingItem label={t("Language")}>
|
2022-07-17 16:02:17 +08:00
|
|
|
<GuardState
|
|
|
|
|
value={language ?? "en"}
|
|
|
|
|
onCatch={onError}
|
|
|
|
|
onFormat={(e: any) => e.target.value}
|
|
|
|
|
onChange={(e) => onChangeData({ language: e })}
|
2022-11-20 20:12:58 +08:00
|
|
|
onGuard={(e) => patchVerge({ language: e })}
|
2022-07-17 16:02:17 +08:00
|
|
|
>
|
2024-05-17 20:44:18 +08:00
|
|
|
<Select size="small" sx={{ width: 110, "> div": { py: "7.5px" } }}>
|
2024-12-28 13:57:30 +03:00
|
|
|
{languageOptions.map(({ code, label }) => (
|
|
|
|
|
<MenuItem key={code} value={code}>
|
|
|
|
|
{label}
|
|
|
|
|
</MenuItem>
|
|
|
|
|
))}
|
2022-07-17 16:02:17 +08:00
|
|
|
</Select>
|
|
|
|
|
</GuardState>
|
|
|
|
|
</SettingItem>
|
|
|
|
|
|
2022-08-06 03:48:03 +08:00
|
|
|
<SettingItem label={t("Theme Mode")}>
|
2021-12-20 00:01:32 +08:00
|
|
|
<GuardState
|
2022-07-17 16:02:17 +08:00
|
|
|
value={theme_mode}
|
2021-12-20 00:01:32 +08:00
|
|
|
onCatch={onError}
|
2022-07-17 16:02:17 +08:00
|
|
|
onChange={(e) => onChangeData({ theme_mode: e })}
|
2022-11-20 20:12:58 +08:00
|
|
|
onGuard={(e) => patchVerge({ theme_mode: e })}
|
2021-12-20 00:01:32 +08:00
|
|
|
>
|
2022-07-17 16:02:17 +08:00
|
|
|
<ThemeModeSwitch />
|
2021-12-20 00:01:32 +08:00
|
|
|
</GuardState>
|
|
|
|
|
</SettingItem>
|
|
|
|
|
|
2023-11-28 07:49:44 +08:00
|
|
|
{OS !== "linux" && (
|
|
|
|
|
<SettingItem label={t("Tray Click Event")}>
|
|
|
|
|
<GuardState
|
|
|
|
|
value={tray_event ?? "main_window"}
|
|
|
|
|
onCatch={onError}
|
|
|
|
|
onFormat={(e: any) => e.target.value}
|
|
|
|
|
onChange={(e) => onChangeData({ tray_event: e })}
|
|
|
|
|
onGuard={(e) => patchVerge({ tray_event: e })}
|
|
|
|
|
>
|
|
|
|
|
<Select size="small" sx={{ width: 140, "> div": { py: "7.5px" } }}>
|
|
|
|
|
<MenuItem value="main_window">{t("Show Main Window")}</MenuItem>
|
2025-03-13 09:48:49 +08:00
|
|
|
<MenuItem value="tray_menu">{t("Show Tray Menu")}</MenuItem>
|
2023-11-28 07:49:44 +08:00
|
|
|
<MenuItem value="system_proxy">{t("System Proxy")}</MenuItem>
|
|
|
|
|
<MenuItem value="tun_mode">{t("Tun Mode")}</MenuItem>
|
2023-11-30 22:45:02 +08:00
|
|
|
<MenuItem value="disable">{t("Disable")}</MenuItem>
|
2023-11-28 07:49:44 +08:00
|
|
|
</Select>
|
|
|
|
|
</GuardState>
|
|
|
|
|
</SettingItem>
|
|
|
|
|
)}
|
|
|
|
|
|
2024-07-13 01:03:46 +08:00
|
|
|
<SettingItem
|
|
|
|
|
label={t("Copy Env Type")}
|
|
|
|
|
extra={
|
|
|
|
|
<TooltipIcon icon={ContentCopyRounded} onClick={onCopyClashEnv} />
|
|
|
|
|
}
|
|
|
|
|
>
|
2023-12-08 22:16:42 +08:00
|
|
|
<GuardState
|
2023-12-11 10:51:59 +08:00
|
|
|
value={env_type ?? (OS === "windows" ? "powershell" : "bash")}
|
2023-12-08 22:16:42 +08:00
|
|
|
onCatch={onError}
|
|
|
|
|
onFormat={(e: any) => e.target.value}
|
|
|
|
|
onChange={(e) => onChangeData({ env_type: e })}
|
|
|
|
|
onGuard={(e) => patchVerge({ env_type: e })}
|
|
|
|
|
>
|
|
|
|
|
<Select size="small" sx={{ width: 140, "> div": { py: "7.5px" } }}>
|
|
|
|
|
<MenuItem value="bash">Bash</MenuItem>
|
2025-03-02 23:20:10 +08:00
|
|
|
<MenuItem value="fish">Fish</MenuItem>
|
2024-12-04 19:01:13 +08:00
|
|
|
<MenuItem value="nushell">Nushell</MenuItem>
|
2025-03-02 23:20:10 +08:00
|
|
|
<MenuItem value="cmd">CMD</MenuItem>
|
2024-02-02 17:57:56 +08:00
|
|
|
<MenuItem value="powershell">PowerShell</MenuItem>
|
2023-12-08 22:16:42 +08:00
|
|
|
</Select>
|
|
|
|
|
</GuardState>
|
|
|
|
|
</SettingItem>
|
2024-01-18 15:36:44 +08:00
|
|
|
|
|
|
|
|
<SettingItem label={t("Start Page")}>
|
|
|
|
|
<GuardState
|
|
|
|
|
value={start_page ?? "/"}
|
|
|
|
|
onCatch={onError}
|
|
|
|
|
onFormat={(e: any) => e.target.value}
|
|
|
|
|
onChange={(e) => onChangeData({ start_page: e })}
|
|
|
|
|
onGuard={(e) => patchVerge({ start_page: e })}
|
|
|
|
|
>
|
|
|
|
|
<Select size="small" sx={{ width: 140, "> div": { py: "7.5px" } }}>
|
2024-03-29 08:20:31 +08:00
|
|
|
{routers.map((page: { label: string; path: string }) => {
|
2025-02-18 07:10:28 +08:00
|
|
|
return (
|
|
|
|
|
<MenuItem key={page.path} value={page.path}>
|
|
|
|
|
{t(page.label)}
|
|
|
|
|
</MenuItem>
|
|
|
|
|
);
|
2024-01-18 15:36:44 +08:00
|
|
|
})}
|
|
|
|
|
</Select>
|
|
|
|
|
</GuardState>
|
|
|
|
|
</SettingItem>
|
|
|
|
|
|
2024-01-17 15:06:16 +08:00
|
|
|
<SettingItem label={t("Startup Script")}>
|
|
|
|
|
<GuardState
|
|
|
|
|
value={startup_script ?? ""}
|
|
|
|
|
onCatch={onError}
|
|
|
|
|
onFormat={(e: any) => e.target.value}
|
|
|
|
|
onChange={(e) => onChangeData({ startup_script: e })}
|
|
|
|
|
onGuard={(e) => patchVerge({ startup_script: e })}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
value={startup_script}
|
|
|
|
|
disabled
|
2024-03-10 07:00:24 +08:00
|
|
|
sx={{ width: 230 }}
|
2024-01-17 15:06:16 +08:00
|
|
|
endAdornment={
|
|
|
|
|
<>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={async () => {
|
2024-09-02 19:33:17 +08:00
|
|
|
const selected = await open({
|
2024-01-17 15:06:16 +08:00
|
|
|
directory: false,
|
|
|
|
|
multiple: false,
|
|
|
|
|
filters: [
|
|
|
|
|
{
|
|
|
|
|
name: "Shell Script",
|
|
|
|
|
extensions: ["sh", "bat", "ps1"],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
2024-09-20 16:26:23 +08:00
|
|
|
if (selected) {
|
|
|
|
|
onChangeData({ startup_script: `${selected}` });
|
|
|
|
|
patchVerge({ startup_script: `${selected}` });
|
2024-01-17 15:06:16 +08:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t("Browse")}
|
|
|
|
|
</Button>
|
|
|
|
|
{startup_script && (
|
|
|
|
|
<Button
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
onChangeData({ startup_script: "" });
|
|
|
|
|
patchVerge({ startup_script: "" });
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t("Clear")}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
></Input>
|
|
|
|
|
</GuardState>
|
|
|
|
|
</SettingItem>
|
2022-02-19 18:14:40 +08:00
|
|
|
|
2024-06-07 15:51:51 +08:00
|
|
|
<SettingItem
|
|
|
|
|
onClick={() => themeRef.current?.open()}
|
|
|
|
|
label={t("Theme Setting")}
|
|
|
|
|
/>
|
2022-11-10 01:27:05 +08:00
|
|
|
|
2024-06-07 15:51:51 +08:00
|
|
|
<SettingItem
|
|
|
|
|
onClick={() => layoutRef.current?.open()}
|
|
|
|
|
label={t("Layout Setting")}
|
|
|
|
|
/>
|
2022-03-31 23:38:00 +08:00
|
|
|
|
2024-06-07 15:51:51 +08:00
|
|
|
<SettingItem
|
|
|
|
|
onClick={() => miscRef.current?.open()}
|
|
|
|
|
label={t("Miscellaneous")}
|
|
|
|
|
/>
|
2022-09-18 15:52:53 +08:00
|
|
|
|
2024-06-07 15:51:51 +08:00
|
|
|
<SettingItem
|
|
|
|
|
onClick={() => hotkeyRef.current?.open()}
|
|
|
|
|
label={t("Hotkey Setting")}
|
|
|
|
|
/>
|
2022-01-16 03:22:37 +08:00
|
|
|
</SettingList>
|
2021-12-20 00:01:32 +08:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-28 23:15:31 +08:00
|
|
|
export default SettingVergeBasic;
|