mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
feat: runtime config viewer
This commit is contained in:
@@ -174,6 +174,13 @@ pub fn get_clash_info(core: State<'_, Core>) -> CmdResult<ClashInfo> {
|
||||
Ok(clash.info.clone())
|
||||
}
|
||||
|
||||
/// get the running clash config string
|
||||
#[tauri::command]
|
||||
pub fn get_running_config(core: State<'_, Core>) -> CmdResult<Option<String>> {
|
||||
let clash = core.clash.lock();
|
||||
Ok(clash.running_config.clone())
|
||||
}
|
||||
|
||||
/// update the clash core config
|
||||
/// after putting the change to the clash core
|
||||
/// then we should save the latest config
|
||||
|
||||
@@ -87,6 +87,9 @@ pub struct Clash {
|
||||
|
||||
/// some info
|
||||
pub info: ClashInfo,
|
||||
|
||||
/// save the running config
|
||||
pub running_config: Option<String>,
|
||||
}
|
||||
|
||||
impl Clash {
|
||||
@@ -94,7 +97,11 @@ impl Clash {
|
||||
let config = Clash::read_config();
|
||||
let info = ClashInfo::from(&config);
|
||||
|
||||
Clash { config, info }
|
||||
Clash {
|
||||
config,
|
||||
info,
|
||||
running_config: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// get clash config
|
||||
@@ -111,6 +118,14 @@ impl Clash {
|
||||
)
|
||||
}
|
||||
|
||||
/// save running config
|
||||
pub fn set_running_config(&mut self, config: &Mapping) {
|
||||
self.running_config = match serde_yaml::to_string(config) {
|
||||
Ok(config_str) => Some(config_str),
|
||||
Err(_) => None,
|
||||
};
|
||||
}
|
||||
|
||||
/// patch update the clash config
|
||||
/// if the port is changed then return true
|
||||
pub fn patch_config(&mut self, patch: Mapping) -> Result<(bool, bool)> {
|
||||
|
||||
@@ -347,12 +347,10 @@ impl Core {
|
||||
Clash::strict_filter(data)
|
||||
};
|
||||
|
||||
let (mut config, info) = {
|
||||
let clash = self.clash.lock();
|
||||
let config = clash.config.clone();
|
||||
let info = clash.info.clone();
|
||||
(config, info)
|
||||
};
|
||||
let mut clash = self.clash.lock();
|
||||
|
||||
let mut config = clash.config.clone();
|
||||
let info = clash.info.clone();
|
||||
|
||||
for (key, value) in data.into_iter() {
|
||||
config.insert(key, value);
|
||||
@@ -369,6 +367,9 @@ impl Core {
|
||||
Notice::from(window.clone())
|
||||
};
|
||||
|
||||
clash.set_running_config(&config);
|
||||
drop(clash);
|
||||
|
||||
let service = self.service.lock();
|
||||
service.set_config(info, config, notice)
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ fn main() -> std::io::Result<()> {
|
||||
cmds::get_clash_info,
|
||||
cmds::patch_clash_config,
|
||||
cmds::change_clash_core,
|
||||
cmds::get_running_config,
|
||||
// verge
|
||||
cmds::get_verge_config,
|
||||
cmds::patch_verge_config,
|
||||
|
||||
Reference in New Issue
Block a user