feature: copy clash env (#1391)
Some checks failed
Alpha Build / alpha (macos-latest, aarch64-apple-darwin) (push) Has been cancelled
Alpha Build / alpha (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Alpha Build / alpha (windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha (windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha (windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, aarch64-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, armv7-unknown-linux-gnueabihf) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, i686-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (arm64, windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (x64, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (x86, windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
Alpha Build / Update tag (push) Has been cancelled

* feat: copy clash env

* style: use ContentCopyRounded replace CopyAll
This commit is contained in:
Avan 2024-07-13 01:03:46 +08:00 committed by GitHub
parent b4025c45da
commit 32212a46e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 40 additions and 4 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ dist-ssr
update.json update.json
scripts/_env.sh scripts/_env.sh
.vscode .vscode
.tool-versions .tool-versions
.idea

View File

@ -12,6 +12,12 @@ use sysproxy::{Autoproxy, Sysproxy};
use tauri::{api, Manager}; use tauri::{api, Manager};
type CmdResult<T = ()> = Result<T, String>; type CmdResult<T = ()> = Result<T, String>;
#[tauri::command]
pub fn copy_clash_env(app_handle: tauri::AppHandle) -> CmdResult {
feat::copy_clash_env(&app_handle);
Ok(())
}
#[tauri::command] #[tauri::command]
pub fn get_profiles() -> CmdResult<IProfiles> { pub fn get_profiles() -> CmdResult<IProfiles> {
Ok(Config::profiles().data().clone()) Ok(Config::profiles().data().clone())

View File

@ -64,6 +64,7 @@ fn main() -> std::io::Result<()> {
cmds::get_runtime_exists, cmds::get_runtime_exists,
cmds::get_runtime_logs, cmds::get_runtime_logs,
cmds::uwp::invoke_uwp_tool, cmds::uwp::invoke_uwp_tool,
cmds::copy_clash_env,
// verge // verge
cmds::get_verge_config, cmds::get_verge_config,
cmds::patch_verge_config, cmds::patch_verge_config,

View File

@ -1,13 +1,21 @@
import { useRef } from "react"; import { useCallback, useRef } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { open } from "@tauri-apps/api/dialog"; import { open } from "@tauri-apps/api/dialog";
import { Button, MenuItem, Select, Input, Typography } from "@mui/material"; import {
Button,
MenuItem,
Select,
Input,
Typography,
Box,
} from "@mui/material";
import { import {
exitApp, exitApp,
openAppDir, openAppDir,
openCoreDir, openCoreDir,
openLogsDir, openLogsDir,
openDevTools, openDevTools,
copyClashEnv,
} from "@/services/cmds"; } from "@/services/cmds";
import { checkUpdate } from "@tauri-apps/api/updater"; import { checkUpdate } from "@tauri-apps/api/updater";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
@ -24,6 +32,8 @@ import { LayoutViewer } from "./mods/layout-viewer";
import { UpdateViewer } from "./mods/update-viewer"; import { UpdateViewer } from "./mods/update-viewer";
import getSystem from "@/utils/get-system"; import getSystem from "@/utils/get-system";
import { routers } from "@/pages/_routers"; import { routers } from "@/pages/_routers";
import { TooltipIcon } from "@/components/base/base-tooltip-icon";
import { ContentCopyRounded } from "@mui/icons-material";
interface Props { interface Props {
onError?: (err: Error) => void; onError?: (err: Error) => void;
@ -67,6 +77,11 @@ const SettingVerge = ({ onError }: Props) => {
} }
}; };
const onCopyClashEnv = useCallback(async () => {
await copyClashEnv();
Notice.success(t("Copy Success"), 1000);
}, []);
return ( return (
<SettingList title={t("Verge Setting")}> <SettingList title={t("Verge Setting")}>
<ThemeViewer ref={themeRef} /> <ThemeViewer ref={themeRef} />
@ -123,7 +138,12 @@ const SettingVerge = ({ onError }: Props) => {
</SettingItem> </SettingItem>
)} )}
<SettingItem label={t("Copy Env Type")}> <SettingItem
label={t("Copy Env Type")}
extra={
<TooltipIcon icon={ContentCopyRounded} onClick={onCopyClashEnv} />
}
>
<GuardState <GuardState
value={env_type ?? (OS === "windows" ? "powershell" : "bash")} value={env_type ?? (OS === "windows" ? "powershell" : "bash")}
onCatch={onError} onCatch={onError}

View File

@ -277,6 +277,7 @@
"Tray Click Event": "Tray Click Event", "Tray Click Event": "Tray Click Event",
"Show Main Window": "Show Main Window", "Show Main Window": "Show Main Window",
"Copy Env Type": "Copy Env Type", "Copy Env Type": "Copy Env Type",
"Copy Success": "Copy Success",
"Start Page": "Start Page", "Start Page": "Start Page",
"Startup Script": "Startup Script", "Startup Script": "Startup Script",
"Browse": "Browse", "Browse": "Browse",

View File

@ -275,6 +275,7 @@
"Tray Click Event": "رویداد کلیک در سینی سیستم", "Tray Click Event": "رویداد کلیک در سینی سیستم",
"Show Main Window": "نمایش پنجره اصلی", "Show Main Window": "نمایش پنجره اصلی",
"Copy Env Type": "کپی نوع محیط", "Copy Env Type": "کپی نوع محیط",
"Copy Success": "کپی با موفقیت انجام شد",
"Start Page": "صفحه شروع", "Start Page": "صفحه شروع",
"Startup Script": "اسکریپت راه‌اندازی", "Startup Script": "اسکریپت راه‌اندازی",
"Browse": "مرور کردن", "Browse": "مرور کردن",

View File

@ -275,6 +275,7 @@
"Tray Click Event": "Событие щелчка в лотке", "Tray Click Event": "Событие щелчка в лотке",
"Show Main Window": "Показать главное окно", "Show Main Window": "Показать главное окно",
"Copy Env Type": "Скопировать тип Env", "Copy Env Type": "Скопировать тип Env",
"Copy Success": "Скопировано",
"Start Page": "Главная страница", "Start Page": "Главная страница",
"Startup Script": "Скрипт запуска", "Startup Script": "Скрипт запуска",
"Browse": "Просмотреть", "Browse": "Просмотреть",

View File

@ -277,6 +277,7 @@
"Tray Click Event": "托盘点击事件", "Tray Click Event": "托盘点击事件",
"Show Main Window": "显示主窗口", "Show Main Window": "显示主窗口",
"Copy Env Type": "复制环境变量类型", "Copy Env Type": "复制环境变量类型",
"Copy Success": "复制成功",
"Start Page": "启动页面", "Start Page": "启动页面",
"Startup Script": "启动脚本", "Startup Script": "启动脚本",
"Browse": "浏览", "Browse": "浏览",

View File

@ -2,6 +2,10 @@ import dayjs from "dayjs";
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "@tauri-apps/api/tauri";
import { Notice } from "@/components/base"; import { Notice } from "@/components/base";
export async function copyClashEnv() {
return invoke<void>("copy_clash_env");
}
export async function getClashLogs() { export async function getClashLogs() {
const regex = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/; const regex = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/;
const newRegex = /(.+?)\s+(.+?)\s+(.+)/; const newRegex = /(.+?)\s+(.+?)\s+(.+)/;