fix: MIME config (#5154)

* fix: MIME config #2487

* fix: path

* refactor: enhance logic
This commit is contained in:
Sline
2025-10-21 22:02:41 +08:00
committed by GitHub
parent e7a4415d1f
commit 9c9aefe4cd
2 changed files with 248 additions and 10 deletions

View File

@@ -490,17 +490,24 @@ pub fn init_scheme() -> Result<()> {
}
#[cfg(target_os = "linux")]
pub fn init_scheme() -> Result<()> {
let output = std::process::Command::new("xdg-mime")
.arg("default")
.arg("clash-verge.desktop")
.arg("x-scheme-handler/clash")
.output()?;
if !output.status.success() {
return Err(anyhow::anyhow!(
"failed to set clash scheme, {}",
String::from_utf8_lossy(&output.stderr)
));
const DESKTOP_FILE: &str = "clash-verge.desktop";
for scheme in DEEP_LINK_SCHEMES {
let handler = format!("x-scheme-handler/{scheme}");
let output = std::process::Command::new("xdg-mime")
.arg("default")
.arg(DESKTOP_FILE)
.arg(&handler)
.output()?;
if !output.status.success() {
return Err(anyhow::anyhow!(
"failed to set {handler}, {}",
String::from_utf8_lossy(&output.stderr)
));
}
}
crate::utils::linux::ensure_mimeapps_entries(DESKTOP_FILE, DEEP_LINK_SCHEMES)?;
Ok(())
}
#[cfg(target_os = "macos")]
@@ -508,6 +515,9 @@ pub fn init_scheme() -> Result<()> {
Ok(())
}
#[cfg(target_os = "linux")]
const DEEP_LINK_SCHEMES: &[&str] = &["clash", "clash-verge"];
pub async fn startup_script() -> Result<()> {
let app_handle = handle::Handle::app_handle();
let script_path = {