From 072b3f6f26b7a65f9be696de33d7f25ed77b64f6 Mon Sep 17 00:00:00 2001 From: Jonson Petard <41122242+greenhat616@users.noreply.github.com> Date: Wed, 13 Dec 2023 05:32:24 +0800 Subject: [PATCH] chore: rename clash-meta to mihomo --- backend/Cargo.lock | 50 ++++++++++++++++++++++++ backend/tauri/Cargo.toml | 2 +- backend/tauri/src/config/verge.rs | 6 +-- backend/tauri/src/core/core.rs | 6 +-- backend/tauri/src/utils/resolve.rs | 1 + backend/tauri/tauri.conf.json | 19 +++++++-- scripts/check.ts | 6 +-- scripts/portable.ts | 2 +- src/components/layout/layout-traffic.tsx | 2 +- src/services/types.d.ts | 2 +- 10 files changed, 79 insertions(+), 17 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 3d4bd7696e..f864e4286c 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -3148,6 +3148,17 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "os_info" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +dependencies = [ + "log 0.4.20", + "serde", + "winapi", +] + [[package]] name = "os_pipe" version = "1.1.4" @@ -4601,6 +4612,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sys-locale" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8a11bd9c338fdba09f7881ab41551932ad42e405f61d01e8406baea71c07aee" +dependencies = [ + "js-sys", + "libc", + "wasm-bindgen", + "web-sys", + "windows-sys 0.45.0", +] + [[package]] name = "sysinfo" version = "0.29.11" @@ -4778,6 +4802,7 @@ dependencies = [ "objc", "once_cell", "open 3.2.0", + "os_info", "os_pipe", "percent-encoding", "png", @@ -4793,6 +4818,7 @@ dependencies = [ "serialize-to-javascript", "shared_child", "state", + "sys-locale", "tar", "tauri-macros", "tauri-runtime", @@ -6016,6 +6042,15 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -6034,6 +6069,21 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/backend/tauri/Cargo.toml b/backend/tauri/Cargo.toml index 7eda44155f..e4c9b133f6 100644 --- a/backend/tauri/Cargo.toml +++ b/backend/tauri/Cargo.toml @@ -37,7 +37,7 @@ parking_lot = "0.12.0" tokio = { version = "1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } reqwest = { version = "0.11", features = ["json", "rustls-tls"] } -tauri = { version = "1.5.3", features = [ +tauri = { version = "1.5.3", features = [ "os-all", "global-shortcut-all", "notification-all", "process-all", diff --git a/backend/tauri/src/config/verge.rs b/backend/tauri/src/config/verge.rs index 85fe651308..470b9d6e19 100644 --- a/backend/tauri/src/config/verge.rs +++ b/backend/tauri/src/config/verge.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub enum ClashCore { - #[serde(rename = "clash-premium", alias = "clash")] + #[serde(rename = "clash", alias = "clash-premium")] ClashPremium, #[serde(rename = "clash-rs")] ClashRs, @@ -27,7 +27,7 @@ impl Default for ClashCore { impl From for String { fn from(core: ClashCore) -> Self { match core { - ClashCore::ClashPremium => "clash-premium".into(), + ClashCore::ClashPremium => "clash".into(), ClashCore::ClashRs => "clash-rs".into(), ClashCore::Mihomo => "mihomo".into(), ClashCore::MihomoAlpha => "mihomo-alpha".into(), @@ -38,7 +38,7 @@ impl From for String { impl std::fmt::Display for ClashCore { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - ClashCore::ClashPremium => write!(f, "clash-premium"), + ClashCore::ClashPremium => write!(f, "clash"), ClashCore::ClashRs => write!(f, "clash-rs"), ClashCore::Mihomo => write!(f, "mihomo"), ClashCore::MihomoAlpha => write!(f, "mihomo-alpha"), diff --git a/backend/tauri/src/core/core.rs b/backend/tauri/src/core/core.rs index 7e127c54ea..5caa24693f 100644 --- a/backend/tauri/src/core/core.rs +++ b/backend/tauri/src/core/core.rs @@ -57,18 +57,18 @@ impl CoreManager { let config_path = dirs::path_to_str(&config_path)?; let clash_core = { Config::verge().latest().clash_core.clone() }; - let clash_core = clash_core.unwrap_or(ClashCore::ClashPremium); + let clash_core = clash_core.unwrap_or(ClashCore::ClashPremium).to_string(); let app_dir = dirs::app_home_dir()?; let app_dir = dirs::path_to_str(&app_dir)?; - + log::debug!(target: "app", "check config in `{clash_core}`"); let output = Command::new_sidecar(clash_core)? .args(["-t", "-d", app_dir, "-f", config_path]) .output()?; if !output.status.success() { let error = clash_api::parse_check_output(output.stdout.clone()); - let error = match error.len() > 0 { + let error = match !error.is_empty() { true => error, false => output.stdout.clone(), }; diff --git a/backend/tauri/src/utils/resolve.rs b/backend/tauri/src/utils/resolve.rs index ecbc8a1a84..2d024193be 100644 --- a/backend/tauri/src/utils/resolve.rs +++ b/backend/tauri/src/utils/resolve.rs @@ -281,6 +281,7 @@ pub fn save_window_state(app_handle: &AppHandle, save_to_file: bool) -> Result<( // TODO: use enum instead pub fn resolve_core_version(core_type: &ClashCore) -> Result { let core = core_type.clone().to_string(); + log::debug!(target: "app", "check config in `{core}`"); let cmd = match core_type { ClashCore::ClashPremium | ClashCore::Mihomo | ClashCore::MihomoAlpha => { Command::new_sidecar(core)?.args(["-v"]) diff --git a/backend/tauri/tauri.conf.json b/backend/tauri/tauri.conf.json index 8a959bfaf2..a1723b6fb9 100644 --- a/backend/tauri/tauri.conf.json +++ b/backend/tauri/tauri.conf.json @@ -25,10 +25,12 @@ "icons/icon-new.icns", "icons/icon.ico" ], - "resources": ["resources"], + "resources": [ + "resources" + ], "externalBin": [ "sidecar/clash", - "sidecar/clash-meta", + "sidecar/mihomo", "sidecar/clash-rs" ], "copyright": "© 2022 zzzgydi All Rights Reserved", @@ -36,7 +38,9 @@ "shortDescription": "Clash Nyanpasu! (∠・ω< )⌒☆", "longDescription": "Clash Nyanpasu! (∠・ω< )⌒☆", "deb": { - "depends": ["openssl"] + "depends": [ + "openssl" + ] }, "macOS": { "frameworks": [], @@ -50,7 +54,11 @@ "digestAlgorithm": "sha256", "timestampUrl": "", "wix": { - "language": ["zh-CN", "en-US", "ru-RU"] + "language": [ + "zh-CN", + "en-US", + "ru-RU" + ] } } }, @@ -79,6 +87,9 @@ }, "notification": { "all": true + }, + "os": { + "all": true } }, "windows": [], diff --git a/scripts/check.ts b/scripts/check.ts index f7f4f4f1cb..826d58b9b9 100644 --- a/scripts/check.ts +++ b/scripts/check.ts @@ -196,8 +196,8 @@ function clashMeta(): BinInfo { const tmpFile = `${name}-${META_VERSION}.${urlExt}`; return { - name: "clash-meta", - targetFile: `clash-meta-${SIDECAR_HOST}${isWin ? ".exe" : ""}`, + name: "mihomo", + targetFile: `mihomo-${SIDECAR_HOST}${isWin ? ".exe" : ""}`, exeFile, tmpFile, downloadURL, @@ -418,7 +418,7 @@ const resolveEnableLoopback = () => const tasks = [ { name: "clash", func: () => resolveClash(), retry: 5 }, { - name: "clash-meta", + name: "mihomo", func: () => getLatestVersion().then(() => resolveSidecar(clashMeta())), retry: 5, }, diff --git a/scripts/portable.ts b/scripts/portable.ts index 1fa0a2785e..3497f8361d 100644 --- a/scripts/portable.ts +++ b/scripts/portable.ts @@ -20,7 +20,7 @@ async function resolvePortable() { zip.addLocalFile(path.join(releaseDir, "Clash Nyanpasu.exe")); zip.addLocalFile(path.join(releaseDir, "clash.exe")); - zip.addLocalFile(path.join(releaseDir, "clash-meta.exe")); + zip.addLocalFile(path.join(releaseDir, "mihomo.exe")); zip.addLocalFile(path.join(releaseDir, "clash-rs.exe")); zip.addLocalFolder(path.join(releaseDir, "resources"), "resources"); diff --git a/src/components/layout/layout-traffic.tsx b/src/components/layout/layout-traffic.tsx index d1050a8693..1206e8303c 100644 --- a/src/components/layout/layout-traffic.tsx +++ b/src/components/layout/layout-traffic.tsx @@ -47,7 +47,7 @@ export const LayoutTraffic = () => { }, [clashInfo, pageVisible]); /* --------- meta memory information --------- */ - const isMetaCore = verge?.clash_core === "clash-meta"; + const isMetaCore = verge?.clash_core === "mihomo"; const displayMemory = isMetaCore && (verge?.enable_memory_usage ?? true); const memoryWs = useWebsocket( diff --git a/src/services/types.d.ts b/src/services/types.d.ts index b8b5774506..f5178c4618 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -155,7 +155,7 @@ interface IProfilesConfig { interface IVergeConfig { app_log_level?: "trace" | "debug" | "info" | "warn" | "error" | string; language?: string; - clash_core?: string; + clash_core?: "mihomo" | "mihomo-alpha" | "clash-rs" | "clash"; theme_mode?: "light" | "dark" | "system"; theme_blur?: boolean; traffic_graph?: boolean;