mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 03:32:36 +08:00
feat: Support URL Scheme for Linux
This commit is contained in:
parent
3c6d6b90bc
commit
3a2a7a1476
6
src-tauri/src/utils/desktop/clash-verge-scheme.desktop
Normal file
6
src-tauri/src/utils/desktop/clash-verge-scheme.desktop
Normal file
|
@ -0,0 +1,6 @@
|
|||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Clash Verge Scheme Handler
|
||||
Exec=clash-verge %u
|
||||
StartupNotify=false
|
||||
MimeType=x-scheme-handler/clash;
|
|
@ -92,6 +92,14 @@ pub fn clash_pid_path() -> Result<PathBuf> {
|
|||
Ok(app_home_dir()?.join("clash.pid"))
|
||||
}
|
||||
|
||||
#[cfg(linux)]
|
||||
pub fn local_applications_dir() -> Result<PathBuf> {
|
||||
use tauri::api::path::home_dir;
|
||||
Ok(home_dir()
|
||||
.ok_or(anyhow::anyhow!("failed to get home dir"))?
|
||||
.join(".local/share/applications"))
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn service_dir() -> Result<PathBuf> {
|
||||
Ok(app_home_dir()?.join("service"))
|
||||
|
|
|
@ -325,6 +325,28 @@ pub fn init_scheme() -> Result<()> {
|
|||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn init_scheme() -> Result<()> {
|
||||
use std::io::Write;
|
||||
|
||||
let desktop_file_content = include_str!("./desktop/clash-verge-scheme.desktop");
|
||||
let desktop_dir = dirs::local_applications_dir()?;
|
||||
if !desktop_dir.exists() {
|
||||
let _ = std::fs::create_dir_all(&desktop_dir);
|
||||
}
|
||||
let mut desktop_file =
|
||||
std::fs::File::create(dirs::local_applications_dir()?.join("clash-verge-scheme.desktop"))?;
|
||||
desktop_file.write_all(desktop_file_content.as_bytes())?;
|
||||
|
||||
let output = std::process::Command::new("xdg-mime")
|
||||
.arg("default")
|
||||
.arg("clash-verge-scheme.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)
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
|
|
Loading…
Reference in New Issue
Block a user