mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: add check update
Closes #112 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -83,11 +83,15 @@ class _AboutPageState extends State<AboutPage> {
|
||||
),
|
||||
Obx(
|
||||
() => ListTile(
|
||||
// onTap: () => _aboutController.tapOnVersion(),
|
||||
onTap: Utils.checkUpdate,
|
||||
onLongPress: () =>
|
||||
Utils.copyText(_aboutController.currentVersion.value),
|
||||
title: const Text('当前版本'),
|
||||
leading: const Icon(Icons.commit_outlined),
|
||||
trailing: Text(_aboutController.currentVersion.value,
|
||||
style: subTitleStyle),
|
||||
trailing: Text(
|
||||
_aboutController.currentVersion.value,
|
||||
style: subTitleStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
@@ -100,6 +104,7 @@ Commit Hash: ${BuildConfig.commitHash}''',
|
||||
leading: const Icon(Icons.info_outline),
|
||||
onTap: () => Utils.launchURL(
|
||||
'https://github.com/bggRGjQaUbCoE/PiliPlus/commit/${BuildConfig.commitHash}'),
|
||||
onLongPress: () => Utils.copyText(BuildConfig.commitHash),
|
||||
),
|
||||
// Obx(
|
||||
// () => ListTile(
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:PiliPlus/pages/home/view.dart';
|
||||
import 'package:PiliPlus/pages/media/view.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
@@ -41,6 +42,9 @@ class MainController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (GStorage.autoUpdate) {
|
||||
Utils.checkUpdate();
|
||||
}
|
||||
hideTabBar =
|
||||
GStorage.setting.get(SettingBoxKey.hideTabBar, defaultValue: true);
|
||||
isLogin.value = GStorage.isLogin;
|
||||
|
||||
@@ -29,6 +29,7 @@ import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/recommend_filter.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:auto_orientation/auto_orientation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -1886,4 +1887,17 @@ List<SettingsModel> get extraSettings => [
|
||||
setKey: SettingBoxKey.autoClearCache,
|
||||
defaultVal: false,
|
||||
),
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.sw1tch,
|
||||
title: '检查更新',
|
||||
subtitle: '每次启动时检查是否需要更新',
|
||||
leading: const Icon(Icons.system_update_alt_outlined),
|
||||
setKey: SettingBoxKey.autoUpdate,
|
||||
defaultVal: true,
|
||||
onChanged: (val) {
|
||||
if (val) {
|
||||
Utils.checkUpdate();
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
@@ -84,9 +84,6 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
|
||||
val = value ?? !val;
|
||||
|
||||
await GStorage.setting.put(widget.setKey, val);
|
||||
// if (widget.setKey == SettingBoxKey.autoUpdate && value == true) {
|
||||
// Utils.checkUpdate();
|
||||
// }
|
||||
widget.onChanged?.call(val);
|
||||
if (widget.needReboot == true) {
|
||||
SmartDialog.showToast('重启生效');
|
||||
|
||||
@@ -301,6 +301,9 @@ class GStorage {
|
||||
static bool get cdnSpeedTest =>
|
||||
setting.get(SettingBoxKey.cdnSpeedTest, defaultValue: true);
|
||||
|
||||
static bool get autoUpdate =>
|
||||
GStorage.setting.get(SettingBoxKey.autoUpdate, defaultValue: true);
|
||||
|
||||
static List<double> get dynamicDetailRatio => List<double>.from(setting
|
||||
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
|
||||
|
||||
@@ -475,7 +478,7 @@ class SettingBoxKey {
|
||||
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',
|
||||
|
||||
/// 其他
|
||||
// autoUpdate = 'autoUpdate',
|
||||
autoUpdate = 'autoUpdate',
|
||||
autoClearCache = 'autoClearCache',
|
||||
defaultShowComment = 'defaultShowComment',
|
||||
replySortType = 'replySortType',
|
||||
|
||||
@@ -2,7 +2,9 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:PiliPlus/build_config.dart';
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/api.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/http/member.dart';
|
||||
@@ -18,6 +20,7 @@ import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/login.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -789,120 +792,119 @@ class Utils {
|
||||
};
|
||||
}
|
||||
|
||||
// 版本对比
|
||||
// static bool needUpdate(localVersion, remoteVersion) {
|
||||
// return localVersion != remoteVersion;
|
||||
// }
|
||||
|
||||
// 检查更新
|
||||
// static Future<bool> checkUpdate() async {
|
||||
// SmartDialog.dismiss();
|
||||
// var currentInfo = await PackageInfo.fromPlatform();
|
||||
// var result = await Request().get(Api.latestApp, extra: {'ua': 'mob'});
|
||||
// if (result.data.isEmpty) {
|
||||
// SmartDialog.showToast('检查更新失败,github接口未返回数据,请检查网络');
|
||||
// return false;
|
||||
// }
|
||||
// LatestDataModel data = LatestDataModel.fromJson(result.data[0]);
|
||||
// String buildNumber = currentInfo.buildNumber;
|
||||
// String remoteVersion = data.tagName!;
|
||||
// if (Platform.isAndroid) {
|
||||
// buildNumber = buildNumber.substring(0, buildNumber.length - 1);
|
||||
// } else if (Platform.isIOS) {
|
||||
// remoteVersion = remoteVersion.replaceAll('-beta', '');
|
||||
// }
|
||||
// bool isUpdate =
|
||||
// Utils.needUpdate("${currentInfo.version}+$buildNumber", remoteVersion);
|
||||
// if (isUpdate) {
|
||||
// SmartDialog.show(
|
||||
// animationType: SmartAnimationType.centerFade_otherSlide,
|
||||
// builder: (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(
|
||||
// data.tagName!,
|
||||
// style: const TextStyle(fontSize: 20),
|
||||
// ),
|
||||
// const SizedBox(height: 8),
|
||||
// Text(data.body!),
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// launchUrl(
|
||||
// Uri.parse(
|
||||
// "https://github.com/bggRGjQaUbCoE/PiliPlus/commits/main/"),
|
||||
// mode: LaunchMode.externalApplication,
|
||||
// );
|
||||
// },
|
||||
// child: Text(
|
||||
// "点此查看完整更新(即commit)内容",
|
||||
// style: TextStyle(
|
||||
// color: Theme.of(context).colorScheme.primary),
|
||||
// )),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// actions: [
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// GStorage.setting.put(SettingBoxKey.autoUpdate, false);
|
||||
// SmartDialog.dismiss();
|
||||
// },
|
||||
// child: Text(
|
||||
// '不再提醒',
|
||||
// style:
|
||||
// TextStyle(color: Theme.of(context).colorScheme.outline),
|
||||
// ),
|
||||
// ),
|
||||
// TextButton(
|
||||
// onPressed: () => SmartDialog.dismiss(),
|
||||
// child: Text(
|
||||
// '取消',
|
||||
// style:
|
||||
// TextStyle(color: Theme.of(context).colorScheme.outline),
|
||||
// ),
|
||||
// ),
|
||||
// TextButton(
|
||||
// onPressed: () => matchVersion(data),
|
||||
// child: const Text('Github'),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
static Future checkUpdate() async {
|
||||
SmartDialog.dismiss();
|
||||
try {
|
||||
dynamic res = await Request().get(Api.latestApp, extra: {'ua': 'mob'});
|
||||
if (res.data.isEmpty) {
|
||||
SmartDialog.showToast('检查更新失败,GitHub接口未返回数据,请检查网络');
|
||||
return;
|
||||
}
|
||||
DateTime latest = DateTime.parse(res.data[0]['created_at']);
|
||||
latest = latest.copyWith(hour: latest.hour + 8);
|
||||
DateTime current = DateTime.parse(BuildConfig.buildTime);
|
||||
if (current.compareTo(latest) < 0) {
|
||||
SmartDialog.show(
|
||||
animationType: SmartAnimationType.centerFade_otherSlide,
|
||||
builder: (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: () {
|
||||
launchURL(
|
||||
'https://github.com/bggRGjQaUbCoE/PiliPlus/commits/main');
|
||||
},
|
||||
child: Text(
|
||||
"点此查看完整更新(即commit)内容",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
SmartDialog.dismiss();
|
||||
GStorage.setting.put(SettingBoxKey.autoUpdate, false);
|
||||
},
|
||||
child: Text(
|
||||
'不再提醒',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: SmartDialog.dismiss,
|
||||
child: Text(
|
||||
'取消',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
onDownload(res.data[0]);
|
||||
},
|
||||
child: const Text('Github'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('failed to check update: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 下载适用于当前系统的安装包
|
||||
// static Future matchVersion(data) async {
|
||||
// await SmartDialog.dismiss();
|
||||
// // 获取设备信息
|
||||
// DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
// if (Platform.isAndroid) {
|
||||
// AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
// // [arm64-v8a]
|
||||
// String abi = androidInfo.supportedAbis.first;
|
||||
// late String downloadUrl;
|
||||
// if (data.assets.isNotEmpty) {
|
||||
// for (var i in data.assets) {
|
||||
// if (i.downloadUrl.contains(abi)) {
|
||||
// downloadUrl = i.downloadUrl;
|
||||
// }
|
||||
// }
|
||||
// // 应用外下载
|
||||
// launchURL(downloadUrl);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
static Future onDownload(data) async {
|
||||
await SmartDialog.dismiss();
|
||||
try {
|
||||
void download(plat) {
|
||||
if (data['assets'].isNotEmpty) {
|
||||
for (dynamic i in data['assets']) {
|
||||
if (i['name'].contains(plat)) {
|
||||
launchURL(i['browser_download_url']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
// 获取设备信息
|
||||
AndroidDeviceInfo androidInfo = await DeviceInfoPlugin().androidInfo;
|
||||
// [arm64-v8a]
|
||||
download(androidInfo.supportedAbis.first);
|
||||
} else {
|
||||
download('ios');
|
||||
}
|
||||
} catch (_) {
|
||||
launchURL('https://github.com/bggRGjQaUbCoE/PiliPlus/releases/latest');
|
||||
}
|
||||
}
|
||||
|
||||
// 时间戳转时间
|
||||
static tampToSeektime(number) {
|
||||
|
||||
Reference in New Issue
Block a user