mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
87 lines
2.4 KiB
Rust
87 lines
2.4 KiB
Rust
mod widget;
|
|
use widget::Widget;
|
|
|
|
use crate::profile::Profile;
|
|
use gtk::{
|
|
gio::{prelude::TlsCertificateExt, TlsCertificate},
|
|
glib::Uri,
|
|
prelude::IsA,
|
|
};
|
|
use std::rc::Rc;
|
|
|
|
pub struct Gemini {
|
|
// profile: Rc<Profile>,
|
|
widget: Rc<Widget>,
|
|
}
|
|
|
|
impl Gemini {
|
|
// Construct
|
|
|
|
/// Create new `Self` for given Profile
|
|
pub fn new(profile: Rc<Profile>, auth_uri: Uri) -> Self {
|
|
// Init widget
|
|
let widget = Rc::new(Widget::new());
|
|
|
|
// Add new identity option
|
|
widget.form.list.append(None, "Create new..");
|
|
|
|
// Collect additional options from database
|
|
match profile.identity.gemini.database.records() {
|
|
Ok(identities) => {
|
|
for identity in identities {
|
|
// Get certificate details
|
|
let certificate = match TlsCertificate::from_pem(&identity.pem) {
|
|
Ok(certificate) => certificate,
|
|
Err(reason) => todo!("{reason}"),
|
|
};
|
|
|
|
// Get expiration time
|
|
let expires = certificate
|
|
.not_valid_after()
|
|
.unwrap()
|
|
.format_iso8601()
|
|
.unwrap();
|
|
|
|
// Append record option
|
|
widget.form.list.append(
|
|
Some(identity.id),
|
|
&match identity.name {
|
|
Some(name) => format!("{name} ({expires})"),
|
|
None => format!("{expires}"),
|
|
},
|
|
);
|
|
}
|
|
}
|
|
Err(_) => todo!(),
|
|
}
|
|
|
|
// Init events
|
|
widget.connect_response({
|
|
let profile = profile.clone();
|
|
move |value| {
|
|
match value {
|
|
Some(id) => {
|
|
// Activate selected identity ID
|
|
}
|
|
None => {
|
|
// Create and select new identity
|
|
}
|
|
} // @TODO handle result
|
|
}
|
|
});
|
|
|
|
// Return activated `Self`
|
|
Self {
|
|
// profile,
|
|
widget,
|
|
}
|
|
}
|
|
|
|
// Actions
|
|
|
|
/// Show dialog for parent [Widget](https://docs.gtk.org/gtk4/class.Widget.html)
|
|
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
|
|
self.widget.present(parent);
|
|
}
|
|
}
|