Close the Connect dialog onto the app list after a pairing
The post-pairing "Client paired" dialog was a redundant confirmation: the app is already in the Apps list by then, so drop it and just show that list. The bunker-URI direction needed more than that: the client connects from outside, so the dialog has no code path in it at all. Snapshot the current identity's app count on present() and close when the registry grows past it — the same change ping record() sends — then bring Apps forward with a new Windows::show_apps(), which the registry reaches through a weak reference.
This commit is contained in:
3 files changed
+88
-38
No files matched your search
@@ -317,7 +317,7 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
|
||||
first, else the user's key label.
|
||||
- Adding a key never switches the selection. A key refresh never clobbers a pick
|
||||
made while it was in flight (the live selection wins over the settings
|
||||
snapshot), and the post-pairing "Client paired" dialog names the identity used.
|
||||
snapshot).
|
||||
|
||||
## Headless mode and CLI pairing (M6)
|
||||
|
||||
@@ -361,6 +361,15 @@ 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.
|
||||
- **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
|
||||
client-initiated direction closes it in `pair_now`; the bunker-URI direction
|
||||
has no code path in the dialog at all — the client connects from outside — so
|
||||
`ConnectDialog` snapshots the current identity's app count on `present()` and
|
||||
closes when the registry grows past it (the `changes` ping `record()` sends).
|
||||
The other place that grows it, a rebind, moves the app into that same
|
||||
identity's list, so it is noticed too.
|
||||
- `Signer::add_client_relays` mirrors `start`: add with
|
||||
`verify_subscriptions`, **wait until connected**, then subscribe an explicit
|
||||
`(RelayUrl, Vec<Filter>)` target. Subscribing before the connection lands is
|
||||
|
||||
+61
-35
@@ -6,7 +6,8 @@
|
||||
//! secret, so keeping it behind a deliberate reveal is the safer default. The
|
||||
//! dialog is built once and re-presented, like Preferences.
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::cell::Cell;
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::sync::Arc;
|
||||
|
||||
use adw::prelude::*;
|
||||
@@ -22,11 +23,19 @@ use crate::signer::approval::{Decision, Question, Request, SigningKey};
|
||||
use crate::signer::{ClientPairing, Signer, pair_client, parse_client_uri};
|
||||
use crate::state::AppState;
|
||||
use crate::ui::{approval, plain, qr};
|
||||
use crate::window::Windows;
|
||||
|
||||
pub struct ConnectDialog {
|
||||
dialog: adw::Dialog,
|
||||
state: Rc<AppState>,
|
||||
runner: Rc<SignerRunner>,
|
||||
/// Held weakly: the registry owns the dialog, so a strong reference would
|
||||
/// be a cycle. Used to bring the Apps page forward after a pairing.
|
||||
windows: Weak<Windows>,
|
||||
/// How many apps the current identity had when the dialog was opened. A
|
||||
/// 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,
|
||||
@@ -41,7 +50,7 @@ pub struct ConnectDialog {
|
||||
}
|
||||
|
||||
impl ConnectDialog {
|
||||
pub fn new(state: Rc<AppState>, runner: Rc<SignerRunner>) -> Rc<Self> {
|
||||
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()
|
||||
@@ -129,6 +138,8 @@ impl ConnectDialog {
|
||||
dialog,
|
||||
state,
|
||||
runner,
|
||||
windows: Rc::downgrade(windows),
|
||||
shown: Cell::new(None),
|
||||
signer_row,
|
||||
toggle,
|
||||
entry,
|
||||
@@ -151,7 +162,10 @@ impl ConnectDialog {
|
||||
{
|
||||
let state = Rc::clone(&connect.state);
|
||||
let listener = Rc::clone(&connect);
|
||||
state.listen_changes(move || listener.refresh());
|
||||
state.listen_changes(move || {
|
||||
listener.refresh();
|
||||
listener.close_if_paired();
|
||||
});
|
||||
}
|
||||
{
|
||||
let runner = Rc::clone(&connect.runner);
|
||||
@@ -202,6 +216,13 @@ impl ConnectDialog {
|
||||
});
|
||||
}
|
||||
|
||||
// The app count is only meaningful while the dialog is open, so drop
|
||||
// the snapshot the moment it closes.
|
||||
{
|
||||
let listener = Rc::clone(&connect);
|
||||
connect.dialog.connect_closed(move |_| listener.shown.set(None));
|
||||
}
|
||||
|
||||
connect.refresh();
|
||||
connect
|
||||
}
|
||||
@@ -211,6 +232,9 @@ impl ConnectDialog {
|
||||
// the pairing secret, so revealing it stays a deliberate act.
|
||||
self.reveal.set_expanded(false);
|
||||
self.picture.set_paintable(None::<&gdk::Paintable>);
|
||||
// Snapshot before the dialog opens: a pairing after this grows the
|
||||
// count, which is how the bunker-URI direction is noticed.
|
||||
self.shown.set(Some(self.app_count()));
|
||||
self.refresh();
|
||||
self.dialog.present(parent);
|
||||
}
|
||||
@@ -378,10 +402,6 @@ impl ConnectDialog {
|
||||
pairing: ClientPairing,
|
||||
identity: PublicKey,
|
||||
) {
|
||||
let app_name = pairing
|
||||
.name
|
||||
.clone()
|
||||
.unwrap_or_else(|| "The application".to_string());
|
||||
let registry = self.state.registry();
|
||||
let activity = self.state.activity();
|
||||
let changes = self.state.changes();
|
||||
@@ -401,42 +421,48 @@ impl ConnectDialog {
|
||||
// refresh the relay count shown by the dialog and Apps page.
|
||||
connect.runner.notify();
|
||||
connect.entry.set_text("");
|
||||
// No "Client paired" confirmation: the app is already in
|
||||
// the list, so just close onto it.
|
||||
connect.dialog.force_close();
|
||||
connect.present_paired(window.as_ref(), &app_name, identity);
|
||||
connect.show_apps();
|
||||
}
|
||||
Err(error) => connect.report_error(window.as_ref(), &error),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn present_paired(
|
||||
&self,
|
||||
window: Option<>k::Window>,
|
||||
app: &str,
|
||||
identity: PublicKey,
|
||||
) {
|
||||
let name = self
|
||||
.state
|
||||
.names()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(&identity.to_hex())
|
||||
.cloned();
|
||||
let npub = identity.to_bech32().unwrap_or_else(|_| identity.to_hex());
|
||||
let who = match name {
|
||||
Some(name) if !name.trim().is_empty() => format!("{name} ({npub})"),
|
||||
_ => npub,
|
||||
/// How many apps the identity being paired with has right now.
|
||||
fn app_count(&self) -> usize {
|
||||
match self.state.current_identity() {
|
||||
Some(identity) => self
|
||||
.state
|
||||
.registry()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.list_for(identity)
|
||||
.len(),
|
||||
None => 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the dialog once a pairing lands, so the app list is what the user
|
||||
/// sees. This is the only path the bunker-URI direction has: the client
|
||||
/// connects from outside, and the registry growing is the one sign of it.
|
||||
fn close_if_paired(&self) {
|
||||
let Some(shown) = self.shown.get() else {
|
||||
return;
|
||||
};
|
||||
let dialog = adw::AlertDialog::builder()
|
||||
.heading_use_markup(false)
|
||||
.body_use_markup(false)
|
||||
.heading("Client paired")
|
||||
.body(format!("{app} now signs as {who}."))
|
||||
.build();
|
||||
plain::dialog(&dialog);
|
||||
dialog.add_response("close", "Close");
|
||||
dialog.set_default_response(Some("close"));
|
||||
dialog.present(window);
|
||||
if self.app_count() > shown {
|
||||
self.dialog.force_close();
|
||||
self.show_apps();
|
||||
}
|
||||
}
|
||||
|
||||
/// Bring the Apps page forward, where the new application now is.
|
||||
fn show_apps(&self) {
|
||||
if let Some(windows) = self.windows.upgrade() {
|
||||
windows.show_apps();
|
||||
}
|
||||
}
|
||||
|
||||
fn report_error(&self, window: Option<>k::Window>, message: &str) {
|
||||
|
||||
+17
-2
@@ -38,6 +38,9 @@ pub struct Windows {
|
||||
preferences: RefCell<Option<Rc<Preferences>>>,
|
||||
runner: RefCell<Option<Rc<SignerRunner>>>,
|
||||
connect: RefCell<Option<Rc<ConnectDialog>>>,
|
||||
/// The main window's page stack, so the "Connect an app" dialog can bring
|
||||
/// Apps forward after a pairing. `None` until the main window is built.
|
||||
main_stack: RefCell<Option<adw::ViewStack>>,
|
||||
}
|
||||
|
||||
impl Windows {
|
||||
@@ -50,6 +53,7 @@ impl Windows {
|
||||
preferences: RefCell::new(None),
|
||||
runner: RefCell::new(None),
|
||||
connect: RefCell::new(None),
|
||||
main_stack: RefCell::new(None),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -124,7 +128,7 @@ impl Windows {
|
||||
/// Present the "Connect an app…" dialog inside the window the app "is".
|
||||
/// Built once and re-presented, like Preferences: its listeners stay
|
||||
/// registered and the dialog re-presents after being closed.
|
||||
pub fn present_connect(&self) {
|
||||
pub fn present_connect(self: &Rc<Self>) {
|
||||
// Bind the clone to a local first: a `match` scrutinee is a temporary
|
||||
// scope that lasts to the end of the match, so an inline `borrow()`
|
||||
// would still hold the `Ref` when the `None` arm takes `borrow_mut()`.
|
||||
@@ -135,7 +139,7 @@ impl Windows {
|
||||
let Some(runner) = self.runner.borrow().clone() else {
|
||||
return;
|
||||
};
|
||||
let connect = ConnectDialog::new(Rc::clone(&self.state), runner);
|
||||
let connect = ConnectDialog::new(Rc::clone(&self.state), runner, self);
|
||||
*self.connect.borrow_mut() = Some(Rc::clone(&connect));
|
||||
connect
|
||||
}
|
||||
@@ -143,6 +147,14 @@ impl Windows {
|
||||
connect.present(self.primary().as_ref());
|
||||
}
|
||||
|
||||
/// Bring the Apps page to the front. A pairing closes the "Connect an app"
|
||||
/// dialog onto it, so the new application is what the user sees.
|
||||
pub fn show_apps(&self) {
|
||||
if let Some(stack) = self.main_stack.borrow().as_ref() {
|
||||
stack.set_visible_child_name("apps");
|
||||
}
|
||||
}
|
||||
|
||||
/// Follow the key list: the main window is what the app is once a key
|
||||
/// exists, and the identities window is what it is when the last key is
|
||||
/// removed — the state the app starts in.
|
||||
@@ -205,6 +217,9 @@ fn main_window(
|
||||
let activity_view = ActivityView::new(Rc::clone(state));
|
||||
|
||||
let stack = adw::ViewStack::new();
|
||||
// The Connect dialog reaches back through the registry to bring Apps
|
||||
// forward after a pairing; see `Windows::show_apps`.
|
||||
windows.main_stack.replace(Some(stack.clone()));
|
||||
// Apps first: it is what the app is for, and the switcher follows the stack.
|
||||
stack.add_titled_with_icon(
|
||||
&apps_view.widget,
|
||||
|
||||
Reference in new issue
Block a user