Commit 75b573e5 by tanghuan

H5的实际打包版本,调整为从package.json中读取和解析

1 parent 78b40772
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:appframe/config/constant.dart'; import 'package:appframe/config/constant.dart';
...@@ -162,8 +163,11 @@ class LocalServerService { ...@@ -162,8 +163,11 @@ class LocalServerService {
var version = getIt.get<SharedPreferences>().getString(Constant.h5VersionKey) ?? Constant.h5Version; var version = getIt.get<SharedPreferences>().getString(Constant.h5VersionKey) ?? Constant.h5Version;
var dir = await getApplicationSupportDirectory(); var dir = await getApplicationSupportDirectory();
var distFilePath = '${dir.path}/${Constant.h5DistDir}/$version.zip'; var distFilePath = '${dir.path}/${Constant.h5DistDir}/$version.zip';
if (!File(distFilePath).existsSync()) { if (!await File(distFilePath).exists()) {
distFilePath = 'assets/dist.zip'; distFilePath = 'assets/$version.zip';
if (!await File(distFilePath).exists()) {
distFilePath = 'assets/dist.zip';
}
} }
// 解压 // 解压
await ZipUtil.extractZipFile(distFilePath, outputDirectory); await ZipUtil.extractZipFile(distFilePath, outputDirectory);
...@@ -173,10 +177,11 @@ class LocalServerService { ...@@ -173,10 +177,11 @@ class LocalServerService {
// 读取和设置用于显示的版本号 // 读取和设置用于显示的版本号
Future<void> _getAndSetShowVersion(String outputDirectory) async { Future<void> _getAndSetShowVersion(String outputDirectory) async {
var versionFile = File('$outputDirectory/version.txt'); var versionFile = File('$outputDirectory/package.json');
if (await versionFile.exists()) { if (await versionFile.exists()) {
var content = (await versionFile.readAsString()).trim(); var content = (await versionFile.readAsString()).trim();
getIt.get<SharedPreferences>().setString(Constant.h5ShowVersionKey, content); var json = jsonDecode(content);
getIt.get<SharedPreferences>().setString(Constant.h5ShowVersionKey, json['version'] ?? 'undefined');
} else { } else {
getIt.get<SharedPreferences>().setString(Constant.h5ShowVersionKey, 'undefined'); getIt.get<SharedPreferences>().setString(Constant.h5ShowVersionKey, 'undefined');
} }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!