Commit bd06b441 by tanghuan

1.APP唤醒时,检测H5版本;2. AppInfo指令的版本信息

1 parent f6cdbe0f
......@@ -1132,6 +1132,42 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
///
bool _hasBeenResumed = false;
/// 版本检测并发控制标志
bool _isCheckingVersionOfH5 = false;
/// H5资源已下载标志(本次生命周期内)
bool _hasDownloadedH5 = false;
///
/// 从后台恢复时进行版本检测
/// 参照 _init() 方法中的版本检测逻辑
/// 检测或下载中时不重复处理
///
Future<void> _checkVersionUpgrade() async {
if (_isCheckingVersionOfH5 || _hasDownloadedH5) {
return;
}
_isCheckingVersionOfH5 = true;
try {
var curVersion = getIt.get<SharedPreferences>().getString(Constant.h5VersionKey) ?? Constant.h5Version;
var versionConfig = await _getVersionConfig();
var configVersion = versionConfig['version'] as String;
var downloadUrl = versionConfig['zip'] as String;
if (Constant.needUpgrade && curVersion != configVersion) {
await _downloadH5Zip(configVersion, downloadUrl);
_setH5Version(configVersion);
_hasDownloadedH5 = true;
emit(state.copyWith(suggestUpgrade: true));
}
} catch (e) {
debugPrint('后台H5版本检测失败 $e');
} finally {
_isCheckingVersionOfH5 = false;
}
}
@override
Future<void> didChangeAppLifecycleState(AppLifecycleState lifecycleState) async {
// 只针对iOS进行处理
......@@ -1150,25 +1186,30 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
}
}
// switch (state) {
if (lifecycleState == AppLifecycleState.resumed) {
// 代表从后台恢复,进行版本检测
_checkVersionUpgrade();
}
// switch (lifecycleState) {
// case AppLifecycleState.resumed:
// // 应用从后台回到前台时触发
// print('resumed--------------');
// debugPrint('======> lifecycleState resumed--------------');
// break;
// case AppLifecycleState.paused:
// // 应用进入后台时触发
// print('paused--------------');
// debugPrint('======> lifecycleState paused--------------');
// break;
// case AppLifecycleState.inactive:
// // 应用处于非活跃状态时触发
// print('inactive--------------');
// debugPrint('======> lifecycleState inactive--------------');
// break;
// case AppLifecycleState.detached:
// // 应用即将退出时触发
// print('detached--------------');
// debugPrint('======> lifecycleState detached--------------');
// break;
// case AppLifecycleState.hidden:
// print('hidden--------------');
// debugPrint('======> lifecycleState hidden--------------');
// break;
// }
}
......
......@@ -116,6 +116,6 @@ class Constant {
static const String hasShownPrivacyFirstTimeKey = 'has_shown_privacy_first_time';
/// 测试阶段使用
static const bool needIM = true;
static const bool needIM = false;
static const bool needUpgrade = true;
}
import 'package:appframe/config/constant.dart';
import 'package:appframe/services/dispatcher.dart';
class AppInfoHandler extends MessageHandler {
@override
Future<Map<String, dynamic>> handleMessage(params) async {
return {"version": "0.1", "theme": "light"};
return {
"version": Constant.appVersion,
"theme": "light",
"appshop": '',
};
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!