mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-22 12:02:18 +01:00
Since the material_ui bump the app supplied no framework MaterialLocalizations, so crdt_sync_flutter's E2ePassphraseButton showDialog crashed and the phone stayed locked. Nothing synced and the PC fallback rang on 2026-11-16. The app now provides the localization delegates. Publish failures now reach logcat in release builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
48 lines
1.8 KiB
Dart
48 lines
1.8 KiB
Dart
import 'dart:developer' as developer;
|
|
|
|
import 'package:flutter/foundation.dart' show debugPrint;
|
|
import 'package:wake_alarm_sync/services/alarm_sync_service.dart';
|
|
import 'package:wake_alarm_sync/services/firebase_backend.dart';
|
|
import 'package:wake_alarm_sync/services/settings_sync.dart';
|
|
import 'package:wake_alarm_sync/services/sync_settings.dart';
|
|
|
|
/// Pushes the finished session's record to the PC, best effort.
|
|
///
|
|
/// Runs from the session screen, unattended, at the end of a morning: a
|
|
/// backend that is down must not keep the screen up. The home screen's
|
|
/// startup publish stages the same history again, so a push that fails here
|
|
/// is retried the next time the app is opened.
|
|
class SessionPublisher {
|
|
/// Creates a publisher; [open] is injectable for tests.
|
|
SessionPublisher({Future<AlarmSyncService> Function()? open})
|
|
: _open = open ?? AlarmSyncService.open;
|
|
|
|
final Future<AlarmSyncService> Function() _open;
|
|
|
|
/// Stages and pushes; returns a status line, never throws.
|
|
Future<String> publish() async {
|
|
try {
|
|
final settings = await SyncSettings.load();
|
|
final hasFirebase = await loadAccount() != null;
|
|
if (!settings.isConfigured && !hasFirebase) {
|
|
return 'No sync backend — session kept locally';
|
|
}
|
|
final service = await _open();
|
|
await stageLocalSettings(service);
|
|
await service.push(settings.token);
|
|
await applySyncedSettings(service);
|
|
return 'Session synced to PC ✓';
|
|
} on Exception catch (e, stack) {
|
|
// developer.log is invisible in a release build; logcat needs print.
|
|
debugPrint('WakeAlarmSession: session publish failed: $e');
|
|
developer.log(
|
|
'session publish failed: $e',
|
|
name: 'WakeAlarmSession',
|
|
error: e,
|
|
stackTrace: stack,
|
|
);
|
|
return 'Session kept locally (sync failed)';
|
|
}
|
|
}
|
|
}
|