ui: tidy the import dialog and the first-run vault step
Reveal the `ncryptsec` password only when the pasted string is one — it is dead weight for an `nsec`/hex import — place it directly under the key field, and let the dialog track its content so the revealed row is not clipped. The submit branch now trims too, so the field and the branch agree on what counts as an `ncryptsec`. Also stop stretching the first-run "Set a passphrase" button to the full width of the status page.
This commit is contained in:
1 file changed
+31
-7
+31
-7
@@ -69,6 +69,7 @@ impl KeysView {
|
||||
let set_up = gtk::Button::builder()
|
||||
.label("Set a passphrase")
|
||||
.css_classes(["pill", "suggested-action"])
|
||||
.halign(gtk::Align::Center)
|
||||
.build();
|
||||
let setup = adw::StatusPage::builder()
|
||||
.icon_name("security-high-symbolic")
|
||||
@@ -631,13 +632,17 @@ impl FormDialog {
|
||||
toolbar.add_top_bar(&header);
|
||||
toolbar.add_bottom_bar(&buttons);
|
||||
toolbar.set_content(Some(&overlay));
|
||||
// Pin the width on the child: with `follows_content_size` below, the
|
||||
// dialog ignores `content-width` (trap 16). 360 fits the 460-wide
|
||||
// identities window (and leaves a margin when it floats).
|
||||
toolbar.set_size_request(360, -1);
|
||||
|
||||
let dialog = adw::Dialog::builder()
|
||||
.title(title)
|
||||
// A plain `AdwDialog` honours `content-width`; an `AdwAlertDialog`
|
||||
// does not (it uses breakpoints — trap 17). 360 fits the 460-wide
|
||||
// identities window (and leaves a margin when it floats).
|
||||
.content_width(360)
|
||||
// Track the content: an `AdwDialog` otherwise fixes its size at
|
||||
// presentation (trap 16), which would clip a row revealed later (the
|
||||
// import dialog's ncryptsec password).
|
||||
.follows_content_size(true)
|
||||
.child(&toolbar)
|
||||
.build();
|
||||
// Return activates the action, but only while it is sensitive; the
|
||||
@@ -865,7 +870,7 @@ fn present_import(handles: Handles, state: Rc<AppState>) {
|
||||
// anyway, and a label is only for keys with no discoverable profile.
|
||||
let name = adw::EntryRow::builder().title("Name").build();
|
||||
let import_password = adw::PasswordEntryRow::builder()
|
||||
.title("Password (ncryptsec only)")
|
||||
.title("ncryptsec password")
|
||||
.build();
|
||||
{
|
||||
let name = name.clone();
|
||||
@@ -888,13 +893,32 @@ fn present_import(handles: Handles, state: Rc<AppState>) {
|
||||
entry.set_activates_default(true);
|
||||
name.set_activates_default(true);
|
||||
import_password.set_activates_default(true);
|
||||
// The ncryptsec password sits directly under the key field, so the reveal is
|
||||
// next to what triggered it; it stays hidden (and wiped) unless the pasted
|
||||
// string is an `ncryptsec` — dead weight for the `nsec`/hex case otherwise.
|
||||
let set_password_visible: Rc<dyn Fn()> = {
|
||||
let entry = entry.clone();
|
||||
let import_password = import_password.clone();
|
||||
Rc::new(move || {
|
||||
let encrypted = entry.text().trim().starts_with("ncryptsec1");
|
||||
import_password.set_visible(encrypted);
|
||||
if !encrypted {
|
||||
import_password.set_text("");
|
||||
}
|
||||
})
|
||||
};
|
||||
set_password_visible();
|
||||
{
|
||||
let set_password_visible = Rc::clone(&set_password_visible);
|
||||
entry.connect_changed(move |_| set_password_visible());
|
||||
}
|
||||
let list = gtk::ListBox::builder()
|
||||
.selection_mode(gtk::SelectionMode::None)
|
||||
.css_classes(["boxed-list"])
|
||||
.build();
|
||||
list.append(&entry);
|
||||
list.append(&name);
|
||||
list.append(&import_password);
|
||||
list.append(&name);
|
||||
fields.append_to(&list);
|
||||
|
||||
let form = Rc::new(FormDialog::new(
|
||||
@@ -960,7 +984,7 @@ fn present_import(handles: Handles, state: Rc<AppState>) {
|
||||
let store = Arc::clone(&store);
|
||||
runtime::spawn(
|
||||
async move {
|
||||
if text.starts_with("ncryptsec1") {
|
||||
if text.trim().starts_with("ncryptsec1") {
|
||||
store
|
||||
.import_user_key_encrypted(&label, &text, &import_password, &passphrase)
|
||||
.await
|
||||
|
||||
Reference in new issue
Block a user