kirakira/lib/smol/config.dart

24 lines
1.2 KiB
Dart
Raw Normal View History

// Deploy-time configuration, empty by default (mirrors gsmol's config.js).
// A release may bake in a server key with:
// flutter build apk --dart-define=SMOL_PRESET_SERVER=example.org \
// --dart-define=SMOL_PRESET_SERVER_KEY=base32key
// It only makes sense when whoever ships this app and whoever runs that
// smolmaild are the same trusted party: the value arrives with the app
// itself, which is the trusted channel SPEC.md §4 asks a pin to come from.
// This only seeds the first run — once written it is an ordinary pin,
// removable in settings like any other, and never overwrites a host the user
// (or a previous install) already pinned.
import "package:smol_mail/smol/address.dart";
import "package:smol_mail/smol/store.dart";
const _presetHost = String.fromEnvironment("SMOL_PRESET_SERVER");
const _presetKey = String.fromEnvironment("SMOL_PRESET_SERVER_KEY");
void applyPresetServer(SmolStore store) {
if (_presetHost.isEmpty || _presetKey.isEmpty) return;
if (store.serverPin(_presetHost, defaultPort) != null) return;
// A malformed preset leaves the host unpinned rather than blocking boot.
store.pinServer(_presetHost, _presetKey, defaultPort);
}