2024-09-02 19:33:17 +08:00
|
|
|
|
import { invoke } from "@tauri-apps/api/core";
|
2022-11-20 22:03:55 +08:00
|
|
|
|
import { Notice } from "@/components/base";
|
2021-12-25 22:33:29 +08:00
|
|
|
|
|
2024-07-13 01:03:46 +08:00
|
|
|
|
export async function copyClashEnv() {
|
|
|
|
|
|
return invoke<void>("copy_clash_env");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-05 02:00:59 +08:00
|
|
|
|
export async function getProfiles() {
|
2022-11-19 17:22:29 +08:00
|
|
|
|
return invoke<IProfilesConfig>("get_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-11-19 17:22:29 +08:00
|
|
|
|
export async function patchProfilesConfig(profiles: IProfilesConfig) {
|
2022-11-18 18:26:55 +08:00
|
|
|
|
return invoke<void>("patch_profiles_config", { profiles });
|
2022-11-18 18:18:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-19 19:21:55 +08:00
|
|
|
|
export async function createProfile(
|
2022-11-19 17:22:29 +08:00
|
|
|
|
item: Partial<IProfileItem>,
|
2024-11-21 06:01:56 +08:00
|
|
|
|
fileData?: string | null,
|
2022-03-19 19:21:55 +08:00
|
|
|
|
) {
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-29 08:54:02 +08:00
|
|
|
|
export async function reorderProfile(activeId: string, overId: string) {
|
|
|
|
|
|
return invoke<void>("reorder_profile", {
|
|
|
|
|
|
activeId,
|
|
|
|
|
|
overId,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-19 17:22:29 +08:00
|
|
|
|
export async function updateProfile(index: string, option?: IProfileOption) {
|
2022-03-10 02:03:55 +08:00
|
|
|
|
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,
|
2024-11-21 06:01:56 +08:00
|
|
|
|
profile: Partial<IProfileItem>,
|
2022-01-05 02:00:59 +08:00
|
|
|
|
) {
|
|
|
|
|
|
return invoke<void>("patch_profile", { index, profile });
|
2021-12-25 22:33:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-05 02:00:59 +08:00
|
|
|
|
export async function getClashInfo() {
|
2022-11-19 17:22:29 +08:00
|
|
|
|
return invoke<IClashInfo | null>("get_clash_info");
|
2022-01-05 02:00:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-21 10:02:28 +08:00
|
|
|
|
// Get runtime config which controlled by verge
|
2022-08-12 03:20:55 +08:00
|
|
|
|
export async function getRuntimeConfig() {
|
2024-02-21 10:02:28 +08:00
|
|
|
|
return invoke<IConfigData | null>("get_runtime_config");
|
2022-08-12 03:20:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function getRuntimeYaml() {
|
|
|
|
|
|
return invoke<string | null>("get_runtime_yaml");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function getRuntimeExists() {
|
|
|
|
|
|
return invoke<string[]>("get_runtime_exists");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function getRuntimeLogs() {
|
|
|
|
|
|
return invoke<Record<string, [string, string][]>>("get_runtime_logs");
|
2022-07-25 01:20:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-19 17:22:29 +08:00
|
|
|
|
export async function patchClashConfig(payload: Partial<IConfigData>) {
|
2022-01-05 02:00:59 +08:00
|
|
|
|
return invoke<void>("patch_clash_config", { payload });
|
2021-12-25 22:33:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-09 07:45:46 +08:00
|
|
|
|
export async function patchClashMode(payload: String) {
|
|
|
|
|
|
return invoke<void>("patch_clash_mode", { payload });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-25 22:33:29 +08:00
|
|
|
|
export async function getVergeConfig() {
|
2022-11-19 17:22:29 +08:00
|
|
|
|
return invoke<IVergeConfig>("get_verge_config");
|
2021-12-25 22:33:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-19 17:22:29 +08:00
|
|
|
|
export async function patchVergeConfig(payload: IVergeConfig) {
|
2021-12-25 22:33:29 +08:00
|
|
|
|
return invoke<void>("patch_verge_config", { payload });
|
|
|
|
|
|
}
|
2022-01-12 02:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
export async function getSystemProxy() {
|
2022-09-07 01:51:43 +08:00
|
|
|
|
return invoke<{
|
|
|
|
|
|
enable: boolean;
|
|
|
|
|
|
server: string;
|
|
|
|
|
|
bypass: string;
|
|
|
|
|
|
}>("get_sys_proxy");
|
2022-01-12 02:54:50 +08:00
|
|
|
|
}
|
2022-02-16 03:21:34 +08:00
|
|
|
|
|
2024-05-26 17:59:39 +08:00
|
|
|
|
export async function getAutotemProxy() {
|
|
|
|
|
|
return invoke<{
|
|
|
|
|
|
enable: boolean;
|
|
|
|
|
|
url: string;
|
|
|
|
|
|
}>("get_auto_proxy");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-17 09:48:44 +08:00
|
|
|
|
export async function getAutoLaunchStatus() {
|
2025-03-17 13:51:52 +08:00
|
|
|
|
try {
|
|
|
|
|
|
return await invoke<boolean>("get_auto_launch_status");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("获取自启动状态失败:", error);
|
|
|
|
|
|
// 出错时返回false作为默认值
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-03-17 09:48:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-17 01:59:49 +08:00
|
|
|
|
export async function changeClashCore(clashCore: string) {
|
2025-02-26 05:21:14 +08:00
|
|
|
|
return invoke<string | null>("change_clash_core", { clashCore });
|
2022-05-17 01:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-09 23:11:02 +08:00
|
|
|
|
export async function restartCore() {
|
|
|
|
|
|
return invoke<void>("restart_core");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function restartApp() {
|
|
|
|
|
|
return invoke<void>("restart_app");
|
2022-03-06 14:59:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-24 11:25:22 +08:00
|
|
|
|
export async function getAppDir() {
|
|
|
|
|
|
return invoke<string>("get_app_dir");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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) =>
|
2024-11-21 06:01:56 +08:00
|
|
|
|
Notice.error(err?.message || err.toString(), 1500),
|
2022-03-12 23:58:20 +08:00
|
|
|
|
);
|
2022-02-16 03:21:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-13 00:44:24 +08:00
|
|
|
|
export async function openCoreDir() {
|
|
|
|
|
|
return invoke<void>("open_core_dir").catch((err) =>
|
2024-11-21 06:01:56 +08:00
|
|
|
|
Notice.error(err?.message || err.toString(), 1500),
|
2022-12-13 00:44:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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) =>
|
2024-11-21 06:01:56 +08:00
|
|
|
|
Notice.error(err?.message || err.toString(), 1500),
|
2022-03-12 23:58:20 +08:00
|
|
|
|
);
|
2022-02-16 03:21:34 +08:00
|
|
|
|
}
|
2022-04-24 21:03:47 +08:00
|
|
|
|
|
2022-08-06 21:56:54 +08:00
|
|
|
|
export async function openWebUrl(url: string) {
|
|
|
|
|
|
return invoke<void>("open_web_url", { url });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-18 11:11:22 +08:00
|
|
|
|
export async function cmdGetProxyDelay(
|
|
|
|
|
|
name: string,
|
|
|
|
|
|
timeout: number,
|
2024-11-21 06:01:56 +08:00
|
|
|
|
url?: string,
|
2024-02-18 11:11:22 +08:00
|
|
|
|
) {
|
2025-03-09 04:22:34 +08:00
|
|
|
|
// 确保URL不为空
|
|
|
|
|
|
const testUrl = url || "http://cp.cloudflare.com/generate_204";
|
|
|
|
|
|
console.log(
|
|
|
|
|
|
`[API] 调用延迟测试API,代理: ${name}, 超时: ${timeout}ms, URL: ${testUrl}`,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
name = encodeURIComponent(name);
|
|
|
|
|
|
const result = await invoke<{ delay: number }>(
|
|
|
|
|
|
"clash_api_get_proxy_delay",
|
|
|
|
|
|
{
|
|
|
|
|
|
name,
|
|
|
|
|
|
url: testUrl, // 传递经过验证的URL
|
|
|
|
|
|
timeout,
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证返回结果中是否有delay字段,并且值是一个有效的数字
|
|
|
|
|
|
if (result && typeof result.delay === "number") {
|
|
|
|
|
|
console.log(
|
|
|
|
|
|
`[API] 延迟测试API调用成功,代理: ${name}, 延迟: ${result.delay}ms`,
|
|
|
|
|
|
);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.error(
|
|
|
|
|
|
`[API] 延迟测试API返回无效结果,代理: ${name}, 结果:`,
|
|
|
|
|
|
result,
|
|
|
|
|
|
);
|
|
|
|
|
|
// 返回一个有效的结果对象,但标记为超时
|
|
|
|
|
|
return { delay: 1e6 };
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(`[API] 延迟测试API调用失败,代理: ${name}`, error);
|
|
|
|
|
|
// 返回一个有效的结果对象,但标记为错误
|
|
|
|
|
|
return { delay: 1e6 };
|
|
|
|
|
|
}
|
2023-11-01 20:52:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-17 11:02:17 +08:00
|
|
|
|
export async function cmdTestDelay(url: string) {
|
|
|
|
|
|
return invoke<number>("test_delay", { url });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-22 00:15:41 -08:00
|
|
|
|
export async function invoke_uwp_tool() {
|
|
|
|
|
|
return invoke<void>("invoke_uwp_tool").catch((err) =>
|
2024-11-21 06:01:56 +08:00
|
|
|
|
Notice.error(err?.message || err.toString(), 1500),
|
2023-11-22 00:15:41 -08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2023-12-15 21:39:34 +08:00
|
|
|
|
|
|
|
|
|
|
export async function getPortableFlag() {
|
|
|
|
|
|
return invoke<boolean>("get_portable_flag");
|
|
|
|
|
|
}
|
2024-02-02 16:32:19 +08:00
|
|
|
|
|
2024-03-11 20:19:21 +08:00
|
|
|
|
export async function openDevTools() {
|
|
|
|
|
|
return invoke("open_devtools");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-02 16:32:19 +08:00
|
|
|
|
export async function exitApp() {
|
|
|
|
|
|
return invoke("exit_app");
|
|
|
|
|
|
}
|
2024-02-24 11:25:22 +08:00
|
|
|
|
|
2025-03-03 05:58:12 +08:00
|
|
|
|
export async function exportDiagnosticInfo() {
|
|
|
|
|
|
return invoke("export_diagnostic_info");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-14 13:31:34 +08:00
|
|
|
|
export async function getSystemInfo() {
|
|
|
|
|
|
return invoke<string>("get_system_info");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-24 11:25:22 +08:00
|
|
|
|
export async function copyIconFile(
|
|
|
|
|
|
path: string,
|
2024-11-21 06:01:56 +08:00
|
|
|
|
name: "common" | "sysproxy" | "tun",
|
2024-02-24 11:25:22 +08:00
|
|
|
|
) {
|
2025-03-04 20:46:17 +08:00
|
|
|
|
const key = `icon_${name}_update_time`;
|
|
|
|
|
|
const previousTime = localStorage.getItem(key) || "";
|
|
|
|
|
|
|
|
|
|
|
|
const currentTime = String(Date.now());
|
|
|
|
|
|
localStorage.setItem(key, currentTime);
|
|
|
|
|
|
|
|
|
|
|
|
const iconInfo = {
|
|
|
|
|
|
name,
|
|
|
|
|
|
previous_t: previousTime,
|
|
|
|
|
|
current_t: currentTime,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return invoke<void>("copy_icon_file", { path, iconInfo });
|
2024-02-24 11:25:22 +08:00
|
|
|
|
}
|
2024-03-15 16:42:17 +08:00
|
|
|
|
|
|
|
|
|
|
export async function downloadIconCache(url: string, name: string) {
|
|
|
|
|
|
return invoke<string>("download_icon_cache", { url, name });
|
|
|
|
|
|
}
|
2024-07-07 18:02:29 +08:00
|
|
|
|
|
|
|
|
|
|
export async function getNetworkInterfaces() {
|
|
|
|
|
|
return invoke<string[]>("get_network_interfaces");
|
|
|
|
|
|
}
|
2024-07-13 14:10:50 +08:00
|
|
|
|
|
|
|
|
|
|
export async function getNetworkInterfacesInfo() {
|
|
|
|
|
|
return invoke<INetworkInterface[]>("get_network_interfaces_info");
|
|
|
|
|
|
}
|
2024-11-08 21:46:15 +08:00
|
|
|
|
|
|
|
|
|
|
export async function createWebdavBackup() {
|
|
|
|
|
|
return invoke<void>("create_webdav_backup");
|
|
|
|
|
|
}
|
2024-11-09 23:11:02 +08:00
|
|
|
|
|
|
|
|
|
|
export async function deleteWebdavBackup(filename: string) {
|
|
|
|
|
|
return invoke<void>("delete_webdav_backup", { filename });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function restoreWebDavBackup(filename: string) {
|
|
|
|
|
|
return invoke<void>("restore_webdav_backup", { filename });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-08 21:46:15 +08:00
|
|
|
|
export async function saveWebdavConfig(
|
|
|
|
|
|
url: string,
|
|
|
|
|
|
username: string,
|
2024-11-21 06:01:56 +08:00
|
|
|
|
password: String,
|
2024-11-08 21:46:15 +08:00
|
|
|
|
) {
|
|
|
|
|
|
return invoke<void>("save_webdav_config", {
|
|
|
|
|
|
url,
|
|
|
|
|
|
username,
|
|
|
|
|
|
password,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function listWebDavBackup() {
|
|
|
|
|
|
let list: IWebDavFile[] = await invoke<IWebDavFile[]>("list_webdav_backup");
|
|
|
|
|
|
list.map((item) => {
|
|
|
|
|
|
item.filename = item.href.split("/").pop() as string;
|
|
|
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
2025-02-26 05:21:14 +08:00
|
|
|
|
|
|
|
|
|
|
export async function scriptValidateNotice(status: string, msg: string) {
|
|
|
|
|
|
return invoke<void>("script_validate_notice", { status, msg });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function validateScriptFile(filePath: string) {
|
|
|
|
|
|
return invoke<boolean>("validate_script_file", { filePath });
|
|
|
|
|
|
}
|
2025-03-03 14:42:31 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取当前运行模式
|
|
|
|
|
|
export const getRunningMode = async () => {
|
2025-03-26 22:04:16 +08:00
|
|
|
|
return invoke<string>("get_running_mode");
|
2025-03-03 14:42:31 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-14 13:31:34 +08:00
|
|
|
|
// 获取应用运行时间
|
|
|
|
|
|
export const getAppUptime = async () => {
|
|
|
|
|
|
return invoke<number>("get_app_uptime");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-26 16:22:13 +08:00
|
|
|
|
// 安装系统服务
|
2025-03-03 14:42:31 +08:00
|
|
|
|
export const installService = async () => {
|
|
|
|
|
|
return invoke<void>("install_service");
|
|
|
|
|
|
};
|
2025-03-20 03:23:14 +08:00
|
|
|
|
|
2025-03-26 16:22:13 +08:00
|
|
|
|
// 卸载系统服务
|
|
|
|
|
|
export const uninstallService = async () => {
|
|
|
|
|
|
return invoke<void>("uninstall_service");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 重装系统服务
|
|
|
|
|
|
export const reinstallService = async () => {
|
|
|
|
|
|
return invoke<void>("reinstall_service");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 修复系统服务
|
|
|
|
|
|
export const repairService = async () => {
|
|
|
|
|
|
return invoke<void>("repair_service");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-20 03:23:14 +08:00
|
|
|
|
export const entry_lightweight_mode = async () => {
|
|
|
|
|
|
return invoke<void>("entry_lightweight_mode");
|
2025-03-26 16:22:13 +08:00
|
|
|
|
};
|
2025-03-20 03:23:14 +08:00
|
|
|
|
|
|
|
|
|
|
export const exit_lightweight_mode = async () => {
|
|
|
|
|
|
return invoke<void>("exit_lightweight_mode");
|
2025-03-26 16:22:13 +08:00
|
|
|
|
};
|
2025-03-31 03:22:24 +08:00
|
|
|
|
|
|
|
|
|
|
export const isAdmin = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
return await invoke<boolean>("is_admin");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("检查管理员权限失败:", error);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|