Compare commits
No commits in common. "44cf59749d6a805ae5ccebfd27e8aae106132cf4" and "8799a6254420ba224de025d6a282175e25b3b229" have entirely different histories.
44cf59749d
...
8799a62544
|
|
@ -3,6 +3,5 @@
|
||||||
"preferredOrientations": [
|
"preferredOrientations": [
|
||||||
"portraitUp",
|
"portraitUp",
|
||||||
"portraitDown"
|
"portraitDown"
|
||||||
],
|
]
|
||||||
"upgradeConfigUrl": "https://umsapi.23544.com/api/biz/version/get-latest-config?appId=787154824761413&environment=1"
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ application_id: "com.yuanxuan.aixue"
|
||||||
app_key: "aixue_prod"
|
app_key: "aixue_prod"
|
||||||
default_url: "http://xszy.lzzneng.com/login.html"
|
default_url: "http://xszy.lzzneng.com/login.html"
|
||||||
bootstrap_config_url: ""
|
bootstrap_config_url: ""
|
||||||
upgrade_config_url: "https://umsapi.23544.com/api/biz/version/get-latest-config?appId=787154824761413&environment=1"
|
upgrade_config_url: ""
|
||||||
preferred_orientations:
|
preferred_orientations:
|
||||||
- "portraitUp"
|
- "portraitUp"
|
||||||
- "portraitDown"
|
- "portraitDown"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
import 'package:webview_flutter_android/webview_flutter_android.dart';
|
import 'package:webview_flutter_android/webview_flutter_android.dart';
|
||||||
import 'package:yx_app_upgrade_flutter/app_upgrade_plugin.dart';
|
|
||||||
import 'package:yx_app_upgrade_flutter/yx_app_upgrade_flutter.dart';
|
import 'package:yx_app_upgrade_flutter/yx_app_upgrade_flutter.dart';
|
||||||
|
|
||||||
export 'package:yx_app_upgrade_flutter/yx_app_upgrade_flutter.dart'
|
export 'package:yx_app_upgrade_flutter/yx_app_upgrade_flutter.dart'
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
part of '../../core_app.dart';
|
part of '../../core_app.dart';
|
||||||
|
|
||||||
/// 升级明细配置,对应升级接口中的 `upgrade` 字段。
|
/// 远程升级配置模型。
|
||||||
class ShellUpgradeReleaseConfig {
|
class ShellUpgradeConfig {
|
||||||
final String? versionName;
|
final String? versionName;
|
||||||
final int? version;
|
final int? version;
|
||||||
final int? isForce;
|
final int? isForce;
|
||||||
|
|
@ -9,7 +9,7 @@ class ShellUpgradeReleaseConfig {
|
||||||
final String? filePath;
|
final String? filePath;
|
||||||
final int? fileSize;
|
final int? fileSize;
|
||||||
|
|
||||||
const ShellUpgradeReleaseConfig({
|
ShellUpgradeConfig({
|
||||||
this.versionName,
|
this.versionName,
|
||||||
this.version,
|
this.version,
|
||||||
this.isForce,
|
this.isForce,
|
||||||
|
|
@ -18,241 +18,24 @@ class ShellUpgradeReleaseConfig {
|
||||||
this.fileSize,
|
this.fileSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory ShellUpgradeReleaseConfig.fromJson(Map<String, dynamic> json) {
|
|
||||||
return ShellUpgradeReleaseConfig(
|
|
||||||
versionName: _readShellUpgradeString(json['versionName']),
|
|
||||||
version: _readShellUpgradeInt(json['version']),
|
|
||||||
isForce: _readShellUpgradeInt(json['isForce']),
|
|
||||||
remark: _readShellUpgradeString(json['remark']),
|
|
||||||
filePath: _readShellUpgradeString(json['filePath']),
|
|
||||||
fileSize: _readShellUpgradeInt(json['fileSize']),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ShellUpgradeReleaseConfig? fromDynamic(dynamic value) {
|
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (value is Map<String, dynamic>) {
|
|
||||||
return ShellUpgradeReleaseConfig.fromJson(value);
|
|
||||||
}
|
|
||||||
if (value is Map) {
|
|
||||||
return ShellUpgradeReleaseConfig.fromJson(
|
|
||||||
Map<String, dynamic>.from(value),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (value is! String) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final trimmed = value.trim();
|
|
||||||
if (trimmed.isEmpty) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final decoded = jsonDecode(trimmed);
|
|
||||||
if (decoded is Map<String, dynamic>) {
|
|
||||||
return ShellUpgradeReleaseConfig.fromJson(decoded);
|
|
||||||
}
|
|
||||||
if (decoded is Map) {
|
|
||||||
return ShellUpgradeReleaseConfig.fromJson(
|
|
||||||
Map<String, dynamic>.from(decoded),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('解析 WebShell 升级配置 upgrade 字段异常: $e');
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 远程升级配置模型,对应顶层升级 JSON。
|
|
||||||
class ShellUpgradeConfig {
|
|
||||||
final bool? success;
|
|
||||||
final String? responseCode;
|
|
||||||
final String? msg;
|
|
||||||
final int? id;
|
|
||||||
final int? upgradeFileId;
|
|
||||||
final int? installFileId;
|
|
||||||
final bool? isLatest;
|
|
||||||
final int? appId;
|
|
||||||
final String? releaseCode;
|
|
||||||
final String? releaseTime;
|
|
||||||
final bool? releaseStatus;
|
|
||||||
final String? upgradeOssUrl;
|
|
||||||
final bool? isAllowRollback;
|
|
||||||
final String? rawConfig;
|
|
||||||
final String? configDescribe;
|
|
||||||
final int? describeType;
|
|
||||||
final int? environment;
|
|
||||||
final String? createdTime;
|
|
||||||
final ShellUpgradeReleaseConfig? upgrade;
|
|
||||||
final ShellBootstrapConfig? config;
|
|
||||||
final String? installOssUrl;
|
|
||||||
final String? describe;
|
|
||||||
|
|
||||||
const ShellUpgradeConfig({
|
|
||||||
this.success,
|
|
||||||
this.responseCode,
|
|
||||||
this.msg,
|
|
||||||
this.id,
|
|
||||||
this.upgradeFileId,
|
|
||||||
this.installFileId,
|
|
||||||
this.isLatest,
|
|
||||||
this.appId,
|
|
||||||
this.releaseCode,
|
|
||||||
this.releaseTime,
|
|
||||||
this.releaseStatus,
|
|
||||||
this.upgradeOssUrl,
|
|
||||||
this.isAllowRollback,
|
|
||||||
this.rawConfig,
|
|
||||||
this.configDescribe,
|
|
||||||
this.describe,
|
|
||||||
this.describeType,
|
|
||||||
this.environment,
|
|
||||||
this.createdTime,
|
|
||||||
this.installOssUrl,
|
|
||||||
this.upgrade,
|
|
||||||
this.config,
|
|
||||||
});
|
|
||||||
|
|
||||||
String? get versionName => upgrade?.versionName;
|
|
||||||
|
|
||||||
int? get version => upgrade?.version;
|
|
||||||
|
|
||||||
int? get isForce => upgrade?.isForce;
|
|
||||||
|
|
||||||
String? get remark => describe ?? upgrade?.remark;
|
|
||||||
|
|
||||||
String? get filePath =>
|
|
||||||
_readShellUpgradeString(installOssUrl ?? upgrade?.filePath);
|
|
||||||
|
|
||||||
int? get fileSize => upgrade?.fileSize;
|
|
||||||
|
|
||||||
bool get hasStructuredPayload => upgrade != null || config != null;
|
|
||||||
|
|
||||||
bool shouldOfferUpgrade({required int localVersion}) {
|
|
||||||
final remoteVersion = upgrade?.version;
|
|
||||||
if (remoteVersion == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return remoteVersion > localVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
factory ShellUpgradeConfig.fromJson(Map<String, dynamic> json) {
|
factory ShellUpgradeConfig.fromJson(Map<String, dynamic> json) {
|
||||||
final data = json['data'];
|
|
||||||
final dataMap = data is Map<String, dynamic>
|
|
||||||
? data
|
|
||||||
: data is Map
|
|
||||||
? Map<String, dynamic>.from(data)
|
|
||||||
: const <String, dynamic>{};
|
|
||||||
final rawConfig = _readShellUpgradeString(dataMap['config']);
|
|
||||||
final parsedConfig = _readShellUpgradeEmbeddedConfig(rawConfig);
|
|
||||||
final rawBootstrapConfig = parsedConfig?['config'];
|
|
||||||
final bootstrapConfig = rawBootstrapConfig is Map<String, dynamic>
|
|
||||||
? ShellBootstrapConfig.fromJson(rawBootstrapConfig)
|
|
||||||
: rawBootstrapConfig is Map
|
|
||||||
? ShellBootstrapConfig.fromJson(
|
|
||||||
Map<String, dynamic>.from(rawBootstrapConfig),
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return ShellUpgradeConfig(
|
return ShellUpgradeConfig(
|
||||||
success: _readShellUpgradeBool(json['success']),
|
versionName: json['versionName']?.toString(),
|
||||||
responseCode: _readShellUpgradeString(json['code']),
|
version: json['version'] as int?,
|
||||||
msg: _readShellUpgradeString(json['msg']),
|
isForce: (json['isForce'] ?? json['isforce']) as int?,
|
||||||
id: _readShellUpgradeInt(dataMap['id']),
|
remark: json['remark']?.toString(),
|
||||||
upgradeFileId: _readShellUpgradeInt(dataMap['upgradeFileId']),
|
filePath: json['filePath']?.toString(),
|
||||||
installFileId: _readShellUpgradeInt(dataMap['installFileId']),
|
fileSize: json['fileSize'] as int?,
|
||||||
isLatest: _readShellUpgradeBool(dataMap['isLatest']),
|
|
||||||
appId: _readShellUpgradeInt(dataMap['appId']),
|
|
||||||
releaseCode: _readShellUpgradeString(dataMap['code']),
|
|
||||||
releaseTime: _readShellUpgradeString(dataMap['releaseTime']),
|
|
||||||
releaseStatus: _readShellUpgradeBool(dataMap['releaseStatus']),
|
|
||||||
upgradeOssUrl: _readShellUpgradeString(dataMap['upgradeOssUrl']),
|
|
||||||
installOssUrl: _readShellUpgradeString(dataMap['installOssUrl']),
|
|
||||||
isAllowRollback: _readShellUpgradeBool(dataMap['isAllowRollback']),
|
|
||||||
rawConfig: rawConfig,
|
|
||||||
upgrade: ShellUpgradeReleaseConfig.fromDynamic(parsedConfig?['upgrade']),
|
|
||||||
config: bootstrapConfig,
|
|
||||||
configDescribe: _readShellUpgradeString(dataMap['configDescribe']),
|
|
||||||
describe: _readShellUpgradeString(dataMap['describe']),
|
|
||||||
describeType: _readShellUpgradeInt(dataMap['describeType']),
|
|
||||||
environment: _readShellUpgradeInt(dataMap['environment']),
|
|
||||||
createdTime: _readShellUpgradeString(dataMap['createdTime']),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String? _readShellUpgradeString(dynamic value) {
|
/// 管理壳应用的升级逻辑,依赖 `yx_app_upgrade_flutter`。
|
||||||
final normalized = value?.toString().trim();
|
|
||||||
if (normalized == null || normalized.isEmpty) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return normalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
int? _readShellUpgradeInt(dynamic value) {
|
|
||||||
if (value is int) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
if (value is num) {
|
|
||||||
return value.toInt();
|
|
||||||
}
|
|
||||||
final normalized = value?.toString().trim();
|
|
||||||
if (normalized == null || normalized.isEmpty) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return int.tryParse(normalized);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool? _readShellUpgradeBool(dynamic value) {
|
|
||||||
if (value is bool) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
if (value is num) {
|
|
||||||
return value != 0;
|
|
||||||
}
|
|
||||||
final normalized = value?.toString().trim().toLowerCase();
|
|
||||||
if (normalized == null || normalized.isEmpty) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (normalized == 'true' || normalized == '1') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (normalized == 'false' || normalized == '0') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic>? _readShellUpgradeEmbeddedConfig(String? value) {
|
|
||||||
if (value == null || value.isEmpty) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final decoded = jsonDecode(value);
|
|
||||||
if (decoded is Map<String, dynamic>) {
|
|
||||||
return decoded;
|
|
||||||
}
|
|
||||||
if (decoded is Map) {
|
|
||||||
return Map<String, dynamic>.from(decoded);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('解析 WebShell 升级配置 data.config 异常: $e');
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 管理壳应用的升级逻辑,依赖 yx_app_upgrade_flutter。
|
|
||||||
class ShellUpgradeService {
|
class ShellUpgradeService {
|
||||||
static final ShellUpgradeService instance = ShellUpgradeService._();
|
static final ShellUpgradeService instance = ShellUpgradeService._();
|
||||||
ShellUpgradeService._();
|
ShellUpgradeService._();
|
||||||
|
|
||||||
String? _configUrl;
|
String? _configUrl;
|
||||||
Future<int?> Function()? _localBuildNumberResolver;
|
|
||||||
|
|
||||||
/// 注入升级配置地址。
|
/// 注入升级配置地址。
|
||||||
void setupConfigUrl(String? configUrl) {
|
void setupConfigUrl(String? configUrl) {
|
||||||
|
|
@ -280,8 +63,7 @@ class ShellUpgradeService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeAuxiliaryUtils.instance.initiateVersionCheck(
|
UpgradeAuxiliaryUtils.instance.initiateVersionCheck( // coverage:ignore-line
|
||||||
// coverage:ignore-line
|
|
||||||
context,
|
context,
|
||||||
showNoUpdateToast: showNoUpdateToast,
|
showNoUpdateToast: showNoUpdateToast,
|
||||||
future: _createVersionResolver(remoteConfig), // coverage:ignore-line
|
future: _createVersionResolver(remoteConfig), // coverage:ignore-line
|
||||||
|
|
@ -292,46 +74,10 @@ class ShellUpgradeService {
|
||||||
ShellUpgradeConfig remoteConfig,
|
ShellUpgradeConfig remoteConfig,
|
||||||
) {
|
) {
|
||||||
return (int upType) async {
|
return (int upType) async {
|
||||||
final upgradeVersion = _convertToAppUpgradeVersion(remoteConfig);
|
return _convertToAppUpgradeVersion(remoteConfig);
|
||||||
if (upgradeVersion == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final localBuildNumber = await _resolveLocalBuildNumber();
|
|
||||||
if (localBuildNumber == null) {
|
|
||||||
debugPrint('获取 WebShell 本地版本号失败,回退到升级插件内部版本比较');
|
|
||||||
return upgradeVersion;
|
|
||||||
}
|
|
||||||
if (!remoteConfig.shouldOfferUpgrade(localVersion: localBuildNumber)) {
|
|
||||||
debugPrint(
|
|
||||||
'WebShell 远端版本(${remoteConfig.version}) <= 本地版本($localBuildNumber),跳过升级提示',
|
|
||||||
);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return upgradeVersion;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int?> _resolveLocalBuildNumber() async {
|
|
||||||
final resolver = _localBuildNumberResolver;
|
|
||||||
if (resolver != null) {
|
|
||||||
return resolver();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final appInfo = await AppUpgradePlugin().getAppInfo();
|
|
||||||
return int.tryParse((appInfo['buildNumber'] ?? '').trim());
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('获取 WebShell 本地版本号异常: $e');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@visibleForTesting
|
|
||||||
void debugSetLocalBuildNumberResolver(Future<int?> Function()? resolver) {
|
|
||||||
_localBuildNumberResolver = resolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<ShellUpgradeConfig?> _fetchConfig(String url) async {
|
Future<ShellUpgradeConfig?> _fetchConfig(String url) async {
|
||||||
try {
|
try {
|
||||||
final uri = Uri.tryParse(url);
|
final uri = Uri.tryParse(url);
|
||||||
|
|
@ -356,14 +102,10 @@ class ShellUpgradeService {
|
||||||
try {
|
try {
|
||||||
final dynamic jsonMap = jsonDecode(content);
|
final dynamic jsonMap = jsonDecode(content);
|
||||||
if (jsonMap is Map<String, dynamic>) {
|
if (jsonMap is Map<String, dynamic>) {
|
||||||
final config = ShellUpgradeConfig.fromJson(jsonMap);
|
final data = jsonMap['data'] is Map<String, dynamic>
|
||||||
return config.hasStructuredPayload ? config : null;
|
? jsonMap['data'] as Map<String, dynamic>
|
||||||
}
|
: jsonMap;
|
||||||
if (jsonMap is Map) {
|
return ShellUpgradeConfig.fromJson(data);
|
||||||
final config = ShellUpgradeConfig.fromJson(
|
|
||||||
Map<String, dynamic>.from(jsonMap),
|
|
||||||
);
|
|
||||||
return config.hasStructuredPayload ? config : null;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('解析 WebShell 升级配置异常: $e');
|
debugPrint('解析 WebShell 升级配置异常: $e');
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,6 @@ class ShellCoreTestHooks {
|
||||||
return ShellUpgradeService.instance._createVersionResolver(config)(upType);
|
return ShellUpgradeService.instance._createVersionResolver(config)(upType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 为测试注入本地构建号解析逻辑。
|
|
||||||
void setLocalBuildNumberResolver(Future<int?> Function()? resolver) {
|
|
||||||
ShellUpgradeService.instance.debugSetLocalBuildNumberResolver(resolver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 为测试设置升级配置地址。
|
/// 为测试设置升级配置地址。
|
||||||
void setupUpgradeConfigUrl(String? url) {
|
void setupUpgradeConfigUrl(String? url) {
|
||||||
ShellUpgradeService.instance.setupConfigUrl(url);
|
ShellUpgradeService.instance.setupConfigUrl(url);
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,8 @@ Future<Uri> _startJsonServer(
|
||||||
);
|
);
|
||||||
request.response.write(body);
|
request.response.write(body);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
request.response.statusCode = error is int
|
request.response.statusCode =
|
||||||
? error
|
error is int ? error : HttpStatus.internalServerError;
|
||||||
: HttpStatus.internalServerError;
|
|
||||||
} finally {
|
} finally {
|
||||||
await request.response.close();
|
await request.response.close();
|
||||||
}
|
}
|
||||||
|
|
@ -1255,10 +1254,7 @@ void main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(config, isNotNull);
|
expect(config, isNotNull);
|
||||||
expect(
|
expect(config!.bootstrapConfigUrl, ' https://example.com/bootstrap.json ');
|
||||||
config!.bootstrapConfigUrl,
|
|
||||||
' https://example.com/bootstrap.json ',
|
|
||||||
);
|
|
||||||
expect(config.upgradeConfigUrl, ' https://example.com/upgrade.json ');
|
expect(config.upgradeConfigUrl, ' https://example.com/upgrade.json ');
|
||||||
expect(
|
expect(
|
||||||
config.preferredOrientations,
|
config.preferredOrientations,
|
||||||
|
|
@ -1271,19 +1267,15 @@ void main() {
|
||||||
|
|
||||||
test('启动配置解析支持空数组、非法对象与非法 JSON', () {
|
test('启动配置解析支持空数组、非法对象与非法 JSON', () {
|
||||||
expect(
|
expect(
|
||||||
shellCoreTestHooks
|
shellCoreTestHooks.parseBootstrapConfigString(
|
||||||
.parseBootstrapConfigString(
|
|
||||||
'{"preferredOrientations":[]}',
|
'{"preferredOrientations":[]}',
|
||||||
)!
|
)!.preferredOrientations,
|
||||||
.preferredOrientations,
|
|
||||||
<DeviceOrientation>[],
|
<DeviceOrientation>[],
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
shellCoreTestHooks
|
shellCoreTestHooks.parseBootstrapConfigString(
|
||||||
.parseBootstrapConfigString(
|
|
||||||
'{"preferredOrientations":"portraitUp"}',
|
'{"preferredOrientations":"portraitUp"}',
|
||||||
)!
|
)!.preferredOrientations,
|
||||||
.preferredOrientations,
|
|
||||||
isNull,
|
isNull,
|
||||||
);
|
);
|
||||||
expect(shellCoreTestHooks.parseBootstrapConfigString('['), isNull);
|
expect(shellCoreTestHooks.parseBootstrapConfigString('['), isNull);
|
||||||
|
|
@ -1327,12 +1319,9 @@ void main() {
|
||||||
await unavailableSocket.close();
|
await unavailableSocket.close();
|
||||||
|
|
||||||
final successUri = await _startJsonServer(
|
final successUri = await _startJsonServer(
|
||||||
(_) async =>
|
(_) async => '{"data":{"initialUrl":"https://remote.example.com","upgradeConfigUrl":"https://remote.example.com/upgrade.json"}}',
|
||||||
'{"data":{"initialUrl":"https://remote.example.com","upgradeConfigUrl":"https://remote.example.com/upgrade.json"}}',
|
|
||||||
);
|
|
||||||
final success = await _runWithRealHttpClient(
|
|
||||||
() => shellCoreTestHooks.fetchBootstrapConfig(successUri.toString()),
|
|
||||||
);
|
);
|
||||||
|
final success = await _runWithRealHttpClient(() => shellCoreTestHooks.fetchBootstrapConfig(successUri.toString()));
|
||||||
expect(success?.initialUrl, 'https://remote.example.com');
|
expect(success?.initialUrl, 'https://remote.example.com');
|
||||||
expect(
|
expect(
|
||||||
success?.upgradeConfigUrl,
|
success?.upgradeConfigUrl,
|
||||||
|
|
@ -1352,9 +1341,7 @@ void main() {
|
||||||
expect(invalidUri?.initialUrl, 'https://remote.example.com');
|
expect(invalidUri?.initialUrl, 'https://remote.example.com');
|
||||||
|
|
||||||
final notFoundUri = await _startJsonServer((_) async => throw 404);
|
final notFoundUri = await _startJsonServer((_) async => throw 404);
|
||||||
final notFound = await _runWithRealHttpClient(
|
final notFound = await _runWithRealHttpClient(() => shellCoreTestHooks.fetchBootstrapConfig(notFoundUri.toString()));
|
||||||
() => shellCoreTestHooks.fetchBootstrapConfig(notFoundUri.toString()),
|
|
||||||
);
|
|
||||||
expect(notFound?.initialUrl, 'https://remote.example.com');
|
expect(notFound?.initialUrl, 'https://remote.example.com');
|
||||||
|
|
||||||
final failed = await _runWithRealHttpClient(
|
final failed = await _runWithRealHttpClient(
|
||||||
|
|
@ -1368,9 +1355,7 @@ void main() {
|
||||||
test('读取启动配置缓存异常时返回 null', () async {
|
test('读取启动配置缓存异常时返回 null', () async {
|
||||||
final originalStore = SharedPreferencesStorePlatform.instance;
|
final originalStore = SharedPreferencesStorePlatform.instance;
|
||||||
SharedPreferencesStorePlatform.instance = _ThrowingPreferencesStore();
|
SharedPreferencesStorePlatform.instance = _ThrowingPreferencesStore();
|
||||||
addTearDown(
|
addTearDown(() => SharedPreferencesStorePlatform.instance = originalStore);
|
||||||
() => SharedPreferencesStorePlatform.instance = originalStore,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(await shellCoreTestHooks.loadCachedBootstrapConfig(), isNull);
|
expect(await shellCoreTestHooks.loadCachedBootstrapConfig(), isNull);
|
||||||
});
|
});
|
||||||
|
|
@ -1958,119 +1943,42 @@ void main() {
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('升级配置解析仅支持新版接口响应', () {
|
test('升级配置解析支持 data、平铺、isforce 和非法 JSON', () {
|
||||||
final wrappedContent = jsonEncode({
|
final wrapped = shellCoreTestHooks.parseUpgradeConfigString(
|
||||||
'success': true,
|
'{"data":{"versionName":"1.0.1","version":101,"isforce":1,"remark":"fix","filePath":"https://example.com/app.apk","fileSize":2048}}',
|
||||||
'code': null,
|
|
||||||
'msg': null,
|
|
||||||
'data': {
|
|
||||||
'id': 787171620319301,
|
|
||||||
'upgradeFileId': 0,
|
|
||||||
'installFileId': 787171620307013,
|
|
||||||
'isLatest': true,
|
|
||||||
'appId': 787154824761413,
|
|
||||||
'code': '1.0.1',
|
|
||||||
'releaseTime': '2026-03-24 09:51:23',
|
|
||||||
'releaseStatus': true,
|
|
||||||
'upgradeOssUrl': '',
|
|
||||||
'installOssUrl':
|
|
||||||
'https://umsapi.23544.com/api/biz/Action/download-app?appId=787154824761413&environment=DevelopmentEnvironment&fileType=install&versionCode=1.0.1',
|
|
||||||
'isAllowRollback': true,
|
|
||||||
'config': jsonEncode({
|
|
||||||
'upgrade': {
|
|
||||||
'versionName': '1.0.0',
|
|
||||||
'version': 100,
|
|
||||||
'isForce': 0,
|
|
||||||
'remark': '1. 修复已知问题\n2. 测试升级弹窗功能是否正常加载',
|
|
||||||
'filePath':
|
|
||||||
'https://gitee.com/mr_koi/static_host/raw/master/app-release.apk',
|
|
||||||
'fileSize': 30000,
|
|
||||||
},
|
|
||||||
'config': {
|
|
||||||
'initialUrl': 'http://xszy.lzzneng.com/login.html',
|
|
||||||
'preferredOrientations': ['portraitUp', 'portraitDown'],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
'configDescribe': '',
|
|
||||||
'describe': '首次更新',
|
|
||||||
'describeType': 1,
|
|
||||||
'environment': 1,
|
|
||||||
'createdTime': '2026-03-24 09:49:32.581',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
final structured = shellCoreTestHooks.parseUpgradeConfigString(
|
|
||||||
wrappedContent,
|
|
||||||
);
|
);
|
||||||
|
final flat = shellCoreTestHooks.parseUpgradeConfigString(
|
||||||
expect(structured, isNotNull);
|
|
||||||
expect(structured!.success, isTrue);
|
|
||||||
expect(structured.id, 787171620319301);
|
|
||||||
expect(structured.installFileId, 787171620307013);
|
|
||||||
expect(structured.isLatest, isTrue);
|
|
||||||
expect(structured.appId, 787154824761413);
|
|
||||||
expect(structured.releaseCode, '1.0.1');
|
|
||||||
expect(structured.releaseStatus, isTrue);
|
|
||||||
expect(structured.isAllowRollback, isTrue);
|
|
||||||
expect(structured.describe, '首次更新');
|
|
||||||
expect(structured.describeType, 1);
|
|
||||||
expect(structured.environment, 1);
|
|
||||||
expect(structured.createdTime, '2026-03-24 09:49:32.581');
|
|
||||||
expect(structured.upgrade, isNotNull);
|
|
||||||
expect(structured.versionName, '1.0.0');
|
|
||||||
expect(structured.version, 100);
|
|
||||||
expect(structured.isForce, 0);
|
|
||||||
expect(structured.remark, contains('修复已知问题'));
|
|
||||||
expect(
|
|
||||||
structured.filePath,
|
|
||||||
'https://umsapi.23544.com/api/biz/Action/download-app?appId=787154824761413&environment=DevelopmentEnvironment&fileType=install&versionCode=1.0.1',
|
|
||||||
);
|
|
||||||
expect(structured.fileSize, 30000);
|
|
||||||
expect(structured.config, isNotNull);
|
|
||||||
expect(
|
|
||||||
structured.config?.initialUrl,
|
|
||||||
'http://xszy.lzzneng.com/login.html',
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
structured.config?.preferredOrientations,
|
|
||||||
<DeviceOrientation>[
|
|
||||||
DeviceOrientation.portraitUp,
|
|
||||||
DeviceOrientation.portraitDown,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
shellCoreTestHooks.parseUpgradeConfigString(
|
|
||||||
'{"versionName":"1.0.2","version":102}',
|
'{"versionName":"1.0.2","version":102}',
|
||||||
),
|
|
||||||
isNull,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expect(wrapped, isNotNull);
|
||||||
|
expect(wrapped!.versionName, '1.0.1');
|
||||||
|
expect(wrapped.isForce, 1);
|
||||||
|
expect(flat?.version, 102);
|
||||||
expect(shellCoreTestHooks.parseUpgradeConfigString('{'), isNull);
|
expect(shellCoreTestHooks.parseUpgradeConfigString('{'), isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('升级配置转换为 AppUpgradeVersion 时仅支持顶层 upgrade', () {
|
test('升级配置转换为 AppUpgradeVersion 时处理缺省值', () {
|
||||||
expect(
|
expect(
|
||||||
shellCoreTestHooks.convertUpgradeConfig(const ShellUpgradeConfig()),
|
shellCoreTestHooks.convertUpgradeConfig(
|
||||||
|
ShellUpgradeConfig(versionName: '1.0.0'),
|
||||||
|
),
|
||||||
isNull,
|
isNull,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
shellCoreTestHooks.convertUpgradeConfig(
|
shellCoreTestHooks.convertUpgradeConfig(ShellUpgradeConfig(version: 1)),
|
||||||
const ShellUpgradeConfig(
|
|
||||||
upgrade: ShellUpgradeReleaseConfig(version: 1),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
isNull,
|
isNull,
|
||||||
);
|
);
|
||||||
|
|
||||||
final converted = shellCoreTestHooks.convertUpgradeConfig(
|
final converted = shellCoreTestHooks.convertUpgradeConfig(
|
||||||
const ShellUpgradeConfig(
|
ShellUpgradeConfig(
|
||||||
upgrade: ShellUpgradeReleaseConfig(
|
|
||||||
versionName: '1.2.3',
|
versionName: '1.2.3',
|
||||||
version: 123,
|
version: 123,
|
||||||
isForce: 1,
|
isForce: 1,
|
||||||
remark: 'important update',
|
remark: 'important update',
|
||||||
|
filePath: '',
|
||||||
fileSize: 2048,
|
fileSize: 2048,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(converted, isNotNull);
|
expect(converted, isNotNull);
|
||||||
|
|
@ -2084,74 +1992,29 @@ void main() {
|
||||||
expect(converted.supportedMethods, hasLength(3));
|
expect(converted.supportedMethods, hasLength(3));
|
||||||
|
|
||||||
final convertedWithPath = shellCoreTestHooks.convertUpgradeConfig(
|
final convertedWithPath = shellCoreTestHooks.convertUpgradeConfig(
|
||||||
const ShellUpgradeConfig(
|
ShellUpgradeConfig(
|
||||||
upgrade: ShellUpgradeReleaseConfig(
|
|
||||||
versionName: '2.0.0',
|
versionName: '2.0.0',
|
||||||
version: 200,
|
version: 200,
|
||||||
filePath: 'https://example.com/app.apk',
|
filePath: 'https://example.com/app.apk',
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(convertedWithPath?.downloadUrl, 'https://example.com/app.apk');
|
expect(convertedWithPath?.downloadUrl, 'https://example.com/app.apk');
|
||||||
expect(convertedWithPath?.appStoreUrl, 'https://example.com/app.apk');
|
expect(convertedWithPath?.appStoreUrl, 'https://example.com/app.apk');
|
||||||
|
|
||||||
final convertedFromStructuredConfig = shellCoreTestHooks
|
|
||||||
.convertUpgradeConfig(
|
|
||||||
const ShellUpgradeConfig(
|
|
||||||
upgrade: ShellUpgradeReleaseConfig(
|
|
||||||
versionName: '3.0.0',
|
|
||||||
version: 300,
|
|
||||||
isForce: 0,
|
|
||||||
remark: '1. 修复已知问题\n2. 测试升级弹窗功能是否正常加载',
|
|
||||||
filePath: 'https://download.example.com/app.apk',
|
|
||||||
fileSize: 25000,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(convertedFromStructuredConfig, isNotNull);
|
|
||||||
expect(convertedFromStructuredConfig!.versionName, '3.0.0');
|
|
||||||
expect(convertedFromStructuredConfig.versionBuildNumber, 300);
|
|
||||||
expect(convertedFromStructuredConfig.isForce, isFalse);
|
|
||||||
expect(convertedFromStructuredConfig.updateContent, contains('修复已知问题'));
|
|
||||||
expect(
|
|
||||||
convertedFromStructuredConfig.downloadUrl,
|
|
||||||
'https://download.example.com/app.apk',
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
convertedFromStructuredConfig.appStoreUrl,
|
|
||||||
'https://download.example.com/app.apk',
|
|
||||||
);
|
|
||||||
expect(convertedFromStructuredConfig.apkSize, 25000 * 1024);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('获取升级配置支持成功、非法地址、非 200 和异常', () async {
|
test('获取升级配置支持成功、非法地址、非 200 和异常', () async {
|
||||||
final successUri = await _startJsonServer(
|
final successUri = await _startJsonServer(
|
||||||
(_) async => jsonEncode({
|
(_) async => '{"versionName":"2.0.0","version":200}',
|
||||||
'success': true,
|
|
||||||
'data': {
|
|
||||||
'installOssUrl': 'https://example.com/app.apk',
|
|
||||||
'config': jsonEncode({
|
|
||||||
'upgrade': {
|
|
||||||
'versionName': '2.0.0',
|
|
||||||
'version': 200,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final success = await _runWithRealHttpClient(
|
final success = await _runWithRealHttpClient(() => shellCoreTestHooks.fetchUpgradeConfig(successUri.toString()));
|
||||||
() => shellCoreTestHooks.fetchUpgradeConfig(successUri.toString()),
|
|
||||||
);
|
|
||||||
expect(success?.versionName, '2.0.0');
|
expect(success?.versionName, '2.0.0');
|
||||||
|
|
||||||
expect(await shellCoreTestHooks.fetchUpgradeConfig('%%%'), isNull);
|
expect(await shellCoreTestHooks.fetchUpgradeConfig('%%%'), isNull);
|
||||||
|
|
||||||
final notFoundUri = await _startJsonServer((_) async => throw 404);
|
final notFoundUri = await _startJsonServer((_) async => throw 404);
|
||||||
expect(
|
expect(
|
||||||
await _runWithRealHttpClient(
|
await _runWithRealHttpClient(() => shellCoreTestHooks.fetchUpgradeConfig(notFoundUri.toString())),
|
||||||
() => shellCoreTestHooks.fetchUpgradeConfig(notFoundUri.toString()),
|
|
||||||
),
|
|
||||||
isNull,
|
isNull,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -2174,8 +2037,7 @@ void main() {
|
||||||
|
|
||||||
test('applyBootstrapConfig 会用远程启动配置覆盖本地配置', () async {
|
test('applyBootstrapConfig 会用远程启动配置覆盖本地配置', () async {
|
||||||
final bootstrapUri = await _startJsonServer(
|
final bootstrapUri = await _startJsonServer(
|
||||||
(_) async =>
|
(_) async => '{"data":{"initialUrl":"https://remote.example.com/home","preferredOrientations":["portraitDown"],"upgradeConfigUrl":" https://remote.example.com/upgrade.json "}}',
|
||||||
'{"data":{"initialUrl":"https://remote.example.com/home","preferredOrientations":["portraitDown"],"upgradeConfigUrl":" https://remote.example.com/upgrade.json "}}',
|
|
||||||
);
|
);
|
||||||
shellCoreTestHooks.initializeEnvironment(
|
shellCoreTestHooks.initializeEnvironment(
|
||||||
const ShellEnvironment(
|
const ShellEnvironment(
|
||||||
|
|
@ -2234,7 +2096,8 @@ void main() {
|
||||||
assetContents['assets/config/fallback_bootstrap.json'] = jsonEncode(
|
assetContents['assets/config/fallback_bootstrap.json'] = jsonEncode(
|
||||||
<String, Object?>{
|
<String, Object?>{
|
||||||
'initialUrl': 'https://asset.example.com/start',
|
'initialUrl': 'https://asset.example.com/start',
|
||||||
'bootstrapConfigUrl': 'http://127.0.0.1:$unavailablePort/config.json',
|
'bootstrapConfigUrl':
|
||||||
|
'http://127.0.0.1:$unavailablePort/config.json',
|
||||||
'upgradeConfigUrl': ' https://asset.example.com/upgrade.json ',
|
'upgradeConfigUrl': ' https://asset.example.com/upgrade.json ',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -2271,9 +2134,7 @@ void main() {
|
||||||
splashImage: MemoryImage(Uint8List.fromList(kTransparentImage)),
|
splashImage: MemoryImage(Uint8List.fromList(kTransparentImage)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
addTearDown(
|
addTearDown(() => shellCoreTestHooks.initializeEnvironment(_testEnvironment));
|
||||||
() => shellCoreTestHooks.initializeEnvironment(_testEnvironment),
|
|
||||||
);
|
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
const MaterialApp(
|
const MaterialApp(
|
||||||
|
|
@ -2352,53 +2213,18 @@ void main() {
|
||||||
expect(find.text('长提示'), findsNothing);
|
expect(find.text('长提示'), findsNothing);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('升级配置异步解析闭包按本地版本决定是否返回升级信息', () async {
|
test('升级配置异步解析闭包可返回版本信息', () async {
|
||||||
addTearDown(() => shellCoreTestHooks.setLocalBuildNumberResolver(null));
|
|
||||||
|
|
||||||
shellCoreTestHooks.setLocalBuildNumberResolver(() async => 200);
|
|
||||||
final version = await shellCoreTestHooks.resolveUpgradeConfig(
|
final version = await shellCoreTestHooks.resolveUpgradeConfig(
|
||||||
const ShellUpgradeConfig(
|
ShellUpgradeConfig(
|
||||||
upgrade: ShellUpgradeReleaseConfig(
|
|
||||||
versionName: '3.0.0',
|
versionName: '3.0.0',
|
||||||
version: 300,
|
version: 300,
|
||||||
filePath: 'https://example.com/app.apk',
|
filePath: 'https://example.com/app.apk',
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(version?.versionName, '3.0.0');
|
expect(version?.versionName, '3.0.0');
|
||||||
expect(version?.versionBuildNumber, 300);
|
expect(version?.versionBuildNumber, 300);
|
||||||
expect(version?.downloadUrl, 'https://example.com/app.apk');
|
expect(version?.downloadUrl, 'https://example.com/app.apk');
|
||||||
|
|
||||||
shellCoreTestHooks.setLocalBuildNumberResolver(() async => 300);
|
|
||||||
final sameVersion = await shellCoreTestHooks.resolveUpgradeConfig(
|
|
||||||
const ShellUpgradeConfig(
|
|
||||||
upgrade: ShellUpgradeReleaseConfig(
|
|
||||||
versionName: '3.0.0',
|
|
||||||
version: 300,
|
|
||||||
filePath: 'https://example.com/app.apk',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(sameVersion, isNull);
|
|
||||||
|
|
||||||
shellCoreTestHooks.setLocalBuildNumberResolver(() async => null);
|
|
||||||
final fallbackVersion = await shellCoreTestHooks.resolveUpgradeConfig(
|
|
||||||
const ShellUpgradeConfig(
|
|
||||||
upgrade: ShellUpgradeReleaseConfig(
|
|
||||||
versionName: '3.0.0',
|
|
||||||
version: 300,
|
|
||||||
filePath: 'https://example.com/app.apk',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(fallbackVersion?.versionName, '3.0.0');
|
|
||||||
expect(fallbackVersion?.versionBuildNumber, 300);
|
|
||||||
|
|
||||||
final hiddenVersion = await shellCoreTestHooks.resolveUpgradeConfig(
|
|
||||||
const ShellUpgradeConfig(),
|
|
||||||
);
|
|
||||||
expect(hiddenVersion, isNull);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue