Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/tinyclient/src/gui/tiny/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,21 @@ 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);
}
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() {
Expand Down
2 changes: 2 additions & 0 deletions crates/tinyclient/src/gui/tiny/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion crates/tinyclient/src/gui/tiny/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
98 changes: 92 additions & 6 deletions crates/tinyclient/src/gui/tiny/settings/passkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -38,6 +37,8 @@ pub(in crate::gui::tiny) struct Held {
pub note: Option<String>,
/// The passkey being renamed, by id, and the field its new name is typed in.
pub renaming: Option<(String, Entity<TextInput>)>,
/// 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,
}
Expand Down Expand Up @@ -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<Shell>) -> Option<Div> {
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
Expand Down Expand Up @@ -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;
Expand All @@ -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 => {
Expand Down Expand Up @@ -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));
}
}
6 changes: 6 additions & 0 deletions e2e/scenarios/tiny-passkey-banner/README.md
Original file line number Diff line number Diff line change
@@ -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.
84 changes: 84 additions & 0 deletions e2e/scenarios/tiny-passkey-banner/drive.py
Original file line number Diff line number Diff line change
@@ -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())
12 changes: 12 additions & 0 deletions e2e/scenarios/tiny-passkey-banner/scenario.json
Original file line number Diff line number Diff line change
@@ -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
}
Loading