replaced account data singleton with a session model

This commit is contained in:
2026-09-27 14:49:38 +02:00
parent 79b33ab248
commit 5e65c4671a
60 changed files with 1019 additions and 679 deletions
+16 -12
View File
@@ -18,7 +18,8 @@ import '../api/marianumconnect/queries/timetable_get_week/timetable_get_week.dar
import '../api/mhsl/custom_timetable_event/get/get_custom_timetable_event.dart';
import '../api/mhsl/custom_timetable_event/get/get_custom_timetable_event_params.dart';
import '../api/mhsl/custom_timetable_event/get/get_custom_timetable_event_response.dart';
import '../model/account_data.dart';
import '../session/session.dart';
import '../session/session_manager.dart';
import '../widget_data/widget_data_mapper.dart';
import '../widget_data/widget_publisher.dart';
import '../widget_data/widget_sync.dart';
@@ -81,17 +82,17 @@ class WidgetBackgroundTask {
/// Throws on fetch failure so the worker path can signal a retry.
static Future<void> runRefreshNow({bool force = false}) async {
await WidgetSync.ensureInitialized();
bool populated;
Session? session;
try {
// Bounded: a hanging keystore read must not stall the caller's budget
// (FCM handler ~25s on iOS) forever.
populated = await AccountData().waitForPopulation().timeout(
session = await SessionManager().waitForLoad().timeout(
const Duration(seconds: 10),
);
} on TimeoutException {
populated = false;
session = null;
}
if (!populated) {
if (session == null) {
// Deliberately does NOT flip the widget to logged-out: a failed or slow
// keychain read (locked iOS device during the 06:00 silent push) is
// indistinguishable from "never logged in" here, and blanking the
@@ -105,7 +106,7 @@ class WidgetBackgroundTask {
log('[widget-refresh] snapshot is fresh, skipping refresh');
return;
}
await _refresh();
await _refresh(session);
}
static Future<void> cancelAll() async {
@@ -142,7 +143,7 @@ void _callbackDispatcher() {
});
}
Future<void> _refresh() async {
Future<void> _refresh(Session session) async {
await WidgetSync.ensureInitialized();
// The background isolate doesn't go through main.dart's BlocBuilder, so we
// re-apply the endpoint the foreground last persisted. Without this the
@@ -181,11 +182,14 @@ Future<void> _refresh() async {
final timegridFuture = _runOrNull<TimetableGetTimegridResponse>(
() => TimetableGetTimegrid().run(),
);
final customEventsFuture = _runOrNull<GetCustomTimetableEventResponse>(
() => GetCustomTimetableEvent(
GetCustomTimetableEventParams(AccountData().getUserSecret()),
).run(),
);
final customEventsFuture = switch (session) {
CredentialSession(:final legacyUserSecret) =>
_runOrNull<GetCustomTimetableEventResponse>(
() => GetCustomTimetableEvent(
GetCustomTimetableEventParams(legacyUserSecret),
).run(),
),
};
final timetable = await timetableFuture;
final subjects = await subjectsFuture;
final rooms = await roomsFuture;