fix(mobile): change update check interval from 24h to 30-90s random

Allows faster detection of urgent updates while preventing excessive
API calls with random cooldown period.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-10 04:16:03 -08:00
parent 88c59e92fd
commit d6eda59d63
1 changed files with 8 additions and 9 deletions

View File

@ -1,3 +1,4 @@
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
@ -18,11 +19,8 @@ class HomeShellPage extends ConsumerStatefulWidget {
class _HomeShellPageState extends ConsumerState<HomeShellPage> class _HomeShellPageState extends ConsumerState<HomeShellPage>
with WidgetsBindingObserver { with WidgetsBindingObserver {
/// ///
static DateTime? _lastCheckTime; static DateTime? _nextCheckAllowedTime;
/// 24
static const _checkInterval = Duration(hours: 24);
@override @override
void initState() { void initState() {
@ -51,10 +49,11 @@ class _HomeShellPageState extends ConsumerState<HomeShellPage>
Future<void> _checkForUpdateIfNeeded() async { Future<void> _checkForUpdateIfNeeded() async {
final now = DateTime.now(); final now = DateTime.now();
// 24 //
if (_lastCheckTime == null || if (_nextCheckAllowedTime == null || now.isAfter(_nextCheckAllowedTime!)) {
now.difference(_lastCheckTime!) > _checkInterval) { // 30-90
_lastCheckTime = now; final randomSeconds = 30 + Random().nextInt(61); // 30 + 0~60 = 30~90
_nextCheckAllowedTime = now.add(Duration(seconds: randomSeconds));
await checkForAppUpdate(context); await checkForAppUpdate(context);
} }
} }