Files
EasyDesignCollection/tool/check_update.dart
T

34 lines
1.5 KiB
Dart
Raw Permalink Normal View History

// 开发自检工具:直接调用应用内更新服务,检查服务器上的最新版本。
//
// 用途:验证更新链路(网络可达 / 接口解析 / 版本判定 / 附件匹配)。
// 运行:
// dart run tool\check_update.dart # 用当前版本检查
// dart run tool\check_update.dart 1.2.1 # 模拟旧版本,验证「发现更新」路径
//
// 说明:使用的是与客户端完全相同的 lib/update/update_service.dart;
// 本文件是命令行工具,直接向控制台打印结果属预期用法。
//
// ignore_for_file: avoid_print
import 'package:sequence_diagram/update/update_service.dart';
import 'package:sequence_diagram/version.dart';
Future<void> main(List<String> args) async {
// 可传入一个版本号模拟旧安装(如 `dart run tool\check_update.dart 1.2.1`)。
final String current = args.isNotEmpty ? args.first : kAppVersion;
print('当前版本(模拟): $current');
try {
final UpdateInfo? info = await UpdateService.check(currentVersion: current);
if (info == null) {
print('结果: 已是最新版本(服务器无更高版本或缺少当前平台的安装包)');
return;
}
print('结果: 发现新版本 v${info.version}');
print('安装包: ${info.assetName} ${(info.assetSize / 1048576).toStringAsFixed(1)} MB');
print('下载地址: ${info.assetUrl}');
print('---- 更新说明 ----');
print(info.notes.trim());
} catch (e) {
print('检查失败: $e');
}
}