Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit bd06b441
authored
2026-04-28 15:10:58 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.APP唤醒时,检测H5版本;2. AppInfo指令的版本信息
1 parent
f6cdbe0f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
8 deletions
lib/bloc/web_cubit.dart
lib/config/constant.dart
lib/data/repositories/message/app_info_handler.dart
lib/bloc/web_cubit.dart
View file @
bd06b44
...
@@ -1132,6 +1132,42 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
...
@@ -1132,6 +1132,42 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
///
///
bool
_hasBeenResumed
=
false
;
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
@override
Future
<
void
>
didChangeAppLifecycleState
(
AppLifecycleState
lifecycleState
)
async
{
Future
<
void
>
didChangeAppLifecycleState
(
AppLifecycleState
lifecycleState
)
async
{
// 只针对iOS进行处理
// 只针对iOS进行处理
...
@@ -1150,25 +1186,30 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
...
@@ -1150,25 +1186,30 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
}
}
}
}
// switch (state) {
if
(
lifecycleState
==
AppLifecycleState
.
resumed
)
{
// 代表从后台恢复,进行版本检测
_checkVersionUpgrade
();
}
// switch (lifecycleState) {
// case AppLifecycleState.resumed:
// case AppLifecycleState.resumed:
// // 应用从后台回到前台时触发
// // 应用从后台回到前台时触发
//
print('
resumed--------------');
//
debugPrint('======> lifecycleState
resumed--------------');
// break;
// break;
// case AppLifecycleState.paused:
// case AppLifecycleState.paused:
// // 应用进入后台时触发
// // 应用进入后台时触发
//
print('
paused--------------');
//
debugPrint('======> lifecycleState
paused--------------');
// break;
// break;
// case AppLifecycleState.inactive:
// case AppLifecycleState.inactive:
// // 应用处于非活跃状态时触发
// // 应用处于非活跃状态时触发
//
print('
inactive--------------');
//
debugPrint('======> lifecycleState
inactive--------------');
// break;
// break;
// case AppLifecycleState.detached:
// case AppLifecycleState.detached:
// // 应用即将退出时触发
// // 应用即将退出时触发
//
print('
detached--------------');
//
debugPrint('======> lifecycleState
detached--------------');
// break;
// break;
// case AppLifecycleState.hidden:
// case AppLifecycleState.hidden:
//
print('
hidden--------------');
//
debugPrint('======> lifecycleState
hidden--------------');
// break;
// break;
// }
// }
}
}
...
...
lib/config/constant.dart
View file @
bd06b44
...
@@ -116,6 +116,6 @@ class Constant {
...
@@ -116,6 +116,6 @@ class Constant {
static
const
String
hasShownPrivacyFirstTimeKey
=
'has_shown_privacy_first_time'
;
static
const
String
hasShownPrivacyFirstTimeKey
=
'has_shown_privacy_first_time'
;
/// 测试阶段使用
/// 测试阶段使用
static
const
bool
needIM
=
tru
e
;
static
const
bool
needIM
=
fals
e
;
static
const
bool
needUpgrade
=
true
;
static
const
bool
needUpgrade
=
true
;
}
}
lib/data/repositories/message/app_info_handler.dart
View file @
bd06b44
import
'package:appframe/config/constant.dart'
;
import
'package:appframe/services/dispatcher.dart'
;
import
'package:appframe/services/dispatcher.dart'
;
class
AppInfoHandler
extends
MessageHandler
{
class
AppInfoHandler
extends
MessageHandler
{
@override
@override
Future
<
Map
<
String
,
dynamic
>>
handleMessage
(
params
)
async
{
Future
<
Map
<
String
,
dynamic
>>
handleMessage
(
params
)
async
{
return
{
"version"
:
"0.1"
,
"theme"
:
"light"
};
return
{
"version"
:
Constant
.
appVersion
,
"theme"
:
"light"
,
"appshop"
:
''
,
};
}
}
}
}
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment