Skip to content

Commit

Permalink
fixup! Add geodata and clashconfig to Profile Info
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanChane committed Jun 21, 2024
1 parent 8e5c957 commit 4e08af0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion clashtui/src/tui/tabs/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl super::TabEvent for ProfileTab {
EventState::WorkDone
}
Keys::ProfileInfo => {
self.popup_txt_msg("Generate info...".to_string());
self.popup_txt_msg("Generating info...".to_string());
self.op.replace(PTOp::GenInfo);
EventState::WorkDone

Expand Down
74 changes: 49 additions & 25 deletions clashtui/src/utils/tui/impl_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,28 @@ impl ClashTuiUtil {
use std::time::{SystemTime, UNIX_EPOCH, Duration};
use chrono::{DateTime, Utc};

// ## Providers
let mut info = vec!["## Providers".to_string()];
let profile_url = self.extract_profile_url(profile_name)?;
info.push(format!("Profile Url: {}", profile_url));
let with_proxy = self.check_proxy();

// ## Profile
let mut info = vec!["## Profile".to_string()];
let profile_type = self.get_profile_type(profile_name)
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::Other, "Profile type not found"))?;
if profile_type == ProfileType::Url {
let profile_url = self.extract_profile_url(profile_name)?;
info.push(format!("Url: {}", profile_url));

if let Ok(rsp) = self.dl_remote_profile(profile_url.as_str(), with_proxy) {
info.push(format!("- subscription-userinfo: {}",
self.str_human_readable_userinfo(&rsp).unwrap_or_else(|e| e.to_string())));
for key in vec!["profile-update-interval"] {
info.push(format!("- {}: {}",
key,
rsp.get_headers().get(key).unwrap_or(&"None".to_string())));
}
}
}

// ## Providers
let profile_yaml_path = self.get_profile_yaml_path(profile_name)?;
let yaml_content = std::fs::read_to_string(&profile_yaml_path)?;
let parsed_yaml = match serde_yaml::from_str::<serde_yaml::Value>(&yaml_content) {
Expand All @@ -633,38 +650,45 @@ impl ClashTuiUtil {
};

let clash_cfg_dir = Path::new(&self.tui_cfg.clash_cfg_dir);
let with_proxy = self.check_proxy();
let net_providers = self.extract_net_provider_helper(&parsed_yaml, &vec![ProfileSectionType::Profile, ProfileSectionType::ProxyProvider, ProfileSectionType::RuleProvider]);
if let Ok(net_res) = net_providers {
for (st, res) in net_res {
let st_str = match st {
ProfileSectionType::ProxyProvider => "Proxy Providers",
ProfileSectionType::RuleProvider => "Rule Providers",
_ => unreachable!(),
};
info.push(format!("{}:", st_str));

let now = std::time::SystemTime::now();
for (name, url, path) in res {
let now = std::time::SystemTime::now();
// ### Proxy Providers
net_res.get(&ProfileSectionType::ProxyProvider).map(|pp_net_res| {
info.push("## Proxy Providers".to_string());
for (name, url, path) in pp_net_res {
let p = clash_cfg_dir.join(path).to_path_buf();
let dur_str = Utils::gen_file_dur_str(&p, Some(now)).unwrap_or("None".to_string());
info.push(format!("- {} ({}): {}",
name,
dur_str,
url));
if st == ProfileSectionType::ProxyProvider {
if let Ok(rsp) = self.dl_remote_profile(url.as_str(), with_proxy) {
info.push(format!(" - subscription-userinfo: {}",
self.str_human_readable_userinfo(&rsp).unwrap_or_else(|e| e.to_string())));
for key in vec!["profile-update-interval"] {
info.push(format!(" - {}: {}",
key,
rsp.get_headers().get(key).unwrap_or(&"None".to_string())));
}

if let Ok(rsp) = self.dl_remote_profile(url.as_str(), with_proxy) {
info.push(format!(" - subscription-userinfo: {}",
self.str_human_readable_userinfo(&rsp).unwrap_or_else(|e| e.to_string())));
for key in vec!["profile-update-interval"] {
info.push(format!(" - {}: {}",
key,
rsp.get_headers().get(key).unwrap_or(&"None".to_string())));
}
}
}
}

});

// ### Rule Providers
net_res.get(&ProfileSectionType::RuleProvider).map(|pp_net_res| {
info.push("## Rule Providers".to_string());
for (name, url, path) in pp_net_res {
let p = clash_cfg_dir.join(path).to_path_buf();
let dur_str = Utils::gen_file_dur_str(&p, Some(now)).unwrap_or("None".to_string());
info.push(format!("- {} ({}): {}",
name,
dur_str,
url));
}
});
}

if !is_cur_profile {
Expand Down

0 comments on commit 4e08af0

Please sign in to comment.