feat: clash meta core support (wip)

This commit is contained in:
GyDi
2022-05-16 01:52:50 +08:00
parent c382ad1cc8
commit b3a72d55ae
5 changed files with 149 additions and 37 deletions

View File

@@ -46,7 +46,9 @@ winreg = { version = "0.10", features = ["transactions"] }
[features]
default = ["custom-protocol", "tauri/ayatana-tray"]
custom-protocol = ["tauri/custom-protocol"]
meta-dev = ["clash-meta", "verge-dev"]
verge-dev = []
clash-meta = []
debug-yml = []
[profile.release]

View File

@@ -9,6 +9,8 @@ use std::{collections::HashMap, time::Duration};
use tauri::api::process::{Command, CommandChild, CommandEvent};
use tokio::time::sleep;
static mut CLASH_CORE: &str = "clash";
#[derive(Debug)]
pub struct Service {
sidecar: Option<CommandChild>,
@@ -25,6 +27,12 @@ impl Service {
}
}
pub fn set_core(&mut self, clash_core: Option<String>) {
unsafe {
CLASH_CORE = Box::leak(clash_core.unwrap_or("clash".into()).into_boxed_str());
}
}
#[allow(unused)]
pub fn set_mode(&mut self, enable: bool) {
self.service_mode = enable;
@@ -92,7 +100,8 @@ impl Service {
let app_dir = dirs::app_home_dir();
let app_dir = app_dir.as_os_str().to_str().unwrap();
let cmd = Command::new_sidecar("clash")?;
let clash_core = unsafe { CLASH_CORE };
let cmd = Command::new_sidecar(clash_core)?;
let (mut rx, cmd_child) = cmd.args(["-d", app_dir]).spawn()?;
self.sidecar = Some(cmd_child);
@@ -342,7 +351,9 @@ pub mod win_service {
sleep(Duration::from_secs(1)).await;
}
let bin_path = current_exe().unwrap().with_file_name("clash.exe");
let clash_core = unsafe { CLASH_CORE };
let clash_bin = format!("{clash_core}.exe");
let bin_path = current_exe().unwrap().with_file_name(clash_bin);
let bin_path = bin_path.as_os_str().to_str().unwrap();
let config_dir = dirs::app_home_dir();

View File

@@ -45,6 +45,10 @@ pub struct Verge {
/// theme setting
pub theme_setting: Option<VergeTheme>,
/// clash core path
#[serde(skip_serializing_if = "Option::is_none")]
pub clash_core: Option<String>,
}
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
@@ -96,6 +100,9 @@ impl Verge {
if patch.traffic_graph.is_some() {
self.traffic_graph = patch.traffic_graph;
}
if patch.clash_core.is_some() {
self.clash_core = patch.clash_core;
}
// system setting
if patch.enable_silent_start.is_some() {

View File

@@ -0,0 +1,7 @@
{
"tauri": {
"bundle": {
"externalBin": ["sidecar/clash", "sidecar/clash-meta"]
}
}
}