mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-22 20:22:17 +01:00
A bypass during a live morning session restarted the ring natively, and the session recorded that re-ring as deadline:<leg> (C7, 2026-11-22). Bypass.record now stamps the cause (dated) when nothing was ringing; the session takes it on its tick or on the dismiss and records bypass:<cause>. A bypass during a deadline re-ring stamps nothing: one sound, one re-ring. Also a debug-only sync backend: a probe build with WAKE_SYNC_EMULATOR syncs to the PC's RTDB emulator instead of prod and the GitHub mirror, with scripts/emu_published.py reading it back for _fallback --published. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.8 KiB
Dart
52 lines
1.8 KiB
Dart
/// A debug-only sync backend: the Firebase RTDB emulator on the PC.
|
|
///
|
|
/// The emulator checks (a bypass reaching "the test backend") need a
|
|
/// backend, and the AVD must never sign in to prod: a probe's per-date
|
|
/// merge would overwrite the phone's real morning. So the probe build
|
|
/// passes `--dart-define=WAKE_SYNC_EMULATOR=http://10.0.2.2:9000` (the AVD's
|
|
/// name for the PC's loopback), and every sync open then returns this client
|
|
/// *instead of* prod Firebase and the GitHub mirror, never beside them.
|
|
///
|
|
/// The define is a compile-time constant: release and `deploy.sh` builds
|
|
/// never set it, so there the branch is dead code. The emulator answers
|
|
/// `auth=owner` as admin, so no Google sign-in is involved.
|
|
library;
|
|
|
|
import 'package:crdt_sync/crdt_sync.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
/// The emulator's origin, or empty (every release build).
|
|
const String kSyncEmulatorUrl = String.fromEnvironment('WAKE_SYNC_EMULATOR');
|
|
|
|
/// Whether this build syncs to the emulator only.
|
|
bool get syncEmulatorOn => kSyncEmulatorUrl.isNotEmpty;
|
|
|
|
/// The account marker the sync gates look for; carries no credential.
|
|
const FirebaseAccount emulatorAccount = FirebaseAccount(
|
|
email: 'emulator',
|
|
password: '',
|
|
);
|
|
|
|
/// Signs every request `auth=owner`, the emulator's admin token.
|
|
class EmulatorTokenProvider extends FirebaseTokenProvider {
|
|
/// Creates a provider that never talks to Google.
|
|
EmulatorTokenProvider()
|
|
: super(apiKey: 'emulator', store: InMemoryCredentialStore());
|
|
|
|
@override
|
|
Future<String> idToken() async => 'owner';
|
|
|
|
@override
|
|
Future<bool> hasSession() async => true;
|
|
}
|
|
|
|
/// A client for the emulator at [url].
|
|
FirebaseRestClient emulatorClient({
|
|
String url = kSyncEmulatorUrl,
|
|
http.Client? httpClient,
|
|
}) => FirebaseRestClient(
|
|
databaseUrl: url,
|
|
auth: EmulatorTokenProvider(),
|
|
httpClient: httpClient,
|
|
);
|