feat(profiles): add profile preview structure and update profile menu handling

This commit is contained in:
Tunglies
2025-11-18 19:08:07 +08:00
parent ec7f912eae
commit 3ec7c6d2b8
3 changed files with 37 additions and 32 deletions

View File

@@ -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
}