mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: refactor commands and support update profile
This commit is contained in:
@@ -28,10 +28,11 @@ interface Props {
|
||||
selected: boolean;
|
||||
itemData: ProfileItem;
|
||||
onClick: () => void;
|
||||
onUpdate: () => void;
|
||||
}
|
||||
|
||||
const ProfileItemComp: React.FC<Props> = (props) => {
|
||||
const { selected, itemData, onClick } = props;
|
||||
const { selected, itemData, onClick, onUpdate } = props;
|
||||
|
||||
const { name = "Profile", extra } = itemData;
|
||||
const { upload = 0, download = 0, total = 0 } = extra ?? {};
|
||||
@@ -87,6 +88,7 @@ const ProfileItemComp: React.FC<Props> = (props) => {
|
||||
color="inherit"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onUpdate();
|
||||
}}
|
||||
>
|
||||
<MenuRounded />
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { useState } from "react";
|
||||
import useSWR, { useSWRConfig } from "swr";
|
||||
import { Box, Button, Grid, TextField, Typography } from "@mui/material";
|
||||
import { getProfiles, importProfile, putProfiles } from "../services/command";
|
||||
import {
|
||||
getProfiles,
|
||||
importProfile,
|
||||
putProfiles,
|
||||
updateProfile,
|
||||
} from "../services/command";
|
||||
import ProfileItemComp from "../components/profile-item";
|
||||
import useNotice from "../utils/use-notice";
|
||||
|
||||
@@ -33,6 +38,16 @@ const RulesPage = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const onUpdateProfile = (index: number) => {
|
||||
updateProfile(index)
|
||||
.then(() => {
|
||||
mutate("getProfiles");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
||||
<Typography variant="h4" component="h1" sx={{ py: 2, mb: 1 }}>
|
||||
@@ -66,6 +81,7 @@ const RulesPage = () => {
|
||||
selected={profiles.current === idx}
|
||||
itemData={item}
|
||||
onClick={() => onProfileChange(idx)}
|
||||
onUpdate={() => onUpdateProfile(idx)}
|
||||
/>
|
||||
</Grid>
|
||||
))}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
|
||||
export async function restartSidecar() {
|
||||
return invoke<void>("restart_sidebar");
|
||||
return invoke<void>("restart_sidecar");
|
||||
}
|
||||
|
||||
export interface ClashInfo {
|
||||
@@ -15,7 +15,11 @@ export async function getClashInfo() {
|
||||
}
|
||||
|
||||
export async function importProfile(url: string) {
|
||||
return invoke<string>("import_profile", { url });
|
||||
return invoke<void>("import_profile", { url });
|
||||
}
|
||||
|
||||
export async function updateProfile(index: number) {
|
||||
return invoke<void>("update_profile", { index });
|
||||
}
|
||||
|
||||
export interface ProfileItem {
|
||||
|
||||
Reference in New Issue
Block a user