Add an About dialog
A proper AdwAboutDialog, reached from "About Regent" in the primary menu: the app name and icon, the version, the author, a short description, the Unlicense and a "Report an Issue" link, plus Source Code and a Nostr (njump) link on the details page. The author's credit row links to the same njump profile, and is titled "Made by" rather than libadwaita's hardcoded "Code by" for the developers list. The primary menu gains a divider before its configuration group. The About dialog holds no state, so unlike Preferences and "Connect an app" it is built per activation rather than kept around. The acceptance test now drives app.about twice.
This commit is contained in:
6 files changed
+119
-7
No files matched your search
@@ -280,10 +280,11 @@ check $? "clicking the notification brings the window to the front"
|
||||
printf '\n== the app actions ==\n'
|
||||
# Connect and Preferences build their dialogs on the first activation and
|
||||
# re-present them on the second; both reach their window through the registry,
|
||||
# not app.windows(). A `RefCell` borrow held across the build (or the wrong
|
||||
# window) shows up here as a dead process rather than as a silent misbehaviour.
|
||||
# not app.windows(). About is built fresh on every activation. A `RefCell`
|
||||
# borrow held across the build (or the wrong window) shows up here as a dead
|
||||
# process rather than as a silent misbehaviour.
|
||||
OBJ_PATH="/$(printf '%s' "$DATA_DIR" | tr '.' '/')"
|
||||
for action in connect connect preferences preferences identities; do
|
||||
for action in connect connect preferences preferences identities about about; do
|
||||
gdbus call --session --dest "$DATA_DIR" --object-path "$OBJ_PATH" \
|
||||
--method org.freedesktop.Application.ActivateAction "$action" '[]' '{}' \
|
||||
>/dev/null 2>&1
|
||||
@@ -291,7 +292,7 @@ for action in connect connect preferences preferences identities; do
|
||||
done
|
||||
|
||||
kill -0 "$APP" 2>/dev/null
|
||||
check $? "activating Connect and Preferences twice and Identities leaves the app running"
|
||||
check $? "activating Connect, Preferences and About twice and Identities leaves the app running"
|
||||
|
||||
! grep -q 'panicked' "$TMP_HOME/app.log"
|
||||
check $? "and nothing panicked"
|
||||
|
||||
@@ -37,6 +37,7 @@ cargo_build = custom_target(binary_name,
|
||||
'src/store/mod.rs',
|
||||
'src/store/keys.rs',
|
||||
'src/store/profiles.rs',
|
||||
'src/ui/about.rs',
|
||||
'src/ui/activity_view.rs',
|
||||
'src/ui/apps_view.rs',
|
||||
'src/ui/approval.rs',
|
||||
|
||||
@@ -108,6 +108,16 @@ pub fn run(args: &[String]) -> glib::ExitCode {
|
||||
app.add_action(&preferences);
|
||||
app.set_accels_for_action("app.preferences", &["<primary>comma"]);
|
||||
|
||||
// The About dialog. It holds no state, so unlike Preferences and "Connect
|
||||
// an app" it is built per activation rather than once. No accelerator:
|
||||
// there is no standard one for About.
|
||||
let about = gio::SimpleAction::new("about", None);
|
||||
{
|
||||
let windows = Rc::clone(&windows);
|
||||
about.connect_activate(move |_, _| windows.present_about());
|
||||
}
|
||||
app.add_action(&about);
|
||||
|
||||
// A notification body click lands here: GNOME Shell emits
|
||||
// `ActionInvoked("default")` and GLib activates the notification's default
|
||||
// action in-process (the `org.gtk.Notifications` path calls
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
//! The About dialog.
|
||||
//!
|
||||
//! A plain `AdwAboutDialog`: the main window's "About Regent" opens it, and it
|
||||
//! is where the project's identity and the ways to reach its author live.
|
||||
//!
|
||||
//! Built per activation, unlike Preferences and "Connect an app": it registers
|
||||
//! no listeners and holds no state, so there is nothing to keep between
|
||||
//! presentations.
|
||||
|
||||
use adw::prelude::*;
|
||||
use gtk::prelude::*;
|
||||
use libadwaita as adw;
|
||||
|
||||
use crate::{APP_ID, VERSION};
|
||||
|
||||
/// Where Regent is developed — the project page, the source and the issue
|
||||
/// tracker at once.
|
||||
const REPOSITORY: &str = "https://gitea.kosmos.org/raucao/regent";
|
||||
|
||||
/// Râu Cao's Nostr profile as a **njump** link: a `nostr:` URI only opens where
|
||||
/// a client has registered the scheme, while this is an ordinary https URL that
|
||||
/// opens in any browser. The key is
|
||||
/// `npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees`
|
||||
/// (`the_nostr_profile_parses` keeps the nprofile and the npub in step).
|
||||
const NOSTR: &str = "https://njump.me/nprofile1qythwumn8ghj7mn0wd68ytntdaek6mmn9ehhyee0qy2hwumn8ghj7mn0wd68ytn00p68ytnyv4mz7qpqraustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89s8k58x2";
|
||||
|
||||
const COMMENTS: &str = "\
|
||||
Regent signs Nostr events and encrypts or decrypts messages for other \
|
||||
applications, without ever handing them your private key. Every request is \
|
||||
shown to you before it is answered.";
|
||||
|
||||
/// The Unlicense is not one of GTK's known licenses, so it goes through
|
||||
/// `Gtk.License.custom`. `AdwAboutDialog` hands the custom text to
|
||||
/// `gtk_label_set_markup`, so this is our own markup — the raw `LICENSE` file
|
||||
/// (it contains `<https://unlicense.org>`) would not parse.
|
||||
const LICENSE: &str =
|
||||
"Released into the public domain under the <a href=\"https://unlicense.org\">Unlicense</a>.";
|
||||
|
||||
/// Build and present the About dialog inside `parent` — the window the app is.
|
||||
pub fn present(parent: Option<&impl IsA<gtk::Widget>>) {
|
||||
let issues = format!("{REPOSITORY}/issues");
|
||||
|
||||
let dialog = adw::AboutDialog::builder()
|
||||
.application_name("Regent")
|
||||
.application_icon(APP_ID)
|
||||
.version(VERSION)
|
||||
.developer_name("Râu Cao")
|
||||
.comments(COMMENTS)
|
||||
.issue_url(&issues)
|
||||
// `set_license` already implies CUSTOM; the property documents intent.
|
||||
.license_type(gtk::License::Custom)
|
||||
.license(LICENSE)
|
||||
.build();
|
||||
|
||||
// "Code by" is libadwaita's hardcoded heading for the `developers` list, so
|
||||
// the author goes in a custom section titled "Made by" instead. A trailing
|
||||
// URL makes the entry a `LinkRow` (`AdwAboutDialog` parses "Name https://…"),
|
||||
// so the name links out to the same njump profile the Nostr row uses.
|
||||
let author = format!("Râu Cao {NOSTR}");
|
||||
dialog.add_credit_section(Some("Made by"), &[&author]);
|
||||
|
||||
// Details-page links.
|
||||
dialog.add_link("Source Code", REPOSITORY);
|
||||
dialog.add_link("Nostr", NOSTR);
|
||||
|
||||
dialog.present(parent);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use nostr::nips::nip19::{FromBech32, Nip19Profile, ToBech32};
|
||||
|
||||
/// The profile link is a hardcoded constant, so a typo — or a pasted link
|
||||
/// for the wrong key — would otherwise ship silently.
|
||||
#[test]
|
||||
fn the_nostr_profile_parses() {
|
||||
let bech32 = super::NOSTR
|
||||
.strip_prefix("https://njump.me/")
|
||||
.expect("the link must be a njump URL");
|
||||
let profile = Nip19Profile::from_bech32(bech32).expect("a valid nprofile");
|
||||
|
||||
assert_eq!(
|
||||
profile.public_key.to_bech32().expect("npub"),
|
||||
"npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
//! User interface.
|
||||
|
||||
pub mod about;
|
||||
pub mod activity_view;
|
||||
pub mod approval;
|
||||
pub mod apps_view;
|
||||
|
||||
+15
-3
@@ -14,6 +14,7 @@ use libadwaita as adw;
|
||||
|
||||
use crate::runner::SignerRunner;
|
||||
use crate::state::AppState;
|
||||
use crate::ui::about;
|
||||
use crate::ui::activity_view::ActivityView;
|
||||
use crate::ui::apps_view::AppsView;
|
||||
use crate::ui::connect::ConnectDialog;
|
||||
@@ -130,6 +131,12 @@ impl Windows {
|
||||
preferences.present(self.primary().as_ref());
|
||||
}
|
||||
|
||||
/// Present the About dialog inside the window the app "is". Built per
|
||||
/// activation: it holds no state and registers no listeners.
|
||||
pub fn present_about(&self) {
|
||||
about::present(self.primary().as_ref());
|
||||
}
|
||||
|
||||
/// 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.
|
||||
@@ -267,12 +274,17 @@ fn main_window(
|
||||
// widget stays centered. (A `pack_end` would instead *prepend* to the end
|
||||
// box, so the first one ends up rightmost.)
|
||||
//
|
||||
// The primary menu. Locking stays on the lock button, so it needs no entry.
|
||||
// The primary menu. Two groups, split by a section divider: the top group
|
||||
// is what the app *does* (pair, manage), the bottom group is configuration
|
||||
// and app info. Locking stays on the lock button, so it needs no entry.
|
||||
let menu = gio::Menu::new();
|
||||
menu.append(Some("Connect an app…"), Some("app.connect"));
|
||||
menu.append(Some("Manage identities…"), Some("app.identities"));
|
||||
menu.append(Some("Preferences…"), Some("app.preferences"));
|
||||
menu.append(Some("Quit"), Some("app.quit"));
|
||||
let bottom = gio::Menu::new();
|
||||
bottom.append(Some("Preferences"), Some("app.preferences"));
|
||||
bottom.append(Some("About Regent"), Some("app.about"));
|
||||
bottom.append(Some("Quit"), Some("app.quit"));
|
||||
menu.append_section(None, &bottom);
|
||||
let menu_button = gtk::MenuButton::builder()
|
||||
.icon_name("open-menu-symbolic")
|
||||
.menu_model(&menu)
|
||||
|
||||
Reference in new issue
Block a user