mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
feat: auto update profiles
This commit is contained in:
parent
81aef736d6
commit
f72536bce0
|
@ -10,6 +10,7 @@ import {
|
||||||
} from "../services/command";
|
} from "../services/command";
|
||||||
import ProfileItemComp from "../components/profile-item";
|
import ProfileItemComp from "../components/profile-item";
|
||||||
import useNotice from "../utils/use-notice";
|
import useNotice from "../utils/use-notice";
|
||||||
|
import noop from "../utils/noop";
|
||||||
|
|
||||||
const RulesPage = () => {
|
const RulesPage = () => {
|
||||||
const [url, setUrl] = useState("");
|
const [url, setUrl] = useState("");
|
||||||
|
@ -19,14 +20,21 @@ const RulesPage = () => {
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
||||||
|
|
||||||
const onClick = () => {
|
const onImport = async () => {
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
setUrl("");
|
setUrl("");
|
||||||
setDisabled(true);
|
setDisabled(true);
|
||||||
importProfile(url)
|
|
||||||
.then(() => notice.success("Successfully import profile."))
|
try {
|
||||||
.catch(() => notice.error("Failed to import profile."))
|
await importProfile(url);
|
||||||
.finally(() => setDisabled(false));
|
mutate("getProfiles", getProfiles());
|
||||||
|
if (!profiles.items?.length) putProfiles(0).catch(noop);
|
||||||
|
notice.success("Successfully import profile.");
|
||||||
|
} catch {
|
||||||
|
notice.error("Failed to import profile.");
|
||||||
|
} finally {
|
||||||
|
setDisabled(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const lockRef = useRef(false);
|
const lockRef = useRef(false);
|
||||||
|
@ -76,7 +84,7 @@ const RulesPage = () => {
|
||||||
<Button
|
<Button
|
||||||
disabled={!url || disabled}
|
disabled={!url || disabled}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={onClick}
|
onClick={onImport}
|
||||||
>
|
>
|
||||||
Import
|
Import
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -48,7 +48,7 @@ export interface ProfilesConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getProfiles() {
|
export async function getProfiles() {
|
||||||
return invoke<ProfilesConfig | null>("get_profiles");
|
return (await invoke<ProfilesConfig>("get_profiles")) ?? {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setProfiles(current: number, profile: ProfileItem) {
|
export async function setProfiles(current: number, profile: ProfileItem) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user