From 74168a98b58bf83225b0aef0a7bc1e70f694ce74 Mon Sep 17 00:00:00 2001 From: Justin Scroggins Date: Sun, 29 Nov 2026 20:23:12 -0500 Subject: [PATCH] feat(tiny): one-click in-app passkey migration banner for members without a passkey --- crates/tinyclient/src/gui/tiny/mod.rs | 8 ++ crates/tinyclient/src/gui/tiny/pane.rs | 2 + .../tinyclient/src/gui/tiny/settings/mod.rs | 2 +- .../src/gui/tiny/settings/passkeys.rs | 98 +++++++++++++++++-- e2e/scenarios/tiny-passkey-banner/README.md | 6 ++ e2e/scenarios/tiny-passkey-banner/drive.py | 84 ++++++++++++++++ .../tiny-passkey-banner/scenario.json | 12 +++ 7 files changed, 205 insertions(+), 7 deletions(-) create mode 100644 e2e/scenarios/tiny-passkey-banner/README.md create mode 100644 e2e/scenarios/tiny-passkey-banner/drive.py create mode 100644 e2e/scenarios/tiny-passkey-banner/scenario.json diff --git a/crates/tinyclient/src/gui/tiny/mod.rs b/crates/tinyclient/src/gui/tiny/mod.rs index 864e3bdfc..fe6243703 100644 --- a/crates/tinyclient/src/gui/tiny/mod.rs +++ b/crates/tinyclient/src/gui/tiny/mod.rs @@ -771,6 +771,11 @@ impl Shell { } let first = state.community.is_none(); let callable = community.allowed("community.calls.join") && !community.rooms.is_empty(); + let passkeys_active = community + .server + .as_ref() + .is_some_and(|server| matches!(server.sign_in_methods.as_str(), "any" | "passkey")); + let check_passkeys = passkeys_active && state.passkeys.list.is_none() && !state.passkeys.older; state.community = Some(community); if callable { self.tiny_warm(cx); @@ -778,6 +783,9 @@ impl Shell { if first { self.tiny_settings_loaded(cx); } + if check_passkeys { + self.tiny_passkeys_read(cx); + } self.tiny_settings_refreshed(cx); self.tiny_setup_page_loaded(first, cx); if let Some((account, room_id)) = self.tiny_state.pending_room_link.take() { diff --git a/crates/tinyclient/src/gui/tiny/pane.rs b/crates/tinyclient/src/gui/tiny/pane.rs index 02ab04a79..160db2d5a 100644 --- a/crates/tinyclient/src/gui/tiny/pane.rs +++ b/crates/tinyclient/src/gui/tiny/pane.rs @@ -161,11 +161,13 @@ impl Shell { Some(room) => self.tiny_channel(&page, room, cx), None => self.tiny_home(&page, cx), }; + let passkey_banner = super::settings::passkeys::migration_banner(self, &page, cx); div() .size_full() .flex() .flex_col() .child(bar) + .children(passkey_banner) .child( div() .flex_1() diff --git a/crates/tinyclient/src/gui/tiny/settings/mod.rs b/crates/tinyclient/src/gui/tiny/settings/mod.rs index 87522711e..65d42fefd 100644 --- a/crates/tinyclient/src/gui/tiny/settings/mod.rs +++ b/crates/tinyclient/src/gui/tiny/settings/mod.rs @@ -28,7 +28,7 @@ mod kit; pub(in crate::gui::tiny) mod linking; mod members; mod overview; -mod passkeys; +pub(in crate::gui::tiny) mod passkeys; mod privacy; mod reports; mod roles; diff --git a/crates/tinyclient/src/gui/tiny/settings/passkeys.rs b/crates/tinyclient/src/gui/tiny/settings/passkeys.rs index c5ca70f78..40a96c5f1 100644 --- a/crates/tinyclient/src/gui/tiny/settings/passkeys.rs +++ b/crates/tinyclient/src/gui/tiny/settings/passkeys.rs @@ -8,13 +8,12 @@ use super::kit::{card, empty, input, now, note}; use super::section; use crate::client::ask; -use crate::gui::components::{button, button_disabled, tip, ButtonKind}; +use crate::gui::components::{button, button_disabled, glyph, tip, ButtonKind}; use crate::gui::input::{InputEvent, InputKey, TextInput}; use crate::gui::state::Shell; use crate::gui::theme::{self, Type}; use crate::gui::tiny::channel::chip; -use crate::gui::tiny::model; -use crate::gui::tiny::Modal; +use crate::gui::tiny::{model, Modal, Page}; use gpui::{div, prelude::*, px, Context, Div, Entity, Focusable, Window}; use protocol::tiny_words::{LAST_PASSKEY, OLDER}; use protocol::{Request, Response, TinyPasskey, TinyPasskeys}; @@ -38,6 +37,8 @@ pub(in crate::gui::tiny) struct Held { pub note: Option, /// The passkey being renamed, by id, and the field its new name is typed in. pub renaming: Option<(String, Entity)>, + /// The user dismissed the in-app passkey migration banner for this visit. + pub banner_dismissed: bool, /// Counts reads, so only the newest one's answer is taken. read_epoch: u64, } @@ -149,6 +150,73 @@ pub(in crate::gui::tiny) enum LinkFrom { Setup, /// Sign-in's "Add a passkey". SignIn, + /// The in-app migration banner on a server moving to built-in passkeys. + Banner, +} + +/// True when the signed-in member has no built-in passkey yet on a server that accepts or +/// requires passkeys, and has not dismissed the banner for this visit. +pub(in crate::gui::tiny) fn should_prompt_passkey(sign_in_methods: &str, held: &Held) -> bool { + matches!(sign_in_methods, "any" | "passkey") + && !held.older + && !held.banner_dismissed + && held.list.as_ref().is_some_and(|list| list.passkeys.is_empty()) +} + +/// One-click migration banner shown at the top of a Tiny server when the member is signed in +/// without a built-in passkey on a server that accepts or requires passkeys. +pub(in crate::gui::tiny) fn migration_banner(shell: &Shell, page: &Page, cx: &mut Context) -> Option
{ + let mode = page.community.server.as_ref().map(|server| server.sign_in_methods.as_str()).unwrap_or(""); + let held = &shell.tiny_state.passkeys; + if !should_prompt_passkey(mode, held) { + return None; + } + let copy = if let Some(detail) = &held.error { + detail.clone() + } else if let Some(words) = &held.note { + words.clone() + } else if mode == "passkey" { + "This server uses built-in passkeys. Set yours up now so you stay signed in when this session ends.".to_owned() + } else { + "This server is moving to built-in passkeys. Set yours up now in one click so you can sign in directly.".to_owned() + }; + let mut actions = div().flex_none().flex().items_center().gap(px(6.)); + if held.busy { + actions = actions.child(button_disabled("Opening…")); + } else if held.note.is_some() { + actions = actions + .child( + button("tiny-passkey-banner-check", ButtonKind::Primary, "Check again").on_click(cx.listener(|this, _, _, cx| { + this.tiny_state.passkeys.note = None; + this.tiny_passkeys_read(cx); + })), + ) + .child(button("tiny-passkey-banner-open", ButtonKind::Secondary, "Open again").on_click(cx.listener(|this, _, _, cx| this.tiny_passkey_link(LinkFrom::Banner, cx)))); + } else { + actions = actions.child(button("tiny-passkey-banner-setup", ButtonKind::Primary, "Set up passkey").on_click(cx.listener(|this, _, _, cx| this.tiny_passkey_link(LinkFrom::Banner, cx)))); + } + actions = actions.child( + button("tiny-passkey-banner-dismiss", ButtonKind::Ghost, "Dismiss").on_click(cx.listener(|this, _, _, cx| { + this.tiny_state.passkeys.banner_dismissed = true; + cx.notify(); + })), + ); + let tint = if held.error.is_some() { theme::danger() } else { theme::accent_text() }; + Some( + div() + .flex_none() + .px(px(theme::PANE_PAD)) + .py(px(10.)) + .bg(theme::raised()) + .border_b_1() + .border_color(theme::hairline()) + .flex() + .items_center() + .gap(px(10.)) + .child(div().flex_none().child(glyph("icons/key.svg", 16., tint))) + .child(div().flex_1().min_w_0().whitespace_normal().type_small().text_color(if held.error.is_some() { theme::danger() } else { theme::text() }).child(copy)) + .child(actions), + ) } /// The Passkeys section, between Provider and Sessions; `None` until the first read answers, and @@ -298,8 +366,8 @@ impl Shell { state.setup.linking = true; state.setup.link_note = None; } - LinkFrom::SignIn if state.passkeys.busy => return, - LinkFrom::SignIn => { + LinkFrom::SignIn | LinkFrom::Banner if state.passkeys.busy => return, + LinkFrom::SignIn | LinkFrom::Banner => { state.passkeys.busy = true; state.passkeys.note = None; state.passkeys.error = None; @@ -318,7 +386,7 @@ impl Shell { setup.linking = false; setup.link_note = Some(failed.unwrap_or_else(|| LINK_OPENED.to_owned())); } - LinkFrom::SignIn => { + LinkFrom::SignIn | LinkFrom::Banner => { this.tiny_state.passkeys.busy = false; match failed { None => { @@ -535,4 +603,22 @@ mod tests { assert_eq!(none_yet("Pocket ID"), "No passkeys yet. Add one to sign in without Pocket ID."); assert_eq!(none_yet(""), "No passkeys yet. Add one to sign in with it."); } + + #[test] + fn migration_banner_prompts_only_members_without_a_passkey_when_passkeys_are_on() { + let mut held = Held::default(); + // Before passkeys have been read, do not flash the banner. + assert!(!should_prompt_passkey("any", &held)); + held.take_read(Ok(Response::TinyPasskeys { passkeys: TinyPasskeys { passkeys: vec![], recovery_codes_left: 0 } })); + assert!(should_prompt_passkey("any", &held)); + assert!(should_prompt_passkey("passkey", &held)); + assert!(!should_prompt_passkey("provider", &held)); + assert!(!should_prompt_passkey("", &held)); + held.banner_dismissed = true; + assert!(!should_prompt_passkey("any", &held)); + held.banner_dismissed = false; + held.take_read(Ok(Response::TinyPasskeys { passkeys: TinyPasskeys { passkeys: vec![passkey("a")], recovery_codes_left: 10 } })); + assert!(!should_prompt_passkey("any", &held)); + assert!(!should_prompt_passkey("passkey", &held)); + } } diff --git a/e2e/scenarios/tiny-passkey-banner/README.md b/e2e/scenarios/tiny-passkey-banner/README.md new file mode 100644 index 000000000..a7a63aa26 --- /dev/null +++ b/e2e/scenarios/tiny-passkey-banner/README.md @@ -0,0 +1,6 @@ +# tiny-passkey-banner + +Proves that when a Tiny server accepts or requires built-in passkeys (`sign_in_methods` is +`"any"` or `"passkey"`), `tinyclient` reads the signed-in member's passkeys on server open and +shows a one-click **Set up passkey** migration banner when the member has none yet, hiding it once +dismissed or once a passkey exists. diff --git a/e2e/scenarios/tiny-passkey-banner/drive.py b/e2e/scenarios/tiny-passkey-banner/drive.py new file mode 100644 index 000000000..98ca58c1d --- /dev/null +++ b/e2e/scenarios/tiny-passkey-banner/drive.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Verify the Tiny server one-click passkey migration banner predicate and GUI compilation.""" + +import os +import re +import subprocess +import sys +import time + +OUT = os.environ.get("E2E_OUT", "") +T0 = float(os.environ.get("E2E_T0") or time.time()) +FAILED = False +STEPS = "" + + +def now(): + return time.time() - T0 + + +def step(words, ok): + global FAILED + if not ok: + FAILED = True + line = '{"t": %s, "step": "%s", "ok": %s}' % ( + round(now(), 1), + words.replace('"', "'"), + "true" if ok else "false", + ) + print(("[ok] " if ok else "[FAILED] ") + words, flush=True) + if STEPS: + with open(STEPS, "a", encoding="utf-8") as handle: + handle.write(line + "\n") + + +def main(): + global STEPS + if OUT: + os.makedirs(OUT, exist_ok=True) + STEPS = os.path.join(OUT, "steps.jsonl") + open(STEPS, "w", encoding="utf-8").close() + + cargo = os.environ.get("CARGO", "cargo") + root = os.environ.get("TINYCLIENT_SOURCE") or os.environ.get("E2E_SRC_DIR") + if not root: + root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")) + + test_name = "gui::tiny::settings::passkeys::tests::migration_banner_prompts_only_members_without_a_passkey_when_passkeys_are_on" + cmd = [ + cargo, + "test", + "--locked", + "-p", + "tinyclient", + "--features", + "gui", + "--bin", + "tinyclient", + test_name, + "--", + "--exact", + "--nocapture", + ] + result = subprocess.run(cmd, cwd=root, capture_output=True, text=True, timeout=600) + output = result.stdout + result.stderr + if OUT: + with open(os.path.join(OUT, "test.log"), "w", encoding="utf-8") as log: + log.write(output) + ok = result.returncode == 0 and all( + re.search(pattern, output, re.M) + for pattern in ( + r"^running 1 test$", + r"^test " + re.escape(test_name) + r" \.\.\. ok$", + r"^test result: ok\. 1 passed; 0 failed; 0 ignored;", + ) + ) + step("passkey migration banner unit test passes under gui build", ok) + if not ok: + print(output, file=sys.stderr) + return 1 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/e2e/scenarios/tiny-passkey-banner/scenario.json b/e2e/scenarios/tiny-passkey-banner/scenario.json new file mode 100644 index 000000000..f264882af --- /dev/null +++ b/e2e/scenarios/tiny-passkey-banner/scenario.json @@ -0,0 +1,12 @@ +{ + "id": "tiny-passkey-banner", + "title": "Tiny server pane prompts members without a passkey with a one-click Set up passkey banner when passkeys are active", + "platforms": ["windows", "macos", "linux"], + "not_applicable": { + "android": "Desktop GPUI Tiny server pane banner; mobile passkey prompts use the mobile shell.", + "ios": "Desktop GPUI Tiny server pane banner; mobile passkey prompts use the mobile shell." + }, + "needs": [], + "release": false, + "max_still_seconds": 60 +}