refactor(heartbeat): refresh devices every 2min instead of pinging /auth/me

This commit is contained in:
2026-04-26 09:01:26 +02:00
parent 4be46f71c7
commit a87c7e8732
2 changed files with 9 additions and 8 deletions

View File

@@ -2,20 +2,21 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:sf_infrastructure/sf_infrastructure.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart' show WidgetRef;
import 'package:sf_shared/sf_shared.dart';
class LegacyHeartbeatService {
LegacyHeartbeatService({
required SaveFamilyRepository repository,
required WidgetRef ref,
required void Function() onUnauthorized,
}) : _repository = repository,
}) : _ref = ref,
_onUnauthorized = onUnauthorized;
final SaveFamilyRepository _repository;
final WidgetRef _ref;
final void Function() _onUnauthorized;
Timer? _timer;
static const _interval = Duration(minutes: 3);
static const _interval = Duration(minutes: 2);
void start() {
if (_timer != null) return;
@@ -32,8 +33,8 @@ class LegacyHeartbeatService {
Future<void> _beat() async {
try {
await _repository.get<dynamic>('/auth/me');
debugPrint('[LegacyHeartbeat] /auth/me => OK');
await _ref.read(legacyDevicesProvider.notifier).refresh();
debugPrint('[LegacyHeartbeat] devices refreshed');
} catch (e) {
debugPrint('[LegacyHeartbeat] error: $e');
if (e is DioException && e.response?.statusCode == 401) {

View File

@@ -60,7 +60,7 @@ class SaveFamilyAppState extends ConsumerState<SaveFamilyApp>
if (isLegacyMode) {
_legacyHeartbeat = LegacyHeartbeatService(
repository: GetIt.I<SaveFamilyRepository>(),
ref: ref,
onUnauthorized: () {
clearSessionData();
appRouter.go(AppRoutes.legacyLogin);