chore: release client-v1.0.61
Deploy Client / build-client-web (push) Successful in 38s
Deploy Client / build-windows (push) Successful in 1m52s
Deploy Client / build-macos (push) Successful in 1m55s
Deploy Client / build-android (push) Successful in 1m0s
Deploy Client / build-ios (push) Successful in 2m47s
Deploy Client / release-deploy-client (push) Successful in 1m21s
Deploy Client / build-client-web (push) Successful in 38s
Deploy Client / build-windows (push) Successful in 1m52s
Deploy Client / build-macos (push) Successful in 1m55s
Deploy Client / build-android (push) Successful in 1m0s
Deploy Client / build-ios (push) Successful in 2m47s
Deploy Client / release-deploy-client (push) Successful in 1m21s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/config/app_config.dart';
|
||||
import '../core/config/app_constants.dart';
|
||||
|
||||
/// 每次从离线恢复到在线时自增。
|
||||
/// 数据 provider 通过 watch 此值实现网络恢复后自动刷新。
|
||||
@@ -44,27 +45,25 @@ class ConnectivityNotifier extends StateNotifier<bool> {
|
||||
// 独立轻量 Dio:无拦截器。连接预算用 Future.timeout 逐次控制,
|
||||
// 故 BaseOptions 超时放宽到 15s 作为兜底。
|
||||
final _dio = Dio(BaseOptions(
|
||||
connectTimeout: const Duration(seconds: 15),
|
||||
receiveTimeout: const Duration(seconds: 15),
|
||||
connectTimeout: AppConstants.connectivityTimeout,
|
||||
receiveTimeout: AppConstants.connectivityTimeout,
|
||||
));
|
||||
|
||||
/// 每次尝试的超时预算,逐次拉长(越来越长)。
|
||||
static const _budgets = <Duration>[
|
||||
Duration(seconds: 4),
|
||||
Duration(seconds: 8),
|
||||
Duration(seconds: 12),
|
||||
];
|
||||
static const _budgets = AppConstants.connectivityBudgets;
|
||||
|
||||
/// 在线时:每 30 秒轻量检测一次(单次,不重试)
|
||||
/// 在线时:轻量检测一次(单次,不重试)
|
||||
void _startOnlineTimer() {
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(seconds: 30), (_) => _check());
|
||||
_timer =
|
||||
Timer.periodic(AppConstants.connectivityOnlinePoll, (_) => _check());
|
||||
}
|
||||
|
||||
/// 离线时:每 1 分钟嗅探一次,降低频率节省资源
|
||||
/// 离线时:降低频率嗅探,节省资源
|
||||
void _startOfflineTimer() {
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(minutes: 1), (_) => _check());
|
||||
_timer =
|
||||
Timer.periodic(AppConstants.connectivityOfflinePoll, (_) => _check());
|
||||
}
|
||||
|
||||
/// 立即触发一次检测(供外部调用,如 API 请求失败 / 启动时)。单次,不重试。
|
||||
@@ -92,14 +91,14 @@ class ConnectivityNotifier extends StateNotifier<bool> {
|
||||
|
||||
/// 连通性检测。[withRetry]=true 时按 [_budgets] 退避重试,间隔递增。
|
||||
Future<bool> _check({bool withRetry = false}) async {
|
||||
final budgets = withRetry ? _budgets : const [Duration(seconds: 4)];
|
||||
final budgets = withRetry ? _budgets : AppConstants.connectivitySingleBudget;
|
||||
var ok = false;
|
||||
for (var i = 0; i < budgets.length; i++) {
|
||||
ok = await _ping(budgets[i]);
|
||||
if (ok) break;
|
||||
// 最后一次失败后不再等待;中间失败按递增间隔退避(0.6s, 1.2s…)
|
||||
if (i < budgets.length - 1) {
|
||||
await Future.delayed(Duration(milliseconds: 600 * (i + 1)));
|
||||
await Future.delayed(AppConstants.connectivityRetryStep * (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user