halkyon_app: instances, sign-in and sync plumbing for Halkyon's apps

What every Halkyon app's shell needs, taken from Halkyon Learn's and set
on halkyon_base's client: the instances a device keeps an account on,
the first start's tiles and where an instance keeps people's data, the
account switcher; signing in anonymously, with GitHub or an email code,
switching person and the start screen; the gates that build an app's
dependencies per instance and per person; and the sync service with its
status, Settings card and banner. Texts of its own in English and
German take the app's name; what only the app can say, it passes in.
Fakes for apps' tests are in testing.dart.

An instance's basics now name the app it serves (`app`, set by the
host's configuration), and an app accepts only an instance of its own.
SerialQueue and CoalescingRunner move into halkyon_core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-19 15:18:49 +02:00
commit e23cc77f7c
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -0,0 +1,57 @@
import 'package:flutter/widgets.dart';
import 'package:halkyon_app/src/auth/data/auth_repository.dart';
import 'package:halkyon_app/src/auth/data/signed_out_mark.dart';
import 'package:halkyon_app/src/auth/model/auth_status.dart';
/// What can be closed once it is no longer needed: an app's dependencies on
/// an instance, or a person's.
abstract interface class Disposable() {
/// Closes it; nothing of it is used afterwards.
Future<void> dispose();
}
/// What this package needs of an app's dependencies on one instance (its
/// composition root), which `InstanceGate` opens for the instance in use and
/// [AppScope] hands down. An app's own class implements it beside its
/// features' repositories.
abstract interface class AppDependencies<P extends Disposable>()
implements Disposable {
/// The instance's name as people know it (its host), for messages about
/// it.
String get serverName;
/// Who is signed in, and signing in and out.
AuthRepository get auth;
/// Whether the person here signed out, so the app asks how to start.
SignedOutMark get signedOut;
/// Opens the dependencies of [person], once the previous person's have
/// closed; `PersonScope` disposes them when the person goes.
Future<P> openPerson(SignedIn person);
}
/// Hands an app's [dependencies] on the instance in use down the widget
/// tree; `InstanceGate` puts it above the app.
class const AppScope({
/// The app's dependencies.
required final AppDependencies<Disposable> dependencies,
required super.child,
super.key,
}) extends InheritedWidget {
/// The dependencies above [context], as the app's own type [D]
/// (`AppScope.of<Dependencies>(context)`), or as [AppDependencies] where
/// that is all that is needed.
///
/// Doesn't register [context] for rebuilds: the dependencies of one app run
/// never change.
static D of<D extends AppDependencies<Disposable>>(BuildContext context) {
final scope = context.getInheritedWidgetOfExactType<AppScope>();
assert(scope != null, 'No AppScope above this widget.');
return scope!.dependencies as D;
}
@override
bool updateShouldNotify(AppScope oldWidget) =>
dependencies != oldWidget.dependencies;
}