fix selected auth detection, remove extra members

This commit is contained in:
yggverse 2024-12-05 08:57:24 +02:00
parent 42d309d1de
commit d627fd1b72
2 changed files with 24 additions and 30 deletions

View File

@ -25,17 +25,15 @@ impl Gemini {
// Init widget // Init widget
let widget = Rc::new(Widget::new(profile.clone())); let widget = Rc::new(Widget::new(profile.clone()));
// Init shared components // Init shared URL string from URI
let auth_url = auth_uri.to_string(); let url = auth_uri.to_string();
// Set first record selected by default
let mut selected: u32 = 0;
// Add guest option // Add guest option
widget.form.list.append( widget.form.list.append(
Value::UseGuestSession, Value::UseGuestSession,
"Guest session", "Guest session",
"No identity for this request", "No identity for this request",
false,
); );
// Add new identity option // Add new identity option
@ -43,6 +41,7 @@ impl Gemini {
Value::GenerateNewAuth, Value::GenerateNewAuth,
"Create new", "Create new",
"Generate long-term certificate", "Generate long-term certificate",
false,
); );
// Add import existing identity option // Add import existing identity option
@ -50,28 +49,14 @@ impl Gemini {
Value::ImportPem, Value::ImportPem,
"Import identity", "Import identity",
"Use existing certificate", "Use existing certificate",
false,
); );
// Collect identities as options from profile database // Collect identities as options from profile database
// * memory cache synced also and could be faster @TODO // * memory cache synced also and could be faster @TODO
let mut i = 2; // start from 3'th
match profile.identity.gemini.database.records() { match profile.identity.gemini.database.records() {
Ok(identities) => { Ok(identities) => {
for identity in identities { for identity in identities {
i += 1;
// Is selected?
if profile
.identity
.gemini
.auth
.memory
.match_scope(auth_url.as_str())
.is_some_and(|auth| auth.profile_identity_gemini_id == identity.id)
{
selected = i;
}
// Get certificate details // Get certificate details
let certificate = match TlsCertificate::from_pem(&identity.pem) { let certificate = match TlsCertificate::from_pem(&identity.pem) {
Ok(certificate) => certificate, Ok(certificate) => certificate,
@ -84,6 +69,7 @@ impl Gemini {
&certificate.subject_name().unwrap().replace("CN=", ""), // trim prefix &certificate.subject_name().unwrap().replace("CN=", ""), // trim prefix
&format!( &format!(
"{} - {} | auth: {}", "{} - {} | auth: {}",
// certificate validity time
certificate certificate
.not_valid_before() .not_valid_before()
.unwrap() .unwrap()
@ -94,6 +80,7 @@ impl Gemini {
.unwrap() .unwrap()
.format(DATE_FORMAT) .format(DATE_FORMAT)
.unwrap(), .unwrap(),
// count active certificate sessions
profile profile
.identity .identity
.gemini .gemini
@ -105,13 +92,18 @@ impl Gemini {
.filter(|this| this.profile_identity_gemini_id == identity.id) .filter(|this| this.profile_identity_gemini_id == identity.id)
.count(), .count(),
), ),
// is selected
profile
.identity
.gemini
.auth
.memory
.match_scope(&url)
.is_some_and(|auth| auth.profile_identity_gemini_id == identity.id),
); );
} }
// Select list item
widget.form.list.gobject.set_selected(selected);
} }
Err(_) => todo!(), Err(e) => todo!("{e}"),
} }
// Init events // Init events
@ -152,16 +144,14 @@ impl Gemini {
.identity .identity
.gemini .gemini
.auth .auth
.apply(profile_identity_gemini_id, auth_url.as_str()) .apply(profile_identity_gemini_id, &url)
{ {
todo!("{}", reason.to_string()) todo!("{}", reason.to_string())
}; };
} }
// Remove all identity auths for `auth_uri` // Remove all identity auths for `auth_uri`
None => { None => {
if let Err(reason) = if let Err(reason) = profile.identity.gemini.auth.remove_scope(&url) {
profile.identity.gemini.auth.remove_scope(auth_url.as_str())
{
todo!("{}", reason.to_string()) todo!("{}", reason.to_string())
}; };
} }

View File

@ -84,8 +84,12 @@ impl List {
// Actions // Actions
/// Append new item /// Append new item
pub fn append(&self, value: Value, title: &str, subtitle: &str) { pub fn append(&self, value: Value, title: &str, subtitle: &str, is_selected: bool) {
self.model.append(&Item::new(value, title, subtitle)); let item = Item::new(value, title, subtitle);
self.model.append(&item);
if is_selected {
self.gobject.set_selected(self.model.find(&item).unwrap()); // @TODO panic or handle?
}
} }
/// Find list item by `Value` /// Find list item by `Value`