Draw the signing identity's avatar like a client app's

The approval dialog showed a client avatar on the "Application" field but no
identity avatar on "Signing as", and the Connect dialog's and the Apps page's
"Signing as" rows had none either.

Add `plain::avatar`/`plain::set_avatar` — initials of the name, or libadwaita's
glyph when there is none, with a cached image when there is one — and use it for
the client fields and the identity fields alike, so the identity's
avatar/placeholder is drawn exactly like a client application's. The Connect
dialog keeps its avatar widget and repoints it on refresh, since the row is
built once.

Identities have no cached image yet (fetching kind-0 pictures is a later
change), so they show initials for now; the texture lookup is already in place.
This commit is contained in:
raucao committed 2026-11-28 15:59:22 +04:00
1 parent 0d98a53fce
commit 35fd7614ad
4 files changed
+94 -30

No files matched your search

+28 -14
View File
@@ -481,7 +481,7 @@ fn details(
.spacing(12)
.build();
content.append(&identity_field(&question.identity));
content.append(&identity_field(state, &question.identity));
content.append(&application_field(state, client));
// The kind is part of what is being signed, so it sits with the payload
// rather than collapsed under Details.
@@ -579,7 +579,7 @@ fn more_details(question: &Question) -> gtk::ListBox {
/// tooltip. The name is what the user recognises; the npub is long and rarely
/// read, so it stays out of the way (the identities window still offers
/// "Copy public key").
fn identity_field(identity: &crate::signer::approval::SigningKey) -> gtk::Box {
fn identity_field(state: &Rc<AppState>, identity: &crate::signer::approval::SigningKey) -> gtk::Box {
let npub = identity
.public_key
.to_bech32()
@@ -589,14 +589,30 @@ fn identity_field(identity: &crate::signer::approval::SigningKey) -> gtk::Box {
.as_deref()
.map(str::trim)
.filter(|name| !name.is_empty());
let row = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.spacing(10)
.build();
// The same avatar/placeholder as the application field beside it: initials of
// the name, or libadwaita's glyph when it has none, with a cached image when
// there is one (identities have none yet).
let avatar = plain::avatar(
32,
name,
state.icons().texture(&identity.public_key.to_hex()).as_ref(),
);
// A signing key always has a name; the shortened npub is only a fallback
// for a key that somehow does not.
let value = match name {
Some(name) => plain::label(name),
None => plain::label(&plain::shorten_npub(&npub)),
};
value.set_hexpand(true);
value.set_tooltip_text(Some(&npub));
plain::field("Signing as", &value)
row.append(&avatar);
row.append(&value);
plain::field("Signing as", &row)
}
/// The application's name (or its shortened key when it declares none), with its
@@ -621,17 +637,15 @@ fn application_field(state: &Rc<AppState>, client: &ClientInfo) -> gtk::Box {
.orientation(gtk::Orientation::Horizontal)
.spacing(10)
.build();
let avatar = match name {
Some(name) => adw::Avatar::new(32, Some(name), true),
None => adw::Avatar::new(32, None, false),
};
if let Some(texture) = state.icons().texture(&public_key) {
avatar.set_custom_image(Some(&texture));
} else if let Some(image) = client.image.as_deref() {
let avatar = avatar.clone();
state.preview_icon(&public_key, image, move |texture| {
avatar.set_custom_image(Some(&texture));
});
let texture = state.icons().texture(&public_key);
let avatar = plain::avatar(32, name, texture.as_ref());
if texture.is_none() {
if let Some(image) = client.image.as_deref() {
let avatar = avatar.clone();
state.preview_icon(&public_key, image, move |texture| {
avatar.set_custom_image(Some(&texture));
});
}
}
let label_text = name
+22 -12
View File
@@ -279,13 +279,11 @@ impl Ui {
let row = plain::expander(&title, &byline);
row.set_subtitle_lines(1);
// The icon is decoration: the name above stays the identifier.
let avatar = match &name {
Some(name) => adw::Avatar::new(32, Some(name), true),
None => adw::Avatar::new(32, None, false),
};
if let Some(texture) = self.state.icons().texture(&app.public_key) {
avatar.set_custom_image(Some(&texture));
}
let avatar = plain::avatar(
32,
name.as_deref(),
self.state.icons().texture(&app.public_key).as_ref(),
);
row.add_prefix(&avatar);
// When the byline is a shortened npub, keep the full key in a tooltip.
if url.is_none() {
@@ -302,19 +300,31 @@ impl Ui {
// Which identity this app signs as. This is the binding the responder
// resolves per request.
let bound = PublicKey::parse(&app.identity).ok();
let (signing_as, signing_npub) = match bound {
Some(identity) => (
format!("Signing as {}", self.state.identity_label(&identity)),
identity.to_bech32().unwrap_or_else(|_| identity.to_hex()),
),
let (signing_as, signing_npub, signing_avatar) = match &bound {
Some(identity) => {
let label = self.state.identity_label(identity);
(
format!("Signing as {label}"),
identity.to_bech32().unwrap_or_else(|_| identity.to_hex()),
// The signing identity's avatar, drawn the same as the
// application's above.
plain::avatar(
32,
Some(label.as_str()),
self.state.icons().texture(&identity.to_hex()).as_ref(),
),
)
}
None => (
"Signing as unknown".to_string(),
"paired before identities existed".to_string(),
plain::avatar(32, None, None),
),
};
let signing_as_row = plain::row(&signing_as, &plain::shorten_npub(&signing_npub));
signing_as_row.set_subtitle_lines(1);
signing_as_row.set_tooltip_text(Some(&signing_npub));
signing_as_row.add_prefix(&signing_avatar);
row.add_row(&signing_as_row);
if app.policy.kinds.is_empty() && app.policy.methods.is_empty() {
+14 -4
View File
@@ -46,6 +46,8 @@ pub struct ConnectDialog {
/// name is kind-0 data and an `AdwPreferencesGroup` description renders
/// markup.
signing_as: adw::ActionRow,
/// The chosen identity's avatar, drawn like a client application's.
signing_avatar: adw::Avatar,
reveal: adw::ExpanderRow,
uri: adw::ActionRow,
picture: gtk::Picture,
@@ -61,6 +63,9 @@ impl ConnectDialog {
let signing_as = plain::row("Signing as", "");
// The npub beneath is a long token: one line, ellipsized in the middle.
signing_as.set_subtitle_lines(1);
// Filled in by `refresh`, from the selected identity.
let signing_avatar = plain::avatar(32, None, None);
signing_as.add_prefix(&signing_avatar);
identity_group.add(&signing_as);
let entry = adw::EntryRow::builder().title("Pairing code").build();
// Insensitive until there is something to pair: an empty submit would
@@ -158,6 +163,7 @@ impl ConnectDialog {
entry,
pair,
signing_as,
signing_avatar,
reveal,
uri,
picture,
@@ -270,19 +276,23 @@ impl ConnectDialog {
// is no identity yet, so there is no name to show.
match self.state.current_identity() {
Some(identity) => {
let label = self.state.identity_label(&identity);
let npub = identity.to_bech32().unwrap_or_else(|_| identity.to_hex());
self.signing_as.set_title(&format!(
"Signing as {}",
self.state.identity_label(&identity)
));
self.signing_as.set_title(&format!("Signing as {label}"));
// Cut for the row; the full npub stays reachable as a tooltip.
self.signing_as.set_subtitle(&plain::shorten_npub(&npub));
self.signing_as.set_tooltip_text(Some(&npub));
plain::set_avatar(
&self.signing_avatar,
Some(label.as_str()),
self.state.icons().texture(&identity.to_hex()).as_ref(),
);
}
None => {
self.signing_as.set_title("Signing as");
self.signing_as.set_subtitle("Add an identity key first.");
self.signing_as.set_tooltip_text(None);
plain::set_avatar(&self.signing_avatar, None, None);
}
}
+30
View File
@@ -120,6 +120,36 @@ pub fn text_field(title: &str, value: &str) -> gtk::Box {
field(title, &label(value))
}
/// The avatar for an application or an identity: initials of `name`, or
/// libadwaita's glyph when there is none, with a cached image when one is
/// available.
///
/// Shared so an identity's avatar/placeholder is drawn exactly like a client
/// application's. The image is decoration, never the sole identifier, so the name
/// beside it stays the thing that is read.
pub fn avatar(size: i32, name: Option<&str>, texture: Option<&gtk::gdk::Texture>) -> adw::Avatar {
let avatar = adw::Avatar::new(size, None, false);
set_avatar(&avatar, name, texture);
avatar
}
/// Point an existing avatar at `name`/`texture` — the same rule as [`avatar`],
/// for a widget that outlives one rebuild (the Connect dialog's "Signing as"
/// row).
pub fn set_avatar(avatar: &adw::Avatar, name: Option<&str>, texture: Option<&gtk::gdk::Texture>) {
match name {
Some(name) => {
avatar.set_text(Some(name));
avatar.set_show_initials(true);
}
None => {
avatar.set_text(None);
avatar.set_show_initials(false);
}
}
avatar.set_custom_image(texture);
}
/// An `ExpanderRow` whose title and subtitle are plain text.
///
/// The enable switch is hidden: on an expander it only hides the child rows,