2021-12-25 22:33:29 +08:00
|
|
|
import { invoke } from "@tauri-apps/api/tauri";
|
|
|
|
|
import { ApiType, CmdType } from "./types";
|
2022-03-12 03:00:46 +08:00
|
|
|
import Notice from "../components/base/base-notice";
|
2021-12-25 22:33:29 +08:00
|
|
|
|
2022-01-05 02:00:59 +08:00
|
|
|
export async function getProfiles() {
|
2022-01-07 23:29:20 +08:00
|
|
|
return invoke<CmdType.ProfilesConfig>("get_profiles");
|
2021-12-25 22:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
2022-01-05 02:00:59 +08:00
|
|
|
export async function syncProfiles() {
|
|
|
|
|
return invoke<void>("sync_profiles");
|
2021-12-25 22:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 14:59:25 +08:00
|
|
|
export async function enhanceProfiles() {
|
|
|
|
|
return invoke<void>("enhance_profiles");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-19 19:21:55 +08:00
|
|
|
export async function createProfile(
|
|
|
|
|
item: Partial<CmdType.ProfileItem>,
|
|
|
|
|
fileData?: string | null
|
|
|
|
|
) {
|
|
|
|
|
return invoke<void>("create_profile", { item, fileData });
|
2022-02-07 17:26:05 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-01 08:58:47 +08:00
|
|
|
export async function viewProfile(index: string) {
|
2022-01-19 23:58:34 +08:00
|
|
|
return invoke<void>("view_profile", { index });
|
2022-01-17 02:16:17 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-27 00:58:17 +08:00
|
|
|
export async function readProfileFile(index: string) {
|
|
|
|
|
return invoke<string>("read_profile_file", { index });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function saveProfileFile(index: string, fileData: string) {
|
|
|
|
|
return invoke<void>("save_profile_file", { index, fileData });
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 22:33:29 +08:00
|
|
|
export async function importProfile(url: string) {
|
2022-03-10 02:03:55 +08:00
|
|
|
return invoke<void>("import_profile", {
|
|
|
|
|
url,
|
|
|
|
|
option: { with_proxy: true },
|
|
|
|
|
});
|
2021-12-25 22:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-10 02:03:55 +08:00
|
|
|
export async function updateProfile(
|
|
|
|
|
index: string,
|
|
|
|
|
option?: CmdType.ProfileOption
|
|
|
|
|
) {
|
|
|
|
|
return invoke<void>("update_profile", { index, option });
|
2021-12-25 22:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-01 08:58:47 +08:00
|
|
|
export async function deleteProfile(index: string) {
|
2022-01-05 02:00:59 +08:00
|
|
|
return invoke<void>("delete_profile", { index });
|
2021-12-25 22:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
2022-01-05 02:00:59 +08:00
|
|
|
export async function patchProfile(
|
2022-03-01 08:58:47 +08:00
|
|
|
index: string,
|
2022-03-07 01:41:42 +08:00
|
|
|
profile: Partial<CmdType.ProfileItem>
|
2022-01-05 02:00:59 +08:00
|
|
|
) {
|
|
|
|
|
return invoke<void>("patch_profile", { index, profile });
|
2021-12-25 22:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-01 08:58:47 +08:00
|
|
|
export async function selectProfile(index: string) {
|
2022-01-05 02:00:59 +08:00
|
|
|
return invoke<void>("select_profile", { index });
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-06 14:59:25 +08:00
|
|
|
export async function changeProfileChain(chain?: string[]) {
|
|
|
|
|
return invoke<void>("change_profile_chain", { chain });
|
2022-01-05 02:00:59 +08:00
|
|
|
}
|
|
|
|
|
|
2022-04-07 01:20:44 +08:00
|
|
|
export async function changeProfileValid(valid?: string[]) {
|
|
|
|
|
return invoke<void>("change_profile_valid", { valid });
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 02:00:59 +08:00
|
|
|
export async function getClashInfo() {
|
|
|
|
|
return invoke<CmdType.ClashInfo | null>("get_clash_info");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function patchClashConfig(payload: Partial<ApiType.ConfigData>) {
|
|
|
|
|
return invoke<void>("patch_clash_config", { payload });
|
2021-12-25 22:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getVergeConfig() {
|
|
|
|
|
return invoke<CmdType.VergeConfig>("get_verge_config");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function patchVergeConfig(payload: CmdType.VergeConfig) {
|
|
|
|
|
return invoke<void>("patch_verge_config", { payload });
|
|
|
|
|
}
|
2022-01-12 02:54:50 +08:00
|
|
|
|
|
|
|
|
export async function getSystemProxy() {
|
|
|
|
|
return invoke<any>("get_sys_proxy");
|
|
|
|
|
}
|
2022-02-16 03:21:34 +08:00
|
|
|
|
2022-03-06 14:59:25 +08:00
|
|
|
export async function restartSidecar() {
|
|
|
|
|
return invoke<void>("restart_sidecar");
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 02:10:25 +08:00
|
|
|
export async function killSidecars() {
|
|
|
|
|
return invoke<any>("kill_sidecars");
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 03:21:34 +08:00
|
|
|
export async function openAppDir() {
|
2022-03-12 23:58:20 +08:00
|
|
|
return invoke<void>("open_app_dir").catch((err) =>
|
|
|
|
|
Notice.error(err?.message || err.toString(), 1500)
|
|
|
|
|
);
|
2022-02-16 03:21:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function openLogsDir() {
|
2022-03-12 23:58:20 +08:00
|
|
|
return invoke<void>("open_logs_dir").catch((err) =>
|
|
|
|
|
Notice.error(err?.message || err.toString(), 1500)
|
|
|
|
|
);
|
2022-02-16 03:21:34 +08:00
|
|
|
}
|