feat: support set system proxy command

This commit is contained in:
GyDi
2021-12-17 02:15:40 +08:00
parent ad60013f52
commit 3a9734e97d
5 changed files with 76 additions and 4 deletions

View File

@@ -21,6 +21,9 @@ pub struct ClashConfig {
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct ClashController {
/// clash core port
pub port: Option<String>,
/// same as `external-controller`
pub server: Option<String>,
pub secret: Option<String>,

View File

@@ -44,9 +44,31 @@ pub fn read_clash() -> Mapping {
pub fn read_clash_controller() -> ClashController {
let config = read_clash();
let key_port_1 = Value::String("port".to_string());
let key_port_2 = Value::String("mixed-port".to_string());
let key_server = Value::String("external-controller".to_string());
let key_secret = Value::String("secret".to_string());
let port = match config.get(&key_port_1) {
Some(value) => match value {
Value::String(val_str) => Some(val_str.clone()),
Value::Number(val_num) => Some(val_num.to_string()),
_ => None,
},
_ => None,
};
let port = match port {
Some(_) => port,
None => match config.get(&key_port_2) {
Some(value) => match value {
Value::String(val_str) => Some(val_str.clone()),
Value::Number(val_num) => Some(val_num.to_string()),
_ => None,
},
_ => None,
},
};
let server = match config.get(&key_server) {
Some(value) => match value {
Value::String(val_str) => Some(val_str.clone()),
@@ -64,7 +86,11 @@ pub fn read_clash_controller() -> ClashController {
_ => None,
};
ClashController { server, secret }
ClashController {
port,
server,
secret,
}
}
/// Get Profiles Config