refactor: change core binary name

This commit is contained in:
MystiPanda 2024-06-19 10:04:28 +08:00
parent 95c23a93cd
commit e6e2b1f142
No known key found for this signature in database
16 changed files with 113 additions and 82 deletions

View File

@ -172,8 +172,8 @@ function clashMetaAlpha() {
const zipFile = `${name}-${META_ALPHA_VERSION}.${urlExt}`; const zipFile = `${name}-${META_ALPHA_VERSION}.${urlExt}`;
return { return {
name: "clash-meta-alpha", name: "verge-mihomo-alpha",
targetFile: `clash-meta-alpha-${SIDECAR_HOST}${isWin ? ".exe" : ""}`, targetFile: `verge-mihomo-alpha-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
exeFile, exeFile,
zipFile, zipFile,
downloadURL, downloadURL,
@ -189,8 +189,8 @@ function clashMeta() {
const zipFile = `${name}-${META_VERSION}.${urlExt}`; const zipFile = `${name}-${META_VERSION}.${urlExt}`;
return { return {
name: "clash-meta", name: "verge-mihomo",
targetFile: `clash-meta-${SIDECAR_HOST}${isWin ? ".exe" : ""}`, targetFile: `verge-mihomo-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
exeFile, exeFile,
zipFile, zipFile,
downloadURL, downloadURL,
@ -434,13 +434,13 @@ const resolveEnableLoopback = () =>
const tasks = [ const tasks = [
// { name: "clash", func: resolveClash, retry: 5 }, // { name: "clash", func: resolveClash, retry: 5 },
{ {
name: "clash-meta-alpha", name: "verge-mihomo-alpha",
func: () => func: () =>
getLatestAlphaVersion().then(() => resolveSidecar(clashMetaAlpha())), getLatestAlphaVersion().then(() => resolveSidecar(clashMetaAlpha())),
retry: 5, retry: 5,
}, },
{ {
name: "clash-meta", name: "verge-mihomo",
func: () => func: () =>
getLatestReleaseVersion().then(() => resolveSidecar(clashMeta())), getLatestReleaseVersion().then(() => resolveSidecar(clashMeta())),
retry: 5, retry: 5,

View File

@ -40,8 +40,8 @@ async function resolvePortable() {
const zip = new AdmZip(); const zip = new AdmZip();
zip.addLocalFile(path.join(releaseDir, "Clash Verge.exe")); zip.addLocalFile(path.join(releaseDir, "Clash Verge.exe"));
zip.addLocalFile(path.join(releaseDir, "clash-meta.exe")); zip.addLocalFile(path.join(releaseDir, "verge-mihomo.exe"));
zip.addLocalFile(path.join(releaseDir, "clash-meta-alpha.exe")); zip.addLocalFile(path.join(releaseDir, "verge-mihomo-alpha.exe"));
zip.addLocalFolder(path.join(releaseDir, "resources"), "resources"); zip.addLocalFolder(path.join(releaseDir, "resources"), "resources");
zip.addLocalFolder( zip.addLocalFolder(
path.join( path.join(

View File

@ -39,8 +39,8 @@ async function resolvePortable() {
const zip = new AdmZip(); const zip = new AdmZip();
zip.addLocalFile(path.join(releaseDir, "Clash Verge.exe")); zip.addLocalFile(path.join(releaseDir, "Clash Verge.exe"));
zip.addLocalFile(path.join(releaseDir, "clash-meta.exe")); zip.addLocalFile(path.join(releaseDir, "verge-mihomo.exe"));
zip.addLocalFile(path.join(releaseDir, "clash-meta-alpha.exe")); zip.addLocalFile(path.join(releaseDir, "verge-mihomo-alpha.exe"));
zip.addLocalFolder(path.join(releaseDir, "resources"), "resources"); zip.addLocalFolder(path.join(releaseDir, "resources"), "resources");
zip.addLocalFolder(configDir, ".config"); zip.addLocalFolder(configDir, ".config");

View File

@ -33,7 +33,7 @@ impl IClashTemp {
let mut map = Mapping::new(); let mut map = Mapping::new();
let mut tun = Mapping::new(); let mut tun = Mapping::new();
tun.insert("stack".into(), "gvisor".into()); tun.insert("stack".into(), "gvisor".into());
tun.insert("device".into(), "Meta".into()); tun.insert("device".into(), "Mihomo".into());
tun.insert("auto-route".into(), true.into()); tun.insert("auto-route".into(), true.into());
tun.insert("strict-route".into(), false.into()); tun.insert("strict-route".into(), false.into());
tun.insert("auto-detect-interface".into(), true.into()); tun.insert("auto-detect-interface".into(), true.into());

View File

@ -198,7 +198,7 @@ impl IVerge {
pub fn template() -> Self { pub fn template() -> Self {
Self { Self {
clash_core: Some("clash-meta".into()), clash_core: Some("verge-mihomo".into()),
language: Some("zh".into()), language: Some("zh".into()),
theme_mode: Some("system".into()), theme_mode: Some("system".into()),
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]

View File

@ -1,7 +1,7 @@
use super::service; use crate::config::*;
use super::{clash_api, logger::Logger}; use crate::core::{clash_api, handle, logger::Logger, service};
use crate::log_err; use crate::log_err;
use crate::{config::*, utils::dirs}; use crate::utils::dirs;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -72,21 +72,11 @@ impl CoreManager {
#[allow(unused_mut)] #[allow(unused_mut)]
let mut should_kill = match self.sidecar.lock().take() { let mut should_kill = match self.sidecar.lock().take() {
Some(child) => { Some(_) => true,
log::debug!(target: "app", "stop the core by sidecar");
let _ = child.kill();
true
}
None => false, None => false,
}; };
let mut system = System::new(); self.stop_core()?; // 先停止
system.refresh_all();
let procs = system.processes_by_name("clash-meta");
for proc in procs {
log::debug!(target: "app", "kill all clash process");
proc.kill();
}
if *self.use_service_mode.lock() { if *self.use_service_mode.lock() {
log::debug!(target: "app", "stop the core by service"); log::debug!(target: "app", "stop the core by service");
@ -128,16 +118,25 @@ impl CoreManager {
let app_dir = dirs::path_to_str(&app_dir)?; let app_dir = dirs::path_to_str(&app_dir)?;
let clash_core = { Config::verge().latest().clash_core.clone() }; let clash_core = { Config::verge().latest().clash_core.clone() };
let clash_core = clash_core.unwrap_or("clash".into()); let mut clash_core = clash_core.unwrap_or("verge-mihomo".into());
let is_clash = clash_core == "clash";
// compatibility
if clash_core.contains("clash") {
clash_core = "verge-mihomo".to_string();
Config::verge().draft().patch_config(IVerge {
clash_core: Some("verge-mihomo".to_string()),
..IVerge::default()
});
Config::verge().apply();
match Config::verge().data().save_file() {
Ok(_) => handle::Handle::refresh_verge(),
Err(err) => log::error!(target: "app", "{err}"),
}
}
let config_path = dirs::path_to_str(&config_path)?; let config_path = dirs::path_to_str(&config_path)?;
let args = match clash_core.as_str() { let args = vec!["-d", app_dir, "-f", config_path];
"clash-meta" => vec!["-d", app_dir, "-f", config_path],
"clash-meta-alpha" => vec!["-d", app_dir, "-f", config_path],
_ => vec!["-d", app_dir, "-f", config_path],
};
let cmd = Command::new_sidecar(clash_core)?; let cmd = Command::new_sidecar(clash_core)?;
let (mut rx, cmd_child) = cmd.args(args).spawn()?; let (mut rx, cmd_child) = cmd.args(args).spawn()?;
@ -150,25 +149,19 @@ impl CoreManager {
while let Some(event) = rx.recv().await { while let Some(event) = rx.recv().await {
match event { match event {
CommandEvent::Stdout(line) => { CommandEvent::Stdout(line) => {
if is_clash { log::info!(target: "app", "[mihomo]: {line}");
let stdout = clash_api::parse_log(line.clone());
log::info!(target: "app", "[clash]: {stdout}");
} else {
log::info!(target: "app", "[clash]: {line}");
};
Logger::global().set_log(line); Logger::global().set_log(line);
} }
CommandEvent::Stderr(err) => { CommandEvent::Stderr(err) => {
// let stdout = clash_api::parse_log(err.clone()); log::error!(target: "app", "[mihomo]: {err}");
log::error!(target: "app", "[clash]: {err}");
Logger::global().set_log(err); Logger::global().set_log(err);
} }
CommandEvent::Error(err) => { CommandEvent::Error(err) => {
log::error!(target: "app", "[clash]: {err}"); log::error!(target: "app", "[mihomo]: {err}");
Logger::global().set_log(err); Logger::global().set_log(err);
} }
CommandEvent::Terminated(_) => { CommandEvent::Terminated(_) => {
log::info!(target: "app", "clash core terminated"); log::info!(target: "app", "mihomo core terminated");
let _ = CoreManager::global().recover_core(); let _ = CoreManager::global().recover_core();
break; break;
} }
@ -188,9 +181,7 @@ impl CoreManager {
} }
// 清空原来的sidecar值 // 清空原来的sidecar值
if let Some(sidecar) = self.sidecar.lock().take() { let _ = self.sidecar.lock().take();
let _ = sidecar.kill();
}
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
// 6秒之后再查看服务是否正常 (时间随便搞的) // 6秒之后再查看服务是否正常 (时间随便搞的)
@ -234,13 +225,11 @@ impl CoreManager {
} }
let mut sidecar = self.sidecar.lock(); let mut sidecar = self.sidecar.lock();
if let Some(child) = sidecar.take() { let _ = sidecar.take();
log::debug!(target: "app", "stop the core by sidecar");
let _ = child.kill();
}
let mut system = System::new(); let mut system = System::new();
system.refresh_all(); system.refresh_all();
let procs = system.processes_by_name("clash-meta"); let procs = system.processes_by_name("verge-mihomo");
for proc in procs { for proc in procs {
log::debug!(target: "app", "kill all clash process"); log::debug!(target: "app", "kill all clash process");
proc.kill(); proc.kill();
@ -251,7 +240,7 @@ impl CoreManager {
/// 切换核心 /// 切换核心
pub async fn change_core(&self, clash_core: Option<String>) -> Result<()> { pub async fn change_core(&self, clash_core: Option<String>) -> Result<()> {
let clash_core = clash_core.ok_or(anyhow::anyhow!("clash core is null"))?; let clash_core = clash_core.ok_or(anyhow::anyhow!("clash core is null"))?;
const CLASH_CORES: [&str; 2] = ["clash-meta", "clash-meta-alpha"]; const CLASH_CORES: [&str; 2] = ["verge-mihomo", "verge-mihomo-alpha"];
if !CLASH_CORES.contains(&clash_core.as_str()) { if !CLASH_CORES.contains(&clash_core.as_str()) {
bail!("invalid clash core name \"{clash_core}\""); bail!("invalid clash core name \"{clash_core}\"");

View File

@ -1,4 +1,5 @@
use crate::config::Config; use crate::config::{Config, IVerge};
use crate::core::handle;
use crate::utils::dirs; use crate::utils::dirs;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -237,7 +238,21 @@ pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
} }
let clash_core = { Config::verge().latest().clash_core.clone() }; let clash_core = { Config::verge().latest().clash_core.clone() };
let clash_core = clash_core.unwrap_or("clash".into()); let mut clash_core = clash_core.unwrap_or("verge-mihomo".into());
// compatibility
if clash_core.contains("clash") {
clash_core = "verge-mihomo".to_string();
Config::verge().draft().patch_config(IVerge {
clash_core: Some("verge-mihomo".to_string()),
..IVerge::default()
});
Config::verge().apply();
match Config::verge().data().save_file() {
Ok(_) => handle::Handle::refresh_verge(),
Err(err) => log::error!(target: "app", "{err}"),
}
}
let bin_ext = if cfg!(windows) { ".exe" } else { "" }; let bin_ext = if cfg!(windows) { ".exe" } else { "" };
let clash_bin = format!("{clash_core}{bin_ext}"); let clash_bin = format!("{clash_core}{bin_ext}");

View File

@ -92,8 +92,8 @@ impl ChainSupport {
(self, core.as_str()), (self, core.as_str()),
(ChainSupport::All, _) (ChainSupport::All, _)
| (ChainSupport::Clash, "clash") | (ChainSupport::Clash, "clash")
| (ChainSupport::ClashMeta, "clash-meta") | (ChainSupport::ClashMeta, "verge-mihomo")
| (ChainSupport::ClashMetaAlpha, "clash-meta-alpha") | (ChainSupport::ClashMetaAlpha, "verge-mihomo-alpha")
), ),
None => true, None => true,
} }

View File

@ -23,7 +23,7 @@
], ],
"resources": ["resources"], "resources": ["resources"],
"publisher": "Clash Verge Rev", "publisher": "Clash Verge Rev",
"externalBin": ["sidecar/clash-meta", "sidecar/clash-meta-alpha"], "externalBin": ["sidecar/verge-mihomo", "sidecar/verge-mihomo-alpha"],
"copyright": "GNU General Public License v3.0", "copyright": "GNU General Public License v3.0",
"category": "DeveloperTool", "category": "DeveloperTool",
"shortDescription": "A Clash Meta GUI based on tauri.", "shortDescription": "A Clash Meta GUI based on tauri.",

View File

@ -10,16 +10,16 @@
"deb": { "deb": {
"depends": ["openssl"], "depends": ["openssl"],
"desktopTemplate": "./template/clash-verge.desktop", "desktopTemplate": "./template/clash-verge.desktop",
"provides": ["clash-verge", "clash-meta"], "provides": ["clash-verge"],
"conflicts": ["clash-verge", "clash-meta"], "conflicts": ["clash-verge"],
"replaces": ["clash-verge", "clash-meta"] "replaces": ["clash-verge"]
}, },
"rpm": { "rpm": {
"depends": ["openssl"], "depends": ["openssl"],
"desktopTemplate": "./template/clash-verge.desktop", "desktopTemplate": "./template/clash-verge.desktop",
"provides": ["clash-verge", "clash-meta"], "provides": ["clash-verge"],
"conflicts": ["clash-verge", "clash-meta"], "conflicts": ["clash-verge"],
"obsoletes": ["clash-verge", "clash-meta"] "obsoletes": ["clash-verge"]
} }
} }
} }

View File

@ -441,6 +441,38 @@ FunctionEnd
!endif !endif
${EndIf} ${EndIf}
; Check if verge-mihomo-alpha.exe is running
!if "${INSTALLMODE}" == "currentUser"
nsis_tauri_utils::FindProcessCurrentUser "verge-mihomo-alpha.exe"
!else
nsis_tauri_utils::FindProcess "verge-mihomo-alpha.exe"
!endif
Pop $R0
${If} $R0 = 0
DetailPrint "Kill verge-mihomo-alpha.exe..."
!if "${INSTALLMODE}" == "currentUser"
nsis_tauri_utils::KillProcessCurrentUser "verge-mihomo-alpha.exe"
!else
nsis_tauri_utils::KillProcess "verge-mihomo-alpha.exe"
!endif
${EndIf}
; Check if verge-mihomo.exe is running
!if "${INSTALLMODE}" == "currentUser"
nsis_tauri_utils::FindProcessCurrentUser "verge-mihomo.exe"
!else
nsis_tauri_utils::FindProcess "verge-mihomo.exe"
!endif
Pop $R0
${If} $R0 = 0
DetailPrint "Kill verge-mihomo.exe..."
!if "${INSTALLMODE}" == "currentUser"
nsis_tauri_utils::KillProcessCurrentUser "verge-mihomo.exe"
!else
nsis_tauri_utils::KillProcess "verge-mihomo.exe"
!endif
${EndIf}
; Check if clash-meta-alpha.exe is running ; Check if clash-meta-alpha.exe is running
!if "${INSTALLMODE}" == "currentUser" !if "${INSTALLMODE}" == "currentUser"
nsis_tauri_utils::FindProcessCurrentUser "clash-meta-alpha.exe" nsis_tauri_utils::FindProcessCurrentUser "clash-meta-alpha.exe"

View File

@ -70,8 +70,8 @@ export const LayoutTraffic = () => {
); );
/* --------- meta memory information --------- */ /* --------- meta memory information --------- */
const isMetaCore = verge?.clash_core?.includes("clash-meta");
const displayMemory = isMetaCore && (verge?.enable_memory_usage ?? true); const displayMemory = verge?.enable_memory_usage ?? true;
const { data: memory = { inuse: 0 } } = useSWRSubscription< const { data: memory = { inuse: 0 } } = useSWRSubscription<
MemoryUsage, MemoryUsage,

View File

@ -12,8 +12,8 @@ import { closeAllConnections, upgradeCore } from "@/services/api";
import getSystem from "@/utils/get-system"; import getSystem from "@/utils/get-system";
const VALID_CORE = [ const VALID_CORE = [
{ name: "Clash Meta", core: "clash-meta" }, { name: "Mihomo", core: "verge-mihomo" },
{ name: "Clash Meta Alpha", core: "clash-meta-alpha" }, { name: "Mihomo Alpha", core: "verge-mihomo-alpha" },
]; ];
const OS = getSystem(); const OS = getSystem();
@ -31,7 +31,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
close: () => setOpen(false), close: () => setOpen(false),
})); }));
const { clash_core = "clash-meta" } = verge ?? {}; const { clash_core = "verge-mihomo" } = verge ?? {};
const onCoreChange = useLockFn(async (core: string) => { const onCoreChange = useLockFn(async (core: string) => {
if (core === clash_core) return; if (core === clash_core) return;

View File

@ -23,7 +23,7 @@ export const TunViewer = forwardRef<DialogRef>((props, ref) => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [values, setValues] = useState({ const [values, setValues] = useState({
stack: "gvisor", stack: "gvisor",
device: "Meta", device: "Mihomo",
autoRoute: true, autoRoute: true,
autoDetectInterface: true, autoDetectInterface: true,
dnsHijack: ["any:53"], dnsHijack: ["any:53"],
@ -36,7 +36,7 @@ export const TunViewer = forwardRef<DialogRef>((props, ref) => {
setOpen(true); setOpen(true);
setValues({ setValues({
stack: clash?.tun.stack ?? "gvisor", stack: clash?.tun.stack ?? "gvisor",
device: clash?.tun.device ?? "Meta", device: clash?.tun.device ?? "Mihomo",
autoRoute: clash?.tun["auto-route"] ?? true, autoRoute: clash?.tun["auto-route"] ?? true,
autoDetectInterface: clash?.tun["auto-detect-interface"] ?? true, autoDetectInterface: clash?.tun["auto-detect-interface"] ?? true,
dnsHijack: clash?.tun["dns-hijack"] ?? ["any:53"], dnsHijack: clash?.tun["dns-hijack"] ?? ["any:53"],
@ -51,7 +51,7 @@ export const TunViewer = forwardRef<DialogRef>((props, ref) => {
try { try {
let tun = { let tun = {
stack: values.stack, stack: values.stack,
device: values.device === "" ? "Meta" : values.device, device: values.device === "" ? "Mihomo" : values.device,
"auto-route": values.autoRoute, "auto-route": values.autoRoute,
"auto-detect-interface": values.autoDetectInterface, "auto-detect-interface": values.autoDetectInterface,
"dns-hijack": values.dnsHijack[0] === "" ? [] : values.dnsHijack, "dns-hijack": values.dnsHijack[0] === "" ? [] : values.dnsHijack,
@ -90,7 +90,7 @@ export const TunViewer = forwardRef<DialogRef>((props, ref) => {
onClick={async () => { onClick={async () => {
let tun = { let tun = {
stack: "gvisor", stack: "gvisor",
device: "Meta", device: "Mihomo",
"auto-route": true, "auto-route": true,
"auto-detect-interface": true, "auto-detect-interface": true,
"dns-hijack": ["any:53"], "dns-hijack": ["any:53"],
@ -99,7 +99,7 @@ export const TunViewer = forwardRef<DialogRef>((props, ref) => {
}; };
setValues({ setValues({
stack: "gvisor", stack: "gvisor",
device: "Meta", device: "Mihomo",
autoRoute: true, autoRoute: true,
autoDetectInterface: true, autoDetectInterface: true,
dnsHijack: ["any:53"], dnsHijack: ["any:53"],
@ -151,7 +151,7 @@ export const TunViewer = forwardRef<DialogRef>((props, ref) => {
spellCheck="false" spellCheck="false"
sx={{ width: 250 }} sx={{ width: 250 }}
value={values.device} value={values.device}
placeholder="Meta" placeholder="Mihomo"
onChange={(e) => onChange={(e) =>
setValues((v) => ({ ...v, device: e.target.value })) setValues((v) => ({ ...v, device: e.target.value }))
} }

View File

@ -27,7 +27,7 @@ export const useClash = () => {
const version = versionData?.premium const version = versionData?.premium
? `${versionData.version} Premium` ? `${versionData.version} Premium`
: versionData?.meta : versionData?.meta
? `${versionData.version} Meta` ? `${versionData.version} Mihomo`
: versionData?.version || "-"; : versionData?.version || "-";
return { return {

View File

@ -24,12 +24,7 @@ const ProxyPage = () => {
const { verge } = useVerge(); const { verge } = useVerge();
const modeList = useMemo(() => { const modeList = ["rule", "global", "direct"];
if (verge?.clash_core?.includes("clash-meta")) {
return ["rule", "global", "direct"];
}
return ["rule", "global", "direct", "script"];
}, [verge?.clash_core]);
const curMode = clashConfig?.mode?.toLowerCase(); const curMode = clashConfig?.mode?.toLowerCase();