detailed profiles info

This commit is contained in:
Julian Freeman
2026-04-16 17:50:33 -04:00
parent 33f43aac56
commit 65b9401726
9 changed files with 356 additions and 98 deletions

View File

@@ -1,4 +1,4 @@
use std::collections::BTreeSet;
use std::collections::{BTreeMap, BTreeSet};
use serde::{Deserialize, Serialize};
@@ -49,6 +49,7 @@ pub struct ExtensionSummary {
pub version: Option<String>,
pub icon_data_url: Option<String>,
pub profile_ids: Vec<String>,
pub profiles: Vec<AssociatedProfileSummary>,
}
#[derive(Serialize)]
@@ -57,6 +58,26 @@ pub struct BookmarkSummary {
pub url: String,
pub title: String,
pub profile_ids: Vec<String>,
pub profiles: Vec<BookmarkAssociatedProfileSummary>,
}
#[derive(Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AssociatedProfileSummary {
pub id: String,
pub name: String,
pub avatar_data_url: Option<String>,
pub avatar_label: String,
}
#[derive(Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BookmarkAssociatedProfileSummary {
pub id: String,
pub name: String,
pub avatar_data_url: Option<String>,
pub avatar_label: String,
pub bookmark_path: String,
}
#[derive(Serialize)]
@@ -124,10 +145,12 @@ pub struct TempExtension {
pub version: Option<String>,
pub icon_data_url: Option<String>,
pub profile_ids: BTreeSet<String>,
pub profiles: BTreeMap<String, AssociatedProfileSummary>,
}
pub struct TempBookmark {
pub url: String,
pub title: String,
pub profile_ids: BTreeSet<String>,
pub profiles: BTreeMap<String, BookmarkAssociatedProfileSummary>,
}

View File

@@ -10,8 +10,9 @@ use tauri::AppHandle;
use crate::{
config_store,
models::{
BookmarkSummary, BrowserConfigEntry, BrowserStats, BrowserView, ExtensionSummary,
ProfileSummary, ScanResponse, TempBookmark, TempExtension,
AssociatedProfileSummary, BookmarkAssociatedProfileSummary, BookmarkSummary,
BrowserConfigEntry, BrowserStats, BrowserView, ExtensionSummary, ProfileSummary,
ScanResponse, TempBookmark, TempExtension,
},
utils::{first_non_empty, load_image_as_data_url, pick_latest_subdirectory, read_json_file},
};
@@ -57,14 +58,15 @@ fn scan_browser(config: BrowserConfigEntry) -> Option<BrowserView> {
}
let profile_info = profile_cache.and_then(|cache| cache.get(&profile_id));
profiles.push(build_profile_summary(
let profile_summary = build_profile_summary(
&root,
&profile_path,
&profile_id,
profile_info,
));
scan_extensions_for_profile(&profile_path, &profile_id, &mut extensions);
scan_bookmarks_for_profile(&profile_path, &profile_id, &mut bookmarks);
);
scan_extensions_for_profile(&profile_path, &profile_summary, &mut extensions);
scan_bookmarks_for_profile(&profile_path, &profile_summary, &mut bookmarks);
profiles.push(profile_summary);
}
let profiles = sort_profiles(profiles);
@@ -76,6 +78,7 @@ fn scan_browser(config: BrowserConfigEntry) -> Option<BrowserView> {
version: entry.version,
icon_data_url: entry.icon_data_url,
profile_ids: entry.profile_ids.into_iter().collect(),
profiles: entry.profiles.into_values().collect(),
})
.collect::<Vec<_>>();
let bookmarks = bookmarks
@@ -84,6 +87,7 @@ fn scan_browser(config: BrowserConfigEntry) -> Option<BrowserView> {
url: entry.url,
title: entry.title,
profile_ids: entry.profile_ids.into_iter().collect(),
profiles: entry.profiles.into_values().collect(),
})
.collect::<Vec<_>>();
@@ -188,7 +192,7 @@ fn resolve_profile_avatar(
fn scan_extensions_for_profile(
profile_path: &Path,
profile_id: &str,
profile: &ProfileSummary,
extensions: &mut BTreeMap<String, TempExtension>,
) {
let extensions_root = profile_path.join("Extensions");
@@ -231,6 +235,7 @@ fn scan_extensions_for_profile(
version: version.clone(),
icon_data_url: icon_data_url.clone(),
profile_ids: BTreeSet::new(),
profiles: BTreeMap::new(),
});
if entry.name == entry.id && name != extension_id {
@@ -242,7 +247,16 @@ fn scan_extensions_for_profile(
if entry.icon_data_url.is_none() {
entry.icon_data_url = icon_data_url.clone();
}
entry.profile_ids.insert(profile_id.to_string());
entry.profile_ids.insert(profile.id.clone());
entry
.profiles
.entry(profile.id.clone())
.or_insert_with(|| AssociatedProfileSummary {
id: profile.id.clone(),
name: profile.name.clone(),
avatar_data_url: profile.avatar_data_url.clone(),
avatar_label: profile.avatar_label.clone(),
});
}
}
@@ -337,7 +351,7 @@ fn icon_candidates_from_object(map: &serde_json::Map<String, Value>) -> Vec<(u32
fn scan_bookmarks_for_profile(
profile_path: &Path,
profile_id: &str,
profile: &ProfileSummary,
bookmarks: &mut BTreeMap<String, TempBookmark>,
) {
let bookmarks_path = profile_path.join("Bookmarks");
@@ -350,14 +364,15 @@ fn scan_bookmarks_for_profile(
};
for root in roots.values() {
collect_bookmarks(root, profile_id, bookmarks);
collect_bookmarks(root, profile, bookmarks, &[]);
}
}
fn collect_bookmarks(
node: &Value,
profile_id: &str,
profile: &ProfileSummary,
bookmarks: &mut BTreeMap<String, TempBookmark>,
ancestors: &[String],
) {
match node.get("type").and_then(Value::as_str) {
Some("url") => {
@@ -381,17 +396,44 @@ fn collect_bookmarks(
url: url.to_string(),
title: title.clone(),
profile_ids: BTreeSet::new(),
profiles: BTreeMap::new(),
});
if entry.title == entry.url && title != url {
entry.title = title;
}
entry.profile_ids.insert(profile_id.to_string());
entry.profile_ids.insert(profile.id.clone());
let bookmark_path = if ancestors.is_empty() {
"Root".to_string()
} else {
ancestors.join(" > ")
};
entry
.profiles
.entry(profile.id.clone())
.or_insert_with(|| BookmarkAssociatedProfileSummary {
id: profile.id.clone(),
name: profile.name.clone(),
avatar_data_url: profile.avatar_data_url.clone(),
avatar_label: profile.avatar_label.clone(),
bookmark_path,
});
}
Some("folder") => {
if let Some(children) = node.get("children").and_then(Value::as_array) {
let folder_name = node
.get("name")
.and_then(Value::as_str)
.filter(|value| !value.is_empty());
let next_ancestors = if let Some(name) = folder_name {
let mut path = ancestors.to_vec();
path.push(name.to_string());
path
} else {
ancestors.to_vec()
};
for child in children {
collect_bookmarks(child, profile_id, bookmarks);
collect_bookmarks(child, profile, bookmarks, &next_ancestors);
}
}
}