From 753801c401b27a267836e85b586f9c576bac6b76 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:21:34 +0530 Subject: [PATCH] [auth] Sync frequently to identify logout early --- auth/lib/app/view/app.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/auth/lib/app/view/app.dart b/auth/lib/app/view/app.dart index 5053f70f12..405ab977ab 100644 --- a/auth/lib/app/view/app.dart +++ b/auth/lib/app/view/app.dart @@ -10,6 +10,7 @@ import 'package:ente_auth/events/signed_out_event.dart'; import "package:ente_auth/l10n/l10n.dart"; import 'package:ente_auth/locale.dart'; import "package:ente_auth/onboarding/view/onboarding_page.dart"; +import 'package:ente_auth/services/authenticator_service.dart'; import 'package:ente_auth/services/update_service.dart'; import 'package:ente_auth/services/user_service.dart'; import 'package:ente_auth/services/window_listener_service.dart'; @@ -34,7 +35,8 @@ class App extends StatefulWidget { State createState() => _AppState(); } -class _AppState extends State with WindowListener, TrayListener { +class _AppState extends State + with WindowListener, TrayListener, WidgetsBindingObserver { late StreamSubscription _signedOutEvent; late StreamSubscription _signedInEvent; Locale? locale; @@ -56,6 +58,7 @@ class _AppState extends State with WindowListener, TrayListener { void initState() { initWindowManager(); initTrayManager(); + WidgetsBinding.instance.addObserver(this); _signedOutEvent = Bus.instance.on().listen((event) { if (mounted) { @@ -98,6 +101,16 @@ class _AppState extends State with WindowListener, TrayListener { _signedInEvent.cancel(); } + @override + Future didChangeAppLifecycleState(AppLifecycleState state) async { + debugPrint("AppLifecycleState: $state"); + if (state == AppLifecycleState.resumed) { + if (Configuration.instance.hasConfiguredAccount()) { + AuthenticatorService.instance.onlineSync().ignore(); + } + } + } + @override Widget build(BuildContext context) { if (Platform.isAndroid || kDebugMode) {