完善PR审查后出现的问题

This commit is contained in:
2026-05-31 10:13:36 +08:00
parent 61ad85f6fc
commit 5ee6ba1e28
4 changed files with 161 additions and 50 deletions
+19 -9
View File
@@ -15,7 +15,16 @@ import '../data/models/app_update_model.dart';
import 'storage_service.dart';
class UpdateService extends ChangeNotifier {
UpdateService._();
UpdateService._()
: _dio = Dio(_dioOptions),
_packageInfoProvider = PackageInfo.fromPlatform;
@visibleForTesting
UpdateService.test({
Dio? dio,
Future<PackageInfo> Function()? packageInfoProvider,
}) : _dio = dio ?? Dio(_dioOptions),
_packageInfoProvider = packageInfoProvider ?? PackageInfo.fromPlatform;
static final UpdateService instance = UpdateService._();
@@ -29,15 +38,16 @@ class UpdateService extends ChangeNotifier {
'https://www.gongyun.org/downloads.html',
);
final Dio _dio = Dio(
BaseOptions(
connectTimeout: const Duration(seconds: 12),
receiveTimeout: const Duration(seconds: 20),
followRedirects: true,
responseType: ResponseType.plain,
),
static final BaseOptions _dioOptions = BaseOptions(
connectTimeout: const Duration(seconds: 12),
receiveTimeout: const Duration(seconds: 20),
followRedirects: true,
responseType: ResponseType.plain,
);
final Dio _dio;
final Future<PackageInfo> Function() _packageInfoProvider;
bool _checking = false;
AppUpdateInfo? _availableUpdate;
@@ -49,7 +59,7 @@ class UpdateService extends ChangeNotifier {
_checking = true;
try {
final current = await PackageInfo.fromPlatform();
final current = await _packageInfoProvider();
final latest = await _fetchLatestRelease(currentVersion: current.version);
if (latest == null ||
_compareVersions(latest.version, current.version) <= 0) {