fix:第一轮跑
This commit is contained in:
1 parent
e834ec7586
commit
33235f450b
56 files changed
+4357
-210
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import 'update_controller.dart';
|
||||
import 'update_service.dart';
|
||||
|
||||
/// 前后台切换仅低频检查一次,网络失败或无新版本均静默结束。
|
||||
abstract final class UpdateForegroundService {
|
||||
static DateTime? _lastCheck;
|
||||
static Future<void>? _running;
|
||||
static Future<void> check(BuildContext context, WidgetRef ref) {
|
||||
final now = DateTime.now();
|
||||
if (_lastCheck != null &&
|
||||
now.difference(_lastCheck!) < const Duration(minutes: 30)) {
|
||||
return Future.value();
|
||||
}
|
||||
return _running ??= _run(context, ref).whenComplete(() => _running = null);
|
||||
}
|
||||
|
||||
static Future<void> _run(BuildContext context, WidgetRef ref) async {
|
||||
_lastCheck = DateTime.now();
|
||||
try {
|
||||
final info = await ref
|
||||
.read(updateControllerProvider.notifier)
|
||||
.checkUpgrade();
|
||||
if (context.mounted) {
|
||||
await UpdateService.showIfNeeded(
|
||||
context,
|
||||
ref,
|
||||
info,
|
||||
source: UpgradeCheckSource.automatic,
|
||||
);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user