feat: match info

opt dateformat

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-06-15 20:12:57 +08:00
parent 25f4ed6636
commit a2c24fb33c
108 changed files with 1703 additions and 877 deletions

132
lib/utils/update.dart Normal file
View File

@@ -0,0 +1,132 @@
import 'dart:io' show Platform;
import 'package:PiliPlus/build_config.dart';
import 'package:PiliPlus/http/api.dart';
import 'package:PiliPlus/http/init.dart';
import 'package:PiliPlus/utils/page_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart' show kDebugMode;
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
class Update {
// 检查更新
static Future<void> checkUpdate([bool isAuto = true]) async {
if (kDebugMode) return;
SmartDialog.dismiss();
try {
final res = await Request().get(Api.latestApp, uaType: 'mob');
if (res.data is Map || res.data.isEmpty) {
if (!isAuto) {
SmartDialog.showToast('检查更新失败GitHub接口未返回数据请检查网络');
}
return;
}
DateTime latest = DateTime.parse(res.data[0]['created_at']);
DateTime current = DateTime.parse('${BuildConfig.buildTime}Z');
current = current.copyWith(hour: current.hour - 8);
if (current.compareTo(latest) >= 0) {
if (!isAuto) {
SmartDialog.showToast('已是最新版本');
}
} else {
SmartDialog.show(
animationType: SmartAnimationType.centerFade_otherSlide,
builder: (context) {
final ThemeData theme = Theme.of(context);
return AlertDialog(
title: const Text('🎉 发现新版本 '),
content: SizedBox(
height: 280,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${res.data[0]['tag_name']}',
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 8),
Text('${res.data[0]['body']}'),
TextButton(
onPressed: () => PageUtils.launchURL(
'https://github.com/bggRGjQaUbCoE/PiliPlus/commits/main'),
child: Text(
"点此查看完整更新(即commit)内容",
style: TextStyle(
color: theme.colorScheme.primary,
),
),
),
],
),
),
),
actions: [
TextButton(
onPressed: () {
SmartDialog.dismiss();
GStorage.setting.put(SettingBoxKey.autoUpdate, false);
},
child: Text(
'不再提醒',
style: TextStyle(
color: theme.colorScheme.outline,
),
),
),
TextButton(
onPressed: SmartDialog.dismiss,
child: Text(
'取消',
style: TextStyle(
color: theme.colorScheme.outline,
),
),
),
TextButton(
onPressed: () => onDownload(res.data[0]),
child: const Text('Github'),
),
],
);
},
);
}
} catch (e) {
if (kDebugMode) debugPrint('failed to check update: $e');
}
}
// 下载适用于当前系统的安装包
static Future<void> onDownload(data) async {
SmartDialog.dismiss();
try {
void download(plat) {
if (data['assets'].isNotEmpty) {
for (dynamic i in data['assets']) {
if (i['name'].contains(plat)) {
PageUtils.launchURL(i['browser_download_url']);
break;
}
}
}
}
if (Platform.isAndroid) {
// 获取设备信息
AndroidDeviceInfo androidInfo = await DeviceInfoPlugin().androidInfo;
// [arm64-v8a]
download(androidInfo.supportedAbis.first);
} else {
download('ios');
}
} catch (_) {
PageUtils.launchURL(
'https://github.com/bggRGjQaUbCoE/PiliPlus/releases/latest');
}
}
}