From d6eda59d639fbd788ca5d88da22132a85d3266c8 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 10 Dec 2025 04:16:03 -0800 Subject: [PATCH] fix(mobile): change update check interval from 24h to 30-90s random MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../presentation/pages/home_shell_page.dart | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart b/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart index cbae7a33..31b17fbe 100644 --- a/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart +++ b/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart @@ -1,3 +1,4 @@ +import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; @@ -18,11 +19,8 @@ class HomeShellPage extends ConsumerStatefulWidget { class _HomeShellPageState extends ConsumerState with WidgetsBindingObserver { - /// 上次检查更新的时间 - static DateTime? _lastCheckTime; - - /// 检查间隔(24小时) - static const _checkInterval = Duration(hours: 24); + /// 下次允许检查更新的时间 + static DateTime? _nextCheckAllowedTime; @override void initState() { @@ -51,10 +49,11 @@ class _HomeShellPageState extends ConsumerState Future _checkForUpdateIfNeeded() async { final now = DateTime.now(); - // 如果从未检查过,或者距上次检查超过24小时,则检查 - if (_lastCheckTime == null || - now.difference(_lastCheckTime!) > _checkInterval) { - _lastCheckTime = now; + // 如果从未检查过,或者已过冷却时间,则检查 + if (_nextCheckAllowedTime == null || now.isAfter(_nextCheckAllowedTime!)) { + // 设置下次允许检查时间(30-90秒随机间隔) + final randomSeconds = 30 + Random().nextInt(61); // 30 + 0~60 = 30~90 + _nextCheckAllowedTime = now.add(Duration(seconds: randomSeconds)); await checkForAppUpdate(context); } }