Simplify the dialogs and move the signer to Preferences

The approval dialog and the "Connect an app" dialog now share one width
(plain::DIALOG_WIDTH, 560) and put the decision first: the payload is a
bounded, scrollable card above the fold, and the verifiable-but-secondary
fields (client key, declared URL, kind number, raw tags, method, peer) live
in a collapsed Details expander. The "cannot be trusted" warning is shown
on the pair screen only, where trust is actually decided.

The Connect dialog loses the signer group: its run state is not what that
dialog is for. Start/Stop moves to Preferences, and "Show Regent's code"
starts the signer when expanded, so removing the button leaves no dead end.
"Pair" stays insensitive until the entry has a code.

The Apps list byline shows the host the application declares instead of the
shortened npub, with the full key and URL in the row's details. A declared
URL is display data the client controls, so only the host is shown.

The Connect dialog follows its content size, so revealing the QR code grows
the dialog instead of hiding it below the fold. That property ignores
content-width, so the width is pinned on the child instead.
This commit is contained in:
raucao committed 2026-11-26 00:11:49 +04:00
1 parent 5643249423
commit 8800ccf1c4
7 files changed
+325 -132

No files matched your search

+51 -2
View File
@@ -135,6 +135,17 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
Shell emits `ActionInvoked(id, "default")` and GLib activates the app action
**in-process** (the `org.gtk.Notifications` path would call
`ActivateAction("focus")` on the app instead — the same action name either way).
- **The dialog's content puts the decision first.** Heading, then one sentence of
our own words — never "it", because the application's name is a row and the
body must not carry client text (it is not selectable) — then the payload as a
bounded, scrollable card, so a long note cannot push the buttons off screen.
"Signing as" and "Application" stay above the fold; the verifiable-but-secondary
fields (client key, declared URL, kind number, raw tags, method, peer, "asked
for") live in a collapsed **Details** expander. The "name and URL are supplied
by the application" warning is shown on the **pair** screen only — on an
already-approved app's request it is banner blindness. Both this dialog and
"Connect an app" use `plain::DIALOG_WIDTH` (560) so neither resizes as the user
moves between them.
- **The dialog owns the deadline, and it is absolute.** `ASK_TIMEOUT` (60 s) is
turned into an `Instant` **when the ask starts** and travels to the UI in the
`Prompt`; the dialog answers `Deny` and closes itself when that instant arrives
@@ -208,7 +219,10 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
1.6 deprecated `AdwPreferencesWindow` in favour of it — built **once** and
re-presented (`AdwDialog` re-presents after being closed), with its listeners
registered once, because the lock state changes while it is open. It holds the
vault group and the auto-approval limit. Deliberately **not** relays: the
signer's run state (Start/Stop), the vault group and the auto-approval limit.
The signer moved here from the "Connect an app" dialog: its run state is not
what that dialog is for, and Start/Stop sat above a pairing flow it did not
belong to. Deliberately **not** relays: the
running signer holds `config.relays` from start, the bunker URI advertises them
and `get_relays` serves them, so a mid-run edit would mean "changed, but not
until restart, and the paired clients were told otherwise". Reachable by
@@ -237,7 +251,11 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
registry and a second signer on the same device key.
- The Apps page shows one `AdwExpanderRow` per app: per-app *Revoke* as a
suffix (visible while collapsed), one *Remove* row per stored permission
(kind for `sign_event`, method for encryption), and *Forget all*.
(kind for `sign_event`, method for encryption), and *Forget all*. The
collapsed byline is the **host** the app declares (`declared_host`), falling
back to the shortened npub when it declares none; the full public key and the
full URL are rows in the details. A declared URL is display data the client
controls — it proves nothing, and the host is shown so the byline stays short.
- The activity log (`store/audit.rs`) records **metadata only**: app, method,
event kind, outcome, time. `Entry` has a typed `kind: Option<u16>` and
deliberately **no free-form detail field**, so event content, plaintext and
@@ -364,6 +382,12 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
the signer is stopped, it is started with the client's relays first. The
`SignerRunner` has a `Stopped | Starting | Running` state so a second start
cannot put two responders on one device key.
- **The other direction needs no Start button.** "Show Regent's code" is gated on
a running signer — the `bunker://` URI only exists while it listens — so
expanding that row starts the signer if it is stopped. That is why the dialog
carries no Start/Stop: the two directions are "paste a code" (auto-starts on
pair) and "show a code" (auto-starts on reveal). Start/Stop lives in
Preferences.
- **A successful pairing closes the "Connect an app" dialog and brings Apps
forward** (`Windows::show_apps`), and there is no "Client paired"
confirmation: the new app is already in the list the user lands on. The
@@ -567,6 +591,31 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
label in the row's own widget tree and sets `MIDDLE`; `set_subtitle` does not
reset it, so once at construction is enough. The row then elides the middle
at whatever width it gets.
14. `AdwExpanderRow` is **not** an `AdwActionRow`: both derive from
`AdwPreferencesRow`, but neither is a subclass of the other, and the two do
not share a `subtitle` accessor trait. `plain::middle_ellipsis` therefore
takes an `&AdwActionRow` and cannot be applied to an expander's subtitle —
`set_subtitle_lines(1)` there means end-ellipsis, which is fine for a short
byline but not for a long token.
15. A `GtkScrolledWindow`'s **natural height is 0** unless
`propagate_natural_height` is set, and `AdwDialog` sizes itself to its child's
natural height. So a dialog whose child is a scroller collapses to just its
header bar the moment an explicit `content_height` is removed — measured at
104px against 303px for the same content. `max_content_height` only applies
when propagation is on. The "Connect an app" dialog needs both: propagation to
get a real height, and the cap so the expanded QR cannot make it enormous.
16. **`AdwDialog` is not resizable**: its size is decided at presentation, so a
dialog whose content grows afterwards (an expander revealing a QR code) keeps
its old height and hides the new content below the fold. Set
`follows-content-size` to make it track the content — "if the content
resizes, the dialog will immediately resize as well". But that property
**ignores `content-width`/`content-height`** and uses the content's natural
size, so a dialog that needs a fixed width must pin it on the child instead
(`toolbar.set_size_request(width, -1)`). Measured for "Connect an app":
without follows, 560×176 collapsed and expanded; with follows and no width
pin, 229×176/229×492; with follows plus the pin, 560×176/560×492. Pinning the
width on the scroller or the content box instead of the toolbar view leaves
the height stuck.
## Blueprint / Meson traps
+89 -57
View File
@@ -250,10 +250,10 @@ pub async fn present_question(
let dialog = adw::AlertDialog::builder()
.heading(heading(request))
.body(story(request))
// Narrower than the 420px default window: a floating `AdwDialog` is
// part of the window and is clipped by it, so it must be able to shrink
// to fit rather than poke out of the sides.
.content_width(360)
// The same width as the "Connect an app" dialog. A floating `AdwDialog`
// is part of the window and is clipped by it, so it must be able to
// shrink to fit rather than poke out of the sides.
.content_width(plain::DIALOG_WIDTH)
.extra_child(&details(question))
.build();
// Heading and body are plain text too: the heading carries no client data
@@ -397,7 +397,7 @@ async fn ask_passphrase(
fn heading(request: &Request) -> String {
match request {
Request::Pair { .. } => "Connect an application?".to_string(),
Request::Pair { .. } => "Connect an app?".to_string(),
Request::Sign { .. } => "Sign an event?".to_string(),
Request::Encrypt { .. } => "Encrypt a message?".to_string(),
Request::Decrypt { .. } => "Decrypt a message?".to_string(),
@@ -405,27 +405,39 @@ fn heading(request: &Request) -> String {
}
/// Our own words about what the request means. No client data.
///
/// Each sentence names its subject rather than saying "it": the application's
/// name is a row below, not in the body, so "it" would have no antecedent.
fn story(request: &Request) -> &'static str {
match request {
Request::Pair { .. } => {
"It would be able to ask Regent for signatures and encryption. Every such \
request will still be shown to you."
"This application would be able to ask Regent for signatures and \
encryption. Every such request will still be shown to you."
}
Request::Sign { .. } => {
"It wants Regent to sign an event with your identity key."
"This application wants Regent to sign an event with your identity key."
}
Request::Encrypt { .. } => {
"This application wants Regent to encrypt a message in your name."
}
Request::Decrypt { .. } => {
"This application wants Regent to decrypt a message for you."
}
Request::Encrypt { .. } => "It wants Regent to encrypt a message in your name.",
Request::Decrypt { .. } => "It wants Regent to decrypt a message for you.",
}
}
/// The selectable, plain-text detail block: who is asking, as which identity,
/// and exactly what.
/// The selectable, plain-text detail block: what is being asked, as which
/// identity, and everything else behind a "Details" expander.
///
/// The payload *is* the decision, so it stays above the fold; the fields that
/// are verifiable but not needed to decide — the client's key, the URL it
/// declares, the raw kind and tags — are collapsed. Client metadata is
/// decoration: the name and URL are supplied by the application itself.
fn details(question: &Question) -> gtk::Box {
let client = &question.client;
let content = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.spacing(10)
.spacing(12)
.build();
content.append(&identity_field(&question.identity));
@@ -433,47 +445,12 @@ fn details(question: &Question) -> gtk::Box {
"Application",
client.name.as_deref().unwrap_or("(unnamed)"),
));
if let Some(url) = &client.url {
content.append(&field("Declared URL", url));
}
content.append(&field(
"Public key",
&client.public_key.to_bech32().unwrap_or_default(),
));
match &question.request {
Request::Pair { requested } => {
if let Some(requested) = requested {
content.append(&field("Asked for", requested));
}
}
Request::Sign {
kind,
preview,
tags,
} => {
content.append(&field("Kind", &format!("{} ({})", kind, kind::name(*kind))));
content.append(&block("Content", preview));
content.append(&field("Tags", tags));
}
Request::Encrypt {
method,
peer,
preview,
} => {
content.append(&field("Method", method));
content.append(&field("Peer", peer));
content.append(&block("Message", preview));
}
Request::Decrypt {
method,
peer,
preview,
} => {
content.append(&field("Method", method));
content.append(&field("Peer", peer));
content.append(&block("Ciphertext", preview));
}
Request::Pair { .. } => {}
Request::Sign { preview, .. } => content.append(&block("Content", preview)),
Request::Encrypt { preview, .. } => content.append(&block("Message", preview)),
Request::Decrypt { preview, .. } => content.append(&block("Ciphertext", preview)),
}
if let Some(previous) = &question.rebind_from {
@@ -484,14 +461,59 @@ fn details(question: &Question) -> gtk::Box {
)));
}
content.append(&note(
"The application's name and URL are supplied by the application itself and \
cannot be trusted.",
));
// Pairing is the moment trust is decided, so the warning stays in view. For
// a request from an already approved app it would be banner blindness —
// the app was vetted when it was paired.
if matches!(question.request, Request::Pair { .. }) {
content.append(&note(
"The application's name and URL are supplied by the application itself and \
cannot be trusted.",
));
}
content.append(&more_details(question));
content
}
/// The collapsed half of the dialog: everything that is verifiable but not
/// needed to decide. Collapsed so the payload stays the most prominent thing.
fn more_details(question: &Question) -> gtk::ListBox {
let client = &question.client;
let row = plain::expander("Details", "Key and request metadata");
row.add_row(&plain::row(
"Client key",
&client.public_key.to_bech32().unwrap_or_default(),
));
if let Some(url) = &client.url {
row.add_row(&plain::row("Declared URL", url));
}
match &question.request {
Request::Pair { requested } => {
if let Some(requested) = requested {
row.add_row(&plain::row("Asked for", requested));
}
}
Request::Sign { kind, tags, .. } => {
row.add_row(&plain::row(
"Kind",
&format!("{} ({})", kind, kind::name(*kind)),
));
row.add_row(&plain::row("Tags", tags));
}
Request::Encrypt { method, peer, .. } | Request::Decrypt { method, peer, .. } => {
row.add_row(&plain::row("Method", method));
row.add_row(&plain::row("Peer", peer));
}
}
let list = gtk::ListBox::builder()
.selection_mode(gtk::SelectionMode::None)
.css_classes(["boxed-list"])
.build();
list.append(&row);
list
}
/// The identity a request would act as: the name on the "Signing as" line, and
/// the npub beneath it. The name is what the user recognises, so it leads; when
/// there is none only the npub is shown.
@@ -545,6 +567,9 @@ fn field_widget(title: &str, value: &impl IsA<gtk::Widget>) -> gtk::Box {
}
/// A titled block for text that may be long, laid out like a quote.
///
/// Bounded: a 5 kB note would otherwise grow the dialog until its buttons left
/// the screen. Past the bound the block scrolls instead.
fn block(title: &str, value: &str) -> gtk::Box {
let container = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
@@ -565,8 +590,15 @@ fn block(title: &str, value: &str) -> gtk::Box {
body.set_margin_end(8);
body.set_hexpand(true);
let scrolled = gtk::ScrolledWindow::builder()
.child(&body)
.propagate_natural_height(true)
.max_content_height(160)
.hscrollbar_policy(gtk::PolicyType::Never)
.build();
let frame = gtk::Box::builder().css_classes(["card"]).build();
frame.append(&body);
frame.append(&scrolled);
container.append(&frame);
container
}
+36 -3
View File
@@ -26,7 +26,7 @@ use crate::ui::{kind, plain};
type Shown = (
Option<String>,
Option<String>,
Vec<(String, Option<String>, Policy)>,
Vec<(String, Option<String>, Option<String>, Policy)>,
);
pub struct AppsView {
@@ -187,7 +187,14 @@ impl Ui {
identity_hex,
identity_name.clone(),
apps.iter()
.map(|app| (app.public_key.clone(), app.name.clone(), app.policy.clone()))
.map(|app| {
(
app.public_key.clone(),
app.name.clone(),
app.url.clone(),
app.policy.clone(),
)
})
.collect(),
);
if self.shown.borrow().as_ref() == Some(&signature) {
@@ -232,8 +239,19 @@ impl Ui {
.map(|key| key.to_bech32().unwrap_or_default())
.unwrap_or_else(|_| app.public_key.clone());
let row = plain::expander(&name, &plain::shorten(&npub, 12, 6));
// The byline is the host the application declares, because a host is
// what a person can recognise; the public key stays in the details. A
// client-supplied URL is display data only — it proves nothing.
let byline = match app.url.as_deref() {
Some(url) => declared_host(url),
None => plain::shorten(&npub, 12, 6),
};
let row = plain::expander(&name, &byline);
row.set_subtitle_lines(1);
row.add_row(&plain::row("Public key", &npub));
if let Some(url) = &app.url {
row.add_row(&plain::row("Declared URL", url));
}
// Which identity this app signs as. This is the binding the responder
// resolves per request.
@@ -366,3 +384,18 @@ fn encryption_label(method: &str) -> String {
other => other.to_string(),
}
}
/// The host an application declared, or the raw string when it does not parse.
///
/// Only the host is shown in the list: the path and query are the application's
/// own decoration, and a URL an application supplies proves nothing about who it
/// is. The full string stays in the row's details.
fn declared_host(url: &str) -> String {
match url::Url::parse(url) {
Ok(parsed) => parsed
.host_str()
.map(str::to_string)
.unwrap_or_else(|| url.to_string()),
Err(_) => url.to_string(),
}
}
+56 -62
View File
@@ -1,10 +1,14 @@
//! The "Connect an app…" dialog: pairing in both directions, and the signer's
//! run state where it is actionable.
//! The "Connect an app…" dialog: pairing in both directions.
//!
//! This replaces the old Signer page. The page's permanent connection string and
//! QR code were mostly dead weight — and the `bunker://` URI embeds the pairing
//! secret, so keeping it behind a deliberate reveal is the safer default. The
//! dialog is built once and re-presented, like Preferences.
//!
//! The signer's run state lives in Preferences. This dialog needs no Start
//! button: the client-initiated direction starts the signer when it pairs, and
//! "Show Regent's code" starts it when expanded, because the URI only exists
//! while the signer listens.
use std::cell::Cell;
use std::rc::{Rc, Weak};
@@ -36,8 +40,6 @@ pub struct ConnectDialog {
/// pairing while it is open — the bunker-URI direction, where the client
/// connects from outside — grows it, and the dialog then closes.
shown: Cell<Option<usize>>,
signer_row: adw::ActionRow,
toggle: gtk::Button,
entry: adw::EntryRow,
pair: gtk::Button,
/// The identity a new pairing will use. A plain row, because the display
@@ -51,32 +53,19 @@ pub struct ConnectDialog {
impl ConnectDialog {
pub fn new(state: Rc<AppState>, runner: Rc<SignerRunner>, windows: &Rc<Windows>) -> Rc<Self> {
// --- Start/stop: the only screen where run-state is actionable. ---
let signer_row = plain::row("Signer", "Stopped");
let toggle = gtk::Button::builder()
.label("Start")
.valign(gtk::Align::Center)
// A small button, not a `pill`: `flat` while running (like the
// "Connect" suffix on the Apps page), swapped for the filled
// `suggested-action` blue while stopped, so "Start" reads as the
// thing to do.
.css_classes(["flat"])
.build();
signer_row.add_suffix(&toggle);
let signer_group = adw::PreferencesGroup::new();
signer_group.add(&signer_row);
// --- The client-initiated direction. ---
let identity_group = adw::PreferencesGroup::builder()
.title("The app shows a code")
.description("New apps sign as the identity selected in the header.")
.build();
let signing_as = plain::row("Signing as", "");
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
// only produce an error dialog.
let pair = gtk::Button::builder()
.label("Pair")
.valign(gtk::Align::Center)
.sensitive(false)
.css_classes(["suggested-action"])
.build();
entry.add_suffix(&pair);
@@ -122,12 +111,17 @@ impl ConnectDialog {
.margin_start(12)
.margin_end(12)
.build();
content.append(&signer_group);
content.append(&identity_group);
content.append(&reveal_group);
let scrolled = gtk::ScrolledWindow::builder()
.child(&content)
.vexpand(true)
// A `GtkScrolledWindow`'s natural height is 0 unless it propagates,
// and the dialog sizes to its child's natural height — without this
// the whole dialog collapses to its header bar. Cap it so the
// expanded QR code cannot make the dialog enormous.
.propagate_natural_height(true)
.max_content_height(620)
.build();
let header = adw::HeaderBar::new();
@@ -135,11 +129,17 @@ impl ConnectDialog {
let toolbar = adw::ToolbarView::new();
toolbar.add_top_bar(&header);
toolbar.set_content(Some(&scrolled));
// Pin the width on the dialog's child, not via `content_width`: with
// `follows_content_size` below, libadwaita ignores `content_width` and
// would use the content's natural width instead (229px, measured).
toolbar.set_size_request(plain::DIALOG_WIDTH, -1);
let dialog = adw::Dialog::builder()
.title("Connect an app")
.content_width(560)
.content_height(620)
// An `AdwDialog` is not resizable: its size is fixed at presentation
// unless it follows its content. This is what makes "Show Regent's
// code" grow the dialog instead of hiding the QR below the fold.
.follows_content_size(true)
.child(&toolbar)
.build();
@@ -149,8 +149,6 @@ impl ConnectDialog {
runner,
windows: Rc::downgrade(windows),
shown: Cell::new(None),
signer_row,
toggle,
entry,
pair,
signing_as,
@@ -182,15 +180,6 @@ impl ConnectDialog {
runner.listen(move || listener.refresh());
}
{
let toggle = connect.toggle.clone();
let listener = Rc::clone(&connect);
toggle.connect_clicked(move |_| match listener.runner.status() {
Status::Stopped => listener.runner.start(Vec::new(), None),
Status::Running(_) => listener.runner.stop(),
Status::Starting => {}
});
}
{
let pair = connect.pair.clone();
let listener = Rc::clone(&connect);
@@ -201,6 +190,15 @@ impl ConnectDialog {
let listener = Rc::clone(&connect);
entry.connect_entry_activated(move |_| listener.pair());
}
{
// Nothing to pair until there is a code: keep "Pair" insensitive
// rather than letting an empty submit produce an error dialog.
let entry = connect.entry.clone();
let pair = connect.pair.clone();
entry.connect_changed(move |entry| {
pair.set_sensitive(!entry.text().trim().is_empty());
});
}
{
let listener = Rc::clone(&connect);
copy.connect_clicked(move |_| {
@@ -215,12 +213,20 @@ impl ConnectDialog {
let reveal = connect.reveal.clone();
let listener = Rc::clone(&connect);
reveal.connect_expanded_notify(move |_| {
if listener.reveal.is_expanded() {
if let Some(uri) = listener.runner.bunker_uri() {
listener.show_qr(&uri);
}
} else {
if !listener.reveal.is_expanded() {
listener.picture.set_paintable(None::<&gdk::Paintable>);
return;
}
// Showing the code *is* the request to pair in this direction,
// and there is no connection string without a running signer.
// Start it rather than leaving a dead row; the runner's listener
// refreshes the row and draws the QR once it is up.
if matches!(listener.runner.status(), Status::Stopped) && listener.state.has_keys()
{
listener.runner.start(Vec::new(), None);
}
if let Some(uri) = listener.runner.bunker_uri() {
listener.show_qr(&uri);
}
});
}
@@ -269,40 +275,28 @@ impl ConnectDialog {
match self.runner.status() {
Status::Stopped => {
self.signer_row.set_subtitle(if has_keys {
"Stopped"
// The connection string only exists while the signer runs, and
// showing the code starts it. Only a missing identity key keeps
// the row out of reach.
self.reveal.set_sensitive(has_keys);
self.reveal.set_subtitle(if has_keys {
"Starts the signer and shows its connection string."
} else {
"Add an identity key first"
"Add an identity key first."
});
self.toggle.set_label("Start");
self.toggle.set_sensitive(has_keys);
self.toggle.add_css_class("suggested-action");
self.toggle.remove_css_class("flat");
self.reveal.set_sensitive(false);
self.reveal.set_subtitle("Start the signer first");
// A stopped signer has no URI, so leave the row collapsed
// rather than expanded and empty: expanding is what starts it.
self.reveal.set_expanded(false);
self.uri.set_subtitle("—");
self.picture.set_paintable(None::<&gdk::Paintable>);
}
Status::Starting => {
self.signer_row.set_subtitle("Starting…");
self.toggle.set_label("Starting…");
self.toggle.set_sensitive(false);
self.toggle.remove_css_class("suggested-action");
self.toggle.add_css_class("flat");
self.reveal.set_sensitive(false);
self.reveal.set_subtitle("Start the signer first");
self.reveal.set_expanded(false);
self.reveal.set_sensitive(has_keys);
self.reveal.set_subtitle("Starting the signer…");
self.uri.set_subtitle("—");
self.picture.set_paintable(None::<&gdk::Paintable>);
}
Status::Running(signer) => {
self.signer_row
.set_subtitle(&format!("Listening on {} relay(s)", signer.relay_count()));
self.toggle.set_label("Stop");
self.toggle.set_sensitive(has_keys);
self.toggle.remove_css_class("suggested-action");
self.toggle.add_css_class("flat");
self.reveal.set_sensitive(true);
self.reveal
.set_subtitle("The connection string embeds the pairing secret.");
+8
View File
@@ -14,6 +14,14 @@ use adw::prelude::*;
use gtk::prelude::*;
use libadwaita as adw;
/// The width both the approval dialog and the "Connect an app" dialog use.
///
/// A floating `AdwDialog` is part of the window and is clipped by it, so a
/// single width keeps the two dialogs from resizing as the user moves between
/// them. 560 is what the "Connect an app" dialog already uses and it fits the
/// main window.
pub const DIALOG_WIDTH: i32 = 560;
/// A plain "Something went wrong" dialog, parented to the widget's window.
///
/// The message is our own text, but it can carry a client-supplied name or a
+79 -7
View File
@@ -1,14 +1,15 @@
//! Preferences: the vault's passphrase, its auto-lock timeout, and the
//! auto-approval rate limit.
//! Preferences: the signer's run state, the vault's passphrase, its auto-lock
//! timeout, and the auto-approval rate limit.
//!
//! None of this is key *management* — that is the identities window — and none
//! of it is a window either: libadwaita replaces `AdwPreferencesWindow` with
//! `AdwPreferencesDialog`, which presents inside the main window.
//!
//! Built **once** and re-presented. `AdwDialog` re-presents after being closed,
//! and its listeners have to stay registered: the lock state genuinely changes
//! while it is open (the auto-lock timer, another window's "Lock now"), so
//! building it per activation would leak a listener every time.
//! and its listeners have to stay registered: the lock state and the signer's
//! run state genuinely change while it is open (the auto-lock timer, another
//! window's "Lock now", a request arriving), so building it per activation
//! would leak a listener every time.
use std::rc::Rc;
@@ -17,6 +18,7 @@ use gtk::prelude::*;
use libadwaita as adw;
use crate::config::Config;
use crate::runner::{SignerRunner, Status};
use crate::runtime;
use crate::state::AppState;
use crate::ui::plain;
@@ -39,6 +41,9 @@ const AUTO_APPROVE_MAX: f64 = 600.0;
pub struct Preferences {
dialog: adw::PreferencesDialog,
state: Rc<AppState>,
runner: Rc<SignerRunner>,
signer_row: adw::ActionRow,
toggle: gtk::Button,
passphrase: adw::ActionRow,
passphrase_button: gtk::Button,
lock_button: gtk::Button,
@@ -47,7 +52,25 @@ pub struct Preferences {
}
impl Preferences {
pub fn new(state: Rc<AppState>) -> Rc<Self> {
pub fn new(state: Rc<AppState>, runner: Rc<SignerRunner>) -> Rc<Self> {
// --- The signer's run state. ---
let signer_row = plain::row("Listen for requests", "—");
let toggle = gtk::Button::builder()
.label("Start")
.valign(gtk::Align::Center)
// A small flat button, like the "Connect" suffix on the Apps page.
// `suggested-action` is swapped in while stopped so "Start" reads as
// the thing to do; the two classes are never combined (a flat
// suggested button renders its label invisible).
.css_classes(["flat"])
.build();
signer_row.add_suffix(&toggle);
let signer_group = adw::PreferencesGroup::builder()
.title("Signer")
.description("Regent answers requests from paired applications while the signer runs.")
.build();
signer_group.add(&signer_row);
// --- Vault ---
let vault = adw::PreferencesGroup::builder()
.title("Vault")
@@ -110,6 +133,7 @@ impl Preferences {
behaviour.add(&auto_approve);
let page = adw::PreferencesPage::new();
page.add(&signer_group);
page.add(&vault);
page.add(&behaviour);
@@ -120,6 +144,9 @@ impl Preferences {
let preferences = Rc::new(Self {
dialog,
state,
runner,
signer_row,
toggle,
passphrase,
passphrase_button,
lock_button,
@@ -127,6 +154,20 @@ impl Preferences {
auto_approve,
});
{
let button = preferences.toggle.clone();
let preferences = Rc::clone(&preferences);
button.connect_clicked(move |_| match preferences.runner.status() {
Status::Stopped => preferences.runner.start(Vec::new(), None),
Status::Running(_) => preferences.runner.stop(),
Status::Starting => {}
});
}
{
let preferences = Rc::clone(&preferences);
let runner = Rc::clone(&preferences.runner);
runner.listen(move || preferences.refresh());
}
{
let button = preferences.passphrase_button.clone();
let preferences = Rc::clone(&preferences);
@@ -179,8 +220,39 @@ impl Preferences {
self.dialog.present(parent);
}
/// Reflect the vault's state: which actions need it open, and the timeout.
/// Reflect the vault's state and the signer's: which actions need the vault
/// open, the timeout, and whether the signer is listening.
fn refresh(&self) {
let has_keys = self.state.has_keys();
match self.runner.status() {
Status::Stopped => {
self.signer_row.set_subtitle(if has_keys {
"Stopped"
} else {
"Add an identity key first"
});
self.toggle.set_label("Start");
self.toggle.set_sensitive(has_keys);
self.toggle.add_css_class("suggested-action");
self.toggle.remove_css_class("flat");
}
Status::Starting => {
self.signer_row.set_subtitle("Starting…");
self.toggle.set_label("Starting…");
self.toggle.set_sensitive(false);
self.toggle.remove_css_class("suggested-action");
self.toggle.add_css_class("flat");
}
Status::Running(signer) => {
self.signer_row
.set_subtitle(&format!("Listening on {} relay(s)", signer.relay_count()));
self.toggle.set_label("Stop");
self.toggle.set_sensitive(has_keys);
self.toggle.remove_css_class("suggested-action");
self.toggle.add_css_class("flat");
}
}
let locked = self.state.is_locked();
self.passphrase_button.set_sensitive(!locked);
self.lock_button.set_sensitive(!locked);
+6 -1
View File
@@ -117,7 +117,12 @@ impl Windows {
let preferences = match existing {
Some(preferences) => preferences,
None => {
let preferences = Preferences::new(Rc::clone(&self.state));
// The runner is created with the main window, so it exists by
// the time Preferences can be opened.
let Some(runner) = self.runner.borrow().clone() else {
return;
};
let preferences = Preferences::new(Rc::clone(&self.state), runner);
*self.preferences.borrow_mut() = Some(Rc::clone(&preferences));
preferences
}