From e031c18ecb22e2fb682bcfe984232bb0de961feb Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Tue, 3 Mar 2026 17:37:39 +0100 Subject: [PATCH] firka: fix Live Activity registration with fallback on resume and delayed retry --- .../ui/phone/screens/home/home_screen.dart | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/firka/lib/ui/phone/screens/home/home_screen.dart b/firka/lib/ui/phone/screens/home/home_screen.dart index 2a69742..ea3248e 100644 --- a/firka/lib/ui/phone/screens/home/home_screen.dart +++ b/firka/lib/ui/phone/screens/home/home_screen.dart @@ -410,6 +410,11 @@ class _HomeScreenState extends FirkaState await LiveActivityService.showConsentScreenIfNeeded(); }); } + if (Platform.isIOS) { + Future.delayed(const Duration(seconds: 4), () { + if (!_disposed) _runLiveActivityLoginIfNeeded(); + }); + } } Future _preloadImages() async { @@ -535,10 +540,35 @@ class _HomeScreenState extends FirkaState if (Platform.isIOS) { _refreshLiveActivityOnResume(); + _runLiveActivityLoginIfNeeded(); } } } + /// Fallback: if Live Activity login never ran (e.g. prefetch bailed on lifecycle + /// or fetchData didn't complete), run it once when app is resumed. + void _runLiveActivityLoginIfNeeded() { + if (_didRunLiveActivityLogin || _disposed) return; + Future.delayed(const Duration(milliseconds: 500), () async { + if (_disposed || _didRunLiveActivityLogin) return; + _didRunLiveActivityLogin = true; + final token = pickActiveToken( + tokens: initData.tokens, + settings: initData.settings, + preferredStudentIdNorm: initData.client.model.studentIdNorm, + ); + final studentName = token?.studentId ?? 'Student'; + LiveActivityService.onUserLogin( + client: initData.client, + studentName: studentName, + settingsStore: initData.settings, + ).catchError((e, st) { + _didRunLiveActivityLogin = false; + logger.severe('LiveActivity registration failed: $e', e, st); + }); + }); + } + void _refreshLiveActivityOnResume() async { if (!_hasCompletedFirstPrefetch) return; try {