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,605 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart' as intl;
import 'halkyon_app_localizations_de.dart';
import 'halkyon_app_localizations_en.dart';
// ignore_for_file: type=lint
/// Callers can lookup localized strings with an instance of HalkyonAppLocalizations
/// returned by `HalkyonAppLocalizations.of(context)`.
///
/// Applications need to include `HalkyonAppLocalizations.delegate()` in their app's
/// `localizationDelegates` list, and the locales they support in the app's
/// `supportedLocales` list. For example:
///
/// ```dart
/// import 'l10n/halkyon_app_localizations.dart';
///
/// return MaterialApp(
/// localizationsDelegates: HalkyonAppLocalizations.localizationsDelegates,
/// supportedLocales: HalkyonAppLocalizations.supportedLocales,
/// home: MyApplicationHome(),
/// );
/// ```
///
/// ## Update pubspec.yaml
///
/// Please make sure to update your pubspec.yaml to include the following
/// packages:
///
/// ```yaml
/// dependencies:
/// # Internationalization support.
/// flutter_localizations:
/// sdk: flutter
/// intl: any # Use the pinned version from flutter_localizations
///
/// # Rest of dependencies
/// ```
///
/// ## iOS Applications
///
/// iOS applications define key application metadata, including supported
/// locales, in an Info.plist file that is built into the application bundle.
/// To configure the locales supported by your app, you’ll need to edit this
/// file.
///
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
/// Then, in the Project Navigator, open the Info.plist file under the Runner
/// project’s Runner folder.
///
/// Next, select the Information Property List item, select Add Item from the
/// Editor menu, then select Localizations from the pop-up menu.
///
/// Select and expand the newly-created Localizations item then, for each
/// locale your application supports, add a new item and select the locale
/// you wish to add from the pop-up menu in the Value field. This list should
/// be consistent with the languages listed in the HalkyonAppLocalizations.supportedLocales
/// property.
abstract class HalkyonAppLocalizations {
HalkyonAppLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
final String localeName;
static HalkyonAppLocalizations of(BuildContext context) {
return Localizations.of<HalkyonAppLocalizations>(
context,
HalkyonAppLocalizations,
)!;
}
static const LocalizationsDelegate<HalkyonAppLocalizations> delegate =
_HalkyonAppLocalizationsDelegate();
/// A list of this localizations delegate along with the default localizations
/// delegates.
///
/// Returns a list of localizations delegates containing this delegate along with
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
/// and GlobalWidgetsLocalizations.delegate.
///
/// Additional delegates can be added by appending to this list in
/// MaterialApp. This list does not have to be used at all if a custom list
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];
/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Locale('de'),
Locale('en'),
Locale('en', 'GB'),
Locale('en', 'US'),
];
/// No description provided for @tryAgain.
///
/// In en, this message translates to:
/// **'Try again'**
String get tryAgain;
/// Screen readers hear it for the wordmark on the first start.
///
/// In en, this message translates to:
/// **'Welcome to {app}'**
String instanceWelcome(String app);
/// No description provided for @instanceBuiltInTagline.
///
/// In en, this message translates to:
/// **'Comes with the app'**
String get instanceBuiltInTagline;
/// No description provided for @instanceAnother.
///
/// In en, this message translates to:
/// **'Another instance'**
String get instanceAnother;
/// No description provided for @instanceAnotherTagline.
///
/// In en, this message translates to:
/// **'Enter its address'**
String get instanceAnotherTagline;
/// No description provided for @instanceAddress.
///
/// In en, this message translates to:
/// **'Instance address'**
String get instanceAddress;
/// No description provided for @instanceAddressInvalid.
///
/// In en, this message translates to:
/// **'This isn\'t an address.'**
String get instanceAddressInvalid;
/// No description provided for @instanceAddressRequired.
///
/// In en, this message translates to:
/// **'Enter the address of an instance.'**
String get instanceAddressRequired;
/// No description provided for @instanceContinue.
///
/// In en, this message translates to:
/// **'Continue'**
String get instanceContinue;
/// No description provided for @instanceUnreachable.
///
/// In en, this message translates to:
/// **'No instance of {app} answers at {name}.'**
String instanceUnreachable(String app, String name);
/// No description provided for @instanceUseBuiltIn.
///
/// In en, this message translates to:
/// **'Use {name}'**
String instanceUseBuiltIn(String name);
/// No description provided for @instanceOpenFailed.
///
/// In en, this message translates to:
/// **'Couldn\'t open the app on {name}.'**
String instanceOpenFailed(String name);
/// No description provided for @instanceDataAndBackupsIn.
///
/// In en, this message translates to:
/// **'Data and backups: {place}'**
String instanceDataAndBackupsIn(String place);
/// No description provided for @instanceDataIn.
///
/// In en, this message translates to:
/// **'Data: {place}'**
String instanceDataIn(String place);
/// No description provided for @instanceBackupsIn.
///
/// In en, this message translates to:
/// **'Backups: {place}'**
String instanceBackupsIn(String place);
/// No description provided for @instanceNoBackups.
///
/// In en, this message translates to:
/// **'No backups'**
String get instanceNoBackups;
/// No description provided for @instanceEuropeanUnion.
///
/// In en, this message translates to:
/// **'European Union'**
String get instanceEuropeanUnion;
/// No description provided for @accountsTitle.
///
/// In en, this message translates to:
/// **'Accounts'**
String get accountsTitle;
/// No description provided for @accountAdd.
///
/// In en, this message translates to:
/// **'Add account'**
String get accountAdd;
/// No description provided for @accountAddSubtitle.
///
/// In en, this message translates to:
/// **'Choose the instance for the account to add.'**
String get accountAddSubtitle;
/// No description provided for @accountSignedIn.
///
/// In en, this message translates to:
/// **'Signed in'**
String get accountSignedIn;
/// No description provided for @accountAnonymous.
///
/// In en, this message translates to:
/// **'Anonymous'**
String get accountAnonymous;
/// No description provided for @accountRemoveTooltip.
///
/// In en, this message translates to:
/// **'Remove account'**
String get accountRemoveTooltip;
/// No description provided for @accountRemoveTitle.
///
/// In en, this message translates to:
/// **'Remove account?'**
String get accountRemoveTitle;
/// No description provided for @accountRemoveMessage.
///
/// In en, this message translates to:
/// **'Removes the account on {name} from this device, with all the device holds of it. What it synced stays on {name}: sign in there again to have it. An anonymous account can\'t be signed into again.'**
String accountRemoveMessage(String name);
/// No description provided for @accountRemoveConfirm.
///
/// In en, this message translates to:
/// **'Remove'**
String get accountRemoveConfirm;
/// No description provided for @sessionUnreachable.
///
/// In en, this message translates to:
/// **'Couldn\'t reach the server.'**
String get sessionUnreachable;
/// No description provided for @personDataFailed.
///
/// In en, this message translates to:
/// **'Couldn\'t open this device\'s data.'**
String get personDataFailed;
/// No description provided for @startSignedOut.
///
/// In en, this message translates to:
/// **'Signed out'**
String get startSignedOut;
/// No description provided for @startOn.
///
/// In en, this message translates to:
/// **'Start on {instance}:'**
String startOn(String instance);
/// No description provided for @startWithGitHub.
///
/// In en, this message translates to:
/// **'Sign in with GitHub'**
String get startWithGitHub;
/// No description provided for @startWithEmail.
///
/// In en, this message translates to:
/// **'Continue with email'**
String get startWithEmail;
/// No description provided for @startWithoutAccount.
///
/// In en, this message translates to:
/// **'Start without an account'**
String get startWithoutAccount;
/// No description provided for @startAnonymous.
///
/// In en, this message translates to:
/// **'Progress is saved on this device. Sign in to keep it.'**
String get startAnonymous;
/// No description provided for @startGitHubFailed.
///
/// In en, this message translates to:
/// **'Couldn\'t sign in with GitHub.'**
String get startGitHubFailed;
/// No description provided for @startNoGitHubAccount.
///
/// In en, this message translates to:
/// **'No account here signs in with this GitHub account yet. Start without an account, then add GitHub in Profile.'**
String get startNoGitHubAccount;
/// No description provided for @startOtherInstance.
///
/// In en, this message translates to:
/// **'Use another instance'**
String get startOtherInstance;
/// No description provided for @emailSignInTitle.
///
/// In en, this message translates to:
/// **'Continue with email'**
String get emailSignInTitle;
/// No description provided for @emailSignInIntro.
///
/// In en, this message translates to:
/// **'We mail you a code to sign in. This instance keeps only a fingerprint of your address, never the address itself, and writes to it only when you ask for a code.'**
String get emailSignInIntro;
/// No description provided for @emailSignInAddress.
///
/// In en, this message translates to:
/// **'Email address'**
String get emailSignInAddress;
/// No description provided for @emailSignInSend.
///
/// In en, this message translates to:
/// **'Send code'**
String get emailSignInSend;
/// No description provided for @emailSignInCodeSent.
///
/// In en, this message translates to:
/// **'We mailed a code to {address}. It\'s valid for 15 minutes.'**
String emailSignInCodeSent(String address);
/// No description provided for @emailSignInResent.
///
/// In en, this message translates to:
/// **'A new code is on its way.'**
String get emailSignInResent;
/// No description provided for @emailSignInCode.
///
/// In en, this message translates to:
/// **'Code'**
String get emailSignInCode;
/// No description provided for @emailSignInContinue.
///
/// In en, this message translates to:
/// **'Continue'**
String get emailSignInContinue;
/// No description provided for @emailSignInResend.
///
/// In en, this message translates to:
/// **'Send a new code'**
String get emailSignInResend;
/// No description provided for @emailSignInOtherAddress.
///
/// In en, this message translates to:
/// **'Use another address'**
String get emailSignInOtherAddress;
/// No description provided for @emailSignInSwitchTitle.
///
/// In en, this message translates to:
/// **'Switch to the account of {address}?'**
String emailSignInSwitchTitle(String address);
/// No description provided for @emailSignInSwitchConfirm.
///
/// In en, this message translates to:
/// **'Switch'**
String get emailSignInSwitchConfirm;
/// No description provided for @emailSignInSwitchStay.
///
/// In en, this message translates to:
/// **'Stay anonymous'**
String get emailSignInSwitchStay;
/// No description provided for @emailSignInTaken.
///
/// In en, this message translates to:
/// **'{address} already signs in to another account. To switch to it, sign out first.'**
String emailSignInTaken(String address);
/// No description provided for @emailSignInUnavailable.
///
/// In en, this message translates to:
/// **'This instance doesn\'t offer signing in with email.'**
String get emailSignInUnavailable;
/// No description provided for @emailSignInNotAnAddress.
///
/// In en, this message translates to:
/// **'This isn\'t an email address.'**
String get emailSignInNotAnAddress;
/// No description provided for @emailSignInTooManyCodes.
///
/// In en, this message translates to:
/// **'Too many codes in the last hour. Try again later.'**
String get emailSignInTooManyCodes;
/// No description provided for @emailSignInWrongCode.
///
/// In en, this message translates to:
/// **'That code isn\'t right.'**
String get emailSignInWrongCode;
/// No description provided for @emailSignInTooManyTries.
///
/// In en, this message translates to:
/// **'Too many wrong codes. Ask for a new one.'**
String get emailSignInTooManyTries;
/// No description provided for @emailSignInCodeExpired.
///
/// In en, this message translates to:
/// **'This code is no longer valid. Ask for a new one.'**
String get emailSignInCodeExpired;
/// No description provided for @emailSignInOtherAddressLinked.
///
/// In en, this message translates to:
/// **'You already sign in with another address.'**
String get emailSignInOtherAddressLinked;
/// No description provided for @emailSignInMailFailed.
///
/// In en, this message translates to:
/// **'The instance couldn\'t send the mail. Try again later.'**
String get emailSignInMailFailed;
/// No description provided for @emailSignInFailed.
///
/// In en, this message translates to:
/// **'Couldn\'t reach the instance. Try again.'**
String get emailSignInFailed;
/// No description provided for @syncTitle.
///
/// In en, this message translates to:
/// **'Sync'**
String get syncTitle;
/// No description provided for @syncNow.
///
/// In en, this message translates to:
/// **'Sync now'**
String get syncNow;
/// No description provided for @syncStateSyncing.
///
/// In en, this message translates to:
/// **'Syncing…'**
String get syncStateSyncing;
/// No description provided for @syncStateSynced.
///
/// In en, this message translates to:
/// **'Everything synced'**
String get syncStateSynced;
/// No description provided for @syncStateFailing.
///
/// In en, this message translates to:
/// **'Sync is failing'**
String get syncStateFailing;
/// No description provided for @syncStateNotYet.
///
/// In en, this message translates to:
/// **'Not synced yet'**
String get syncStateNotYet;
/// No description provided for @syncStateMismatch.
///
/// In en, this message translates to:
/// **'This app can\'t sync with {server}'**
String syncStateMismatch(String server);
/// No description provided for @syncMismatchDetail.
///
/// In en, this message translates to:
/// **'Update the app. If it is up to date, the server needs an update. What you do meanwhile stays on this device and syncs afterwards.'**
String get syncMismatchDetail;
/// No description provided for @syncLastCompleted.
///
/// In en, this message translates to:
/// **'Last completed at {time}'**
String syncLastCompleted(String time);
/// No description provided for @syncLastFailed.
///
/// In en, this message translates to:
/// **'Last attempt failed at {time}'**
String syncLastFailed(String time);
/// No description provided for @syncNoRunYet.
///
/// In en, this message translates to:
/// **'No sync has completed since the app started'**
String get syncNoRunYet;
/// No description provided for @syncPending.
///
/// In en, this message translates to:
/// **'{count, plural, =1{1 change waits to sync} other{{count} changes wait to sync}}'**
String syncPending(int count);
/// No description provided for @syncTroubleLabel.
///
/// In en, this message translates to:
/// **'Sync needs attention'**
String get syncTroubleLabel;
/// No description provided for @syncMismatchBanner.
///
/// In en, this message translates to:
/// **'This app can\'t sync with {server} any more. Update it to keep syncing.'**
String syncMismatchBanner(String server);
/// No description provided for @syncMismatchMore.
///
/// In en, this message translates to:
/// **'More'**
String get syncMismatchMore;
}
class _HalkyonAppLocalizationsDelegate
extends LocalizationsDelegate<HalkyonAppLocalizations> {
const _HalkyonAppLocalizationsDelegate();
@override
Future<HalkyonAppLocalizations> load(Locale locale) {
return SynchronousFuture<HalkyonAppLocalizations>(
lookupHalkyonAppLocalizations(locale),
);
}
@override
bool isSupported(Locale locale) =>
<String>['de', 'en'].contains(locale.languageCode);
@override
bool shouldReload(_HalkyonAppLocalizationsDelegate old) => false;
}
HalkyonAppLocalizations lookupHalkyonAppLocalizations(Locale locale) {
// Lookup logic when language+country codes are specified.
switch (locale.languageCode) {
case 'en':
{
switch (locale.countryCode) {
case 'GB':
return HalkyonAppLocalizationsEnGb();
case 'US':
return HalkyonAppLocalizationsEnUs();
}
break;
}
}
// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'de':
return HalkyonAppLocalizationsDe();
case 'en':
return HalkyonAppLocalizationsEn();
}
throw FlutterError(
'HalkyonAppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.',
);
}