From cb08217ffa46d73b02afcf1e9b64980163f105d1 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 5 Dec 2024 12:50:49 +0200 Subject: [PATCH] show identity details as dropdown item tooltip --- .../window/tab/item/identity/gemini.rs | 55 ++++++++++++++----- .../item/identity/gemini/widget/form/list.rs | 23 +++++--- .../identity/gemini/widget/form/list/item.rs | 15 ++++- .../gemini/widget/form/list/item/imp.rs | 2 + 4 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/app/browser/window/tab/item/identity/gemini.rs b/src/app/browser/window/tab/item/identity/gemini.rs index 18bb716a..1c42f5bd 100644 --- a/src/app/browser/window/tab/item/identity/gemini.rs +++ b/src/app/browser/window/tab/item/identity/gemini.rs @@ -33,6 +33,7 @@ impl Gemini { Value::UseGuestSession, "Guest session", "No identity for this request", + None, false, ); @@ -41,6 +42,7 @@ impl Gemini { Value::GenerateNewAuth, "Create new", "Generate long-term certificate", + None, false, ); @@ -49,6 +51,7 @@ impl Gemini { Value::ImportPem, "Import identity", "Use existing certificate", + None, false, ); @@ -63,13 +66,47 @@ impl Gemini { Err(reason) => todo!("{reason}"), }; + // Get auth details for tooltip + let mut auth_scope = Vec::new(); + + for auth in profile + .identity + .gemini + .auth + .database + .records_scope(None) + .unwrap() + .iter() + .filter(|this| this.profile_identity_gemini_id == identity.id) + { + auth_scope.push(auth.scope.clone()) + } + + // Build tooltip + let mut tooltip = format!( + "Valid:\n{}\n{}", + certificate + .not_valid_before() + .unwrap() + .format_iso8601() + .unwrap(), + certificate + .not_valid_after() + .unwrap() + .format_iso8601() + .unwrap() + ); + + if auth_scope.len() > 0 { + tooltip.push_str(&format!("\n\nScope:\n{}", auth_scope.join("\n"))); + } + // Append record option widget.form.list.append( Value::ProfileIdentityGeminiId(identity.id), &certificate.subject_name().unwrap().replace("CN=", ""), // trim prefix &format!( "{} - {} | scope: {}", - // certificate validity time certificate .not_valid_before() .unwrap() @@ -80,26 +117,16 @@ impl Gemini { .unwrap() .format(DATE_FORMAT) .unwrap(), - // count active certificate sessions - profile - .identity - .gemini - .auth - .database - .records_scope(None) - .unwrap() - .iter() - .filter(|this| this.profile_identity_gemini_id == identity.id) - .count(), + auth_scope.len(), ), - // is selected + Some(&tooltip), profile .identity .gemini .auth .memory .match_scope(&url) - .is_some_and(|auth| auth.profile_identity_gemini_id == identity.id), + .is_some_and(|auth| auth.profile_identity_gemini_id == identity.id), // is selected ); } } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs index d9256a7d..225b0218 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs @@ -63,12 +63,10 @@ impl List { title.set_css_classes(if item.is_active() { &["success"] } else { &[] }); // Update `subtitle` (expected as the last child) - child - .last_child() - .unwrap() - .downcast::