mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat(profiles): add profile preview structure and update profile menu handling
This commit is contained in:
@@ -21,6 +21,12 @@ pub struct IProfiles {
|
||||
pub items: Option<Vec<PrfItem>>,
|
||||
}
|
||||
|
||||
pub struct IProfilePreview<'a> {
|
||||
pub uid: &'a String,
|
||||
pub name: &'a String,
|
||||
pub is_current: bool,
|
||||
}
|
||||
|
||||
/// 清理结果
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CleanupResult {
|
||||
@@ -367,14 +373,20 @@ impl IProfiles {
|
||||
self.current.as_ref() == Some(index)
|
||||
}
|
||||
|
||||
/// 获取所有的profiles(uid,名称)
|
||||
pub fn all_profile_uid_and_name(&self) -> Option<Vec<(&String, &String)>> {
|
||||
/// 获取所有的profiles(uid,名称, 是否为 current)
|
||||
pub fn profiles_preview(&self) -> Option<Vec<IProfilePreview<'_>>> {
|
||||
self.items.as_ref().map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
if let (Some(uid), Some(name)) = (e.uid.as_ref(), e.name.as_ref()) {
|
||||
Some((uid, name))
|
||||
let is_current = self.is_current_profile_index(uid);
|
||||
let preview = IProfilePreview {
|
||||
uid,
|
||||
name,
|
||||
is_current,
|
||||
};
|
||||
Some(preview)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user