绑定设备+覆盖模式+控制显示bug+在线更新
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_patcher/flutter_patcher.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
@@ -56,6 +57,7 @@ class VersionCheckService {
|
||||
final Dio _dio = Dio(BaseOptions(
|
||||
connectTimeout: const Duration(seconds: 10),
|
||||
receiveTimeout: const Duration(seconds: 10),
|
||||
validateStatus: (status) => true,
|
||||
));
|
||||
|
||||
static const String apiUrl = 'http://8.159.134.0:8012/api/update/check';
|
||||
@@ -67,29 +69,26 @@ class VersionCheckService {
|
||||
required int currentVersionCode,
|
||||
}) async {
|
||||
try {
|
||||
_logger.i('🔍 检查版本更新');
|
||||
_logger.i('📱 APK 自带版本: $currentVersion ($currentVersionCode)');
|
||||
debugPrint('');
|
||||
debugPrint('========================================');
|
||||
debugPrint(' UPDATE CHECK START');
|
||||
debugPrint('========================================');
|
||||
debugPrint('[1] APK version: $currentVersion ($currentVersionCode)');
|
||||
|
||||
// 从文件读取已应用的补丁版本
|
||||
final patchInfo = await _loadPatchVersionInfo();
|
||||
final appliedPatchVersion = patchInfo['version'] as String?;
|
||||
final appliedPatchVersionCode = patchInfo['versionCode'] as int?;
|
||||
|
||||
_logger.i('📂 读取到的补丁版本: $appliedPatchVersion ($appliedPatchVersionCode)');
|
||||
debugPrint('[2] Patch file version: $appliedPatchVersion ($appliedPatchVersionCode)');
|
||||
|
||||
// 如果打过补丁,使用补丁的版本;否则使用 APK 自带版本
|
||||
final requestVersion = appliedPatchVersion ?? currentVersion;
|
||||
final requestVersionCode = appliedPatchVersionCode ?? currentVersionCode;
|
||||
// 始终用 APK 基础版本请求服务端,让服务端返回最新版本
|
||||
// 客户端自己判断本地是否已经是最新
|
||||
final requestVersion = currentVersion;
|
||||
final requestVersionCode = currentVersionCode;
|
||||
|
||||
_logger.i('🚀 请求后端版本: $requestVersion ($requestVersionCode)');
|
||||
|
||||
// 🔥 打印完整的请求参数
|
||||
_logger.i('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||||
_logger.i('📤 App 发送的请求参数:');
|
||||
_logger.i(' URL: $apiUrl');
|
||||
_logger.i(' version: $requestVersion');
|
||||
_logger.i(' versionCode: $requestVersionCode');
|
||||
_logger.i('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||||
debugPrint('[3] Request to server: version=$requestVersion, versionCode=$requestVersionCode');
|
||||
debugPrint('[4] URL: $apiUrl?version=$requestVersion&versionCode=$requestVersionCode');
|
||||
|
||||
final response = await _dio.get(
|
||||
apiUrl,
|
||||
@@ -99,47 +98,67 @@ class VersionCheckService {
|
||||
},
|
||||
);
|
||||
|
||||
// 🔥 打印完整的后端返回数据
|
||||
_logger.i('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||||
_logger.i('📥 后端返回的完整数据:');
|
||||
_logger.i(' statusCode: ${response.statusCode}');
|
||||
_logger.i(' 原始响应: ${response.data}');
|
||||
_logger.i('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||||
debugPrint('[5] HTTP status: ${response.statusCode}');
|
||||
debugPrint('[6] Response body: ${response.data}');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data['data'];
|
||||
final respCode = response.data['code'];
|
||||
final data = response.data['data'];
|
||||
final message = response.data['message'] ?? '';
|
||||
|
||||
if (data['hasUpdate'] == false) {
|
||||
_logger.i('✅ 已是最新版本');
|
||||
return null;
|
||||
}
|
||||
|
||||
final versionInfo = AppVersionInfo.fromJson(data);
|
||||
|
||||
// 🔥 关键修复:无论更新类型是什么,只要本地已应用此版本,就跳过
|
||||
if (appliedPatchVersion != null && appliedPatchVersion == versionInfo.version) {
|
||||
_logger.i('✅ 本地已应用版本 ${versionInfo.version},跳过更新(updateType: ${versionInfo.updateType})');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 🔥 额外检查:如果本地补丁版本code >= 服务端返回的versionCode,也跳过
|
||||
if (appliedPatchVersionCode != null && appliedPatchVersionCode >= versionInfo.versionCode) {
|
||||
_logger.i('✅ 本地补丁版本code ($appliedPatchVersionCode) >= 服务端versionCode (${versionInfo.versionCode}),跳过更新');
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.i('✅ 发现新版本: ${versionInfo.version}');
|
||||
_logger.i('🔄 更新类型: ${versionInfo.updateType}');
|
||||
_logger.i('⚠️ 强制更新: ${versionInfo.forceUpdate}');
|
||||
|
||||
return versionInfo;
|
||||
debugPrint('[7] respCode=$respCode, data=$data, message=$message');
|
||||
|
||||
if (respCode != 200 || data == null) {
|
||||
debugPrint('[RESULT] No update - server returned code=$respCode, data=${data == null ? "NULL" : "NOT_NULL"}, message=$message');
|
||||
debugPrint('========================================');
|
||||
debugPrint('');
|
||||
return null;
|
||||
}
|
||||
|
||||
debugPrint('[7.1] data type: ${data.runtimeType}');
|
||||
debugPrint('[7.2] data keys: ${data is Map ? data.keys.toList() : "NOT A MAP"}');
|
||||
debugPrint('[7.3] hasUpdate = ${data['hasUpdate']} (type: ${data['hasUpdate']?.runtimeType})');
|
||||
debugPrint('[7.4] version = ${data['version']}');
|
||||
debugPrint('[7.5] versionCode = ${data['versionCode']}');
|
||||
debugPrint('[7.6] updateType = ${data['updateType']}');
|
||||
debugPrint('[7.7] patch = ${data['patch']}');
|
||||
debugPrint('[7.8] fullApk = ${data['fullApk']}');
|
||||
|
||||
if (data['hasUpdate'] == false) {
|
||||
debugPrint('[RESULT] No update - hasUpdate=false');
|
||||
debugPrint('========================================');
|
||||
debugPrint('');
|
||||
return null;
|
||||
}
|
||||
|
||||
final versionInfo = AppVersionInfo.fromJson(data);
|
||||
debugPrint('[8] Server version: ${versionInfo.version} (${versionInfo.versionCode})');
|
||||
debugPrint('[9] Update type: ${versionInfo.updateType}, force: ${versionInfo.forceUpdate}');
|
||||
debugPrint('[10] patchUrl: ${versionInfo.patchUrl}');
|
||||
debugPrint('[11] patchMd5: ${versionInfo.patchMd5}');
|
||||
debugPrint('[12] apkUrl: ${versionInfo.apkUrl}');
|
||||
|
||||
// 只用版本字符串判断是否已更新:服务端 hasUpdate=true 说了算
|
||||
if (appliedPatchVersion != null && appliedPatchVersion == versionInfo.version) {
|
||||
debugPrint('[RESULT] No update - already at version ${versionInfo.version}');
|
||||
debugPrint('========================================');
|
||||
debugPrint('');
|
||||
return null;
|
||||
}
|
||||
|
||||
debugPrint('[8.1] Local patch version: ${appliedPatchVersion ?? "none"}');
|
||||
debugPrint('[8.2] Server version: ${versionInfo.version}');
|
||||
debugPrint('[8.3] Version different: ${appliedPatchVersion != versionInfo.version}');
|
||||
|
||||
debugPrint('[RESULT] NEW VERSION FOUND: ${versionInfo.version} (${versionInfo.versionCode})');
|
||||
debugPrint('========================================');
|
||||
debugPrint('');
|
||||
|
||||
return versionInfo;
|
||||
} catch (e) {
|
||||
debugPrint('[RESULT] ERROR: $e');
|
||||
debugPrint('========================================');
|
||||
debugPrint('');
|
||||
return null;
|
||||
} catch (e, stack) {
|
||||
_logger.e('❌ 版本检查失败: $e');
|
||||
_logger.e('❌ 堆栈信息: $stack');
|
||||
throw Exception('网络请求失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user