feat(app): add the Nostro app, a window for phones and desktops

Linux phones have no banking apps, and a command line is no answer on a
phone. The app does everything the nostro command does and, like it, only
talks to nostrod: it holds no key and no token.

- Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported
  from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens;
  Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics;
  nostro-app; and Nostro.DebugCommands for the --debug-api build.
- Client: every method also in an asynchronous form for an sd-event loop,
  with DaemonMissing and OutcomeUnknown.
- nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes
  net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both
  Flatpaks cross-built for aarch64, and the licence texts they carry.
- nostro-fake-system, a made-up bus and bank with a real nostrod on them, to
  look at the app against. The README's screenshots are taken on it.
- The nostro command: an API key's environment is the key's own to say, so
  --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL.

The published contract changes in three places, before any release (design
rule 10):
- Transactions' query takes `stored`: answered from what nostrod has stored,
  without asking the bank. The app searches with it; before, every search was
  a call to bunq.
- AddBunq's `environment` no longer chooses over what the key says of itself:
  a key of the other environment is refused.
- SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one
  as DEACTIVATED however well it pays, and leaves it as it is when asked,
  without an error.

The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved
from one to the other (design rule 13). Transaction's schema is unchanged.

Verified: the 17 tests pass with every line, function and region of what they
link run, and the five lint runs are clean. Every screen was looked at on the
made-up system, at a phone's and a desktop's sizes in the light and the dark
look, on Plasma under Wayland. What is said of bunq's cards comes from its
sandbox, with throwaway users, and from one real virtual card. Known to have
been used against production: connecting, and reading accounts, payments and
cards. Not known to have been tried: a payment from the app against bunq,
OAuth against bunq, and anything on a phone.

Building the app takes --graphics=, a Crafter.Graphics checkout on its branch
claude/nostro-app, until that branch is merged and pinned here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-11-19 12:27:14 +01:00
commit 5b4037955b
106 changed files with 17804 additions and 289 deletions

View file

@ -0,0 +1,124 @@
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Nostro.Ui:Gesture;
import std;
import :Geometry;
// What a finger or a mouse did, decided from raw pointer phases; the scroll physics of a list; and the frames a
// window that draws only on demand still owes. Pure arithmetic over points and times, so the tests feed it by hand.
export namespace Nostro::Ui {
enum class PointerPhase : std::uint8_t {
Down,
Move,
Up,
Cancel // the compositor took the touch for a gesture of its own: nothing was tapped
};
struct GestureEvent {
enum class Kind : std::uint8_t {
None,
Tap,
LongPress,
DragStart,
Drag,
Fling,
Release
};
Kind kind = Kind::None;
Point at; // the press for Tap, LongPress and DragStart; the current position for Drag, Fling and Release
Point delta; // DragStart and Drag: the movement since the previous event
Point velocity; // Fling: pixels per second
};
// One pointer at a time. A press that ends within the slop and before the long-press time is a tap. A press held
// past that time without moving is a long press: the host runs the timer and calls Timeout, or the first move or the
// release past that time is, when it comes before the timer could (the host's loop dispatched the press and what
// followed it together, behind a stall, each with its own time). Movement past the slop starts a drag, whose release
// is a fling when it was fast enough. Where the host says that what the press landed on has no long press, a press
// held as long is still a tap at its release.
class GestureDetector {
public:
float slopPx = 8;
std::int64_t longPressMs = 500;
float flingMinPxPerS = 60;
// Whether the press that follows can be a long press: the host's word, before each Down.
bool longPress = true;
GestureEvent Feed(PointerPhase phase, Point p, std::int64_t tMs);
// The host's timer at Down + longPressMs.
GestureEvent Timeout(std::int64_t tMs);
bool Pressed() const noexcept;
bool Dragging() const noexcept;
// When the timer for the press that is down is due; nothing while no press waits for one.
std::optional<std::int64_t> LongPressDue() const noexcept;
private:
struct Sample {
Point p;
std::int64_t tMs;
};
GestureEvent LongPressed();
void Forget(std::int64_t tMs);
bool pressed = false;
bool dragging = false;
bool longPressed = false;
Point down;
Point last;
std::int64_t downAt = 0;
std::vector<Sample> samples;
};
// A scrollable extent: the offset is how far the content moved up.
struct ScrollState {
float offset = 0;
float velocity = 0; // pixels per second, positive scrolls further down
float content = 0;
float viewport = 0;
float Max() const noexcept;
void Clamp() noexcept;
void ScrollBy(float dy) noexcept;
void Fling(float pxPerS) noexcept;
// Advances the fling by dt seconds; true while still moving.
bool Tick(float dt) noexcept;
// Scrolls as little as it takes to bring the span from `top` to `bottom` of the content into view, `margin`
// clear of the viewport's edges where the content allows it: what keeps a field that got the focus on screen
// when the on-screen keyboard takes half the window. True when that moved anything.
bool EnsureVisible(float top, float bottom, float margin) noexcept;
};
// The time of a pointer or touch event on the host's own clock. The compositor stamps each event with the time it
// happened, in milliseconds from a base of its own, wrapping at 2^32; events queued while the loop was busy are
// dispatched together when it comes back, so by the host's clock at dispatch a swipe's backlog is a burst, read as a
// fling at many times the finger's speed, and a press and its release that both waited out a stall happen at once.
// The stamps, unwrapped, tick like the host's clock a constant apart, and no event is dispatched before it
// happened: the smallest difference seen is the nearest to that constant.
struct EventClock {
// `stamp` is the compositor's time of the event, 0 when it gave none; `hostNowMs` the host's clock now.
std::int64_t At(std::uint32_t stamp, std::int64_t hostNowMs) noexcept;
private:
std::uint32_t lastStamp = 0;
std::int64_t unwrapped = 0;
std::optional<std::int64_t> ahead; // the host's clock minus the unwrapped stamps
};
// The frames a screen owes the font atlas. A glyph that found no cell drew blank and gets one when a later frame
// begins, from the glyphs not drawn in the last `patience` frames (the frames in flight plus one), and a frame comes
// only when asked for: Again(waiting) after each frame asks for another while glyphs wait, until `patience` frames in
// a row gained no cell, when the screen needs more cells than the atlas holds. A change in the count (a gain, a
// screen change) starts the count over; Reset does on any other change of what is drawn.
struct FrameWait {
std::uint32_t patience = 4;
std::uint32_t last = 0; // the previous frame's waiting glyphs
std::uint32_t gainless = 0; // frames in a row that gained no cell
bool Again(std::uint32_t waiting) noexcept;
void Reset() noexcept;
};
}