Commit a368b258 by tanghuan

清理缓存的时候,增加清理WebView的localStorage和cache

1 parent 63830387
...@@ -244,14 +244,14 @@ class WebCubit extends Cubit<WebState> { ...@@ -244,14 +244,14 @@ class WebCubit extends Cubit<WebState> {
// 读取 h5 版本号 // 读取 h5 版本号
_readH5ShowVersion(); _readH5ShowVersion();
// 登录IM
_loginIM();
// 初始化其它一些属性 // 初始化其它一些属性
_fluwx = getIt.get<Fluwx>(); _fluwx = getIt.get<Fluwx>();
_playerService = getIt.get<PlayerService>(); _playerService = getIt.get<PlayerService>();
_playerService?.sendResponse = _sendResponse; _playerService?.sendResponse = _sendResponse;
_recorderService = getIt.get<RecorderService>(); _recorderService = getIt.get<RecorderService>();
// 登录IM
_loginIM();
} }
Future<Map<String, String>> _getVersionConfig() async { Future<Map<String, String>> _getVersionConfig() async {
...@@ -305,7 +305,6 @@ class WebCubit extends Cubit<WebState> { ...@@ -305,7 +305,6 @@ class WebCubit extends Cubit<WebState> {
await tempZipFile.copy(saveZipFilePath); await tempZipFile.copy(saveZipFilePath);
// 删除临时文件 // 删除临时文件
await tempZipFile.delete(); await tempZipFile.delete();
} finally { } finally {
dio.close(force: true); dio.close(force: true);
} }
...@@ -487,7 +486,11 @@ class WebCubit extends Cubit<WebState> { ...@@ -487,7 +486,11 @@ class WebCubit extends Cubit<WebState> {
} }
Future<void> clearStorage() async { Future<void> clearStorage() async {
// 1 清理非 h5_version 的缓存 // 1 清理 localStorage
_controller.clearLocalStorage();
_controller.clearCache();
// 2 清理非 h5_version 的缓存
var sharedPreferences = getIt.get<SharedPreferences>(); var sharedPreferences = getIt.get<SharedPreferences>();
sharedPreferences.getKeys().forEach((key) async { sharedPreferences.getKeys().forEach((key) async {
if (!key.startsWith('h5')) { if (!key.startsWith('h5')) {
...@@ -495,7 +498,7 @@ class WebCubit extends Cubit<WebState> { ...@@ -495,7 +498,7 @@ class WebCubit extends Cubit<WebState> {
} }
}); });
// 2 清理 http_dist_assets 下的非当前版本号的文件和目录 // 3 清理 http_dist_assets 下的非当前版本号的文件和目录
var dir = await getApplicationSupportDirectory(); var dir = await getApplicationSupportDirectory();
var httpDir = Directory('${dir.path}/${Constant.h5DistDir}'); var httpDir = Directory('${dir.path}/${Constant.h5DistDir}');
if (httpDir.existsSync()) { if (httpDir.existsSync()) {
...@@ -516,7 +519,7 @@ class WebCubit extends Cubit<WebState> { ...@@ -516,7 +519,7 @@ class WebCubit extends Cubit<WebState> {
} }
} }
// 3 清理临时目录下的所有文件和目录 // 4 清理临时目录下的所有文件和目录
var tempDir = await getTemporaryDirectory(); var tempDir = await getTemporaryDirectory();
if (tempDir.existsSync()) { if (tempDir.existsSync()) {
await for (final FileSystemEntity entity in tempDir.list()) { await for (final FileSystemEntity entity in tempDir.list()) {
...@@ -539,7 +542,7 @@ class WebCubit extends Cubit<WebState> { ...@@ -539,7 +542,7 @@ class WebCubit extends Cubit<WebState> {
}); });
// IM 登出 // IM 登出
await getIt.get<ImService>().logout(); // await getIt.get<ImService>().logout();
goLogin(); goLogin();
} }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!