clash-verge/src-tauri/src/clash.rs

30 lines
709 B
Rust
Raw Normal View History

2021-12-08 18:40:52 +03:00
extern crate log;
2021-12-04 09:31:26 +03:00
2021-12-08 18:40:52 +03:00
use crate::init::app_home_dir;
2021-12-04 09:31:26 +03:00
use tauri::api::process::{Command, CommandEvent};
/// Run the clash bin
2021-12-08 18:40:52 +03:00
pub fn run_clash_bin() {
let app_dir = app_home_dir();
let (mut rx, _sidecar) = Command::new_sidecar("clash")
2021-12-04 09:31:26 +03:00
.expect("failed to create clash binary")
2021-12-08 18:40:52 +03:00
.args(["-d", &app_dir.as_os_str().to_str().unwrap()])
2021-12-04 09:31:26 +03:00
.spawn()
.expect("failed to spawn sidecar");
tauri::async_runtime::spawn(async move {
while let Some(event) = rx.recv().await {
2021-12-08 18:40:52 +03:00
match event {
CommandEvent::Stdout(line) => {
log::info!("{}", line);
}
CommandEvent::Stderr(err) => {
log::error!("{}", err);
}
_ => {}
2021-12-04 09:31:26 +03:00
}
}
});
}