added telemetry call on app resume with 15 minute cooldown
This commit is contained in:
+22
-4
@@ -46,9 +46,11 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
int _knownTotalTabs = 1;
|
||||
int _lastTabIndex = 0;
|
||||
bool _userOnLastTab = false;
|
||||
DateTime? _lastTelemetryAt;
|
||||
|
||||
static const Duration _chatListActiveInterval = Duration(seconds: 15);
|
||||
static const Duration _chatListIdleInterval = Duration(seconds: 60);
|
||||
static const Duration _telemetryInterval = Duration(minutes: 15);
|
||||
|
||||
void _onTabControllerChanged() {
|
||||
final newIndex = Main.bottomNavigator.index;
|
||||
@@ -73,10 +75,29 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
if (talkIsActive) bloc.refresh();
|
||||
}
|
||||
|
||||
// Wall-clock throttle rather than Debouncer.throttle: a Timer does not tick
|
||||
// reliably while the app is suspended, so the window would still be open on
|
||||
// the resume it is supposed to let through.
|
||||
void _reportTelemetry() {
|
||||
if (!mounted) return;
|
||||
final now = DateTime.now();
|
||||
final last = _lastTelemetryAt;
|
||||
if (last != null && now.difference(last) < _telemetryInterval) return;
|
||||
_lastTelemetryAt = now;
|
||||
TelemetryHeartbeat.report(
|
||||
notificationsEnabled: context
|
||||
.read<SettingsCubit>()
|
||||
.val()
|
||||
.notificationSettings
|
||||
.enabled,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
log('AppLifecycle: $state');
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_reportTelemetry();
|
||||
Debouncer.throttle('appLifecycleState', const Duration(seconds: 10), () {
|
||||
if (!mounted) return;
|
||||
log('Refreshing due to LifecycleChange');
|
||||
@@ -178,10 +199,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
|
||||
TelemetryHeartbeat.report(
|
||||
notificationsEnabled:
|
||||
context.read<SettingsCubit>().val().notificationSettings.enabled,
|
||||
);
|
||||
_reportTelemetry();
|
||||
|
||||
// A refreshed FCM token invalidates the existing push subscription — the
|
||||
// NC device identifier stays stable, so we simply re-register (NC first,
|
||||
|
||||
Reference in New Issue
Block a user