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(
|
Obx(
|
||||||
() => ListTile(
|
() => ListTile(
|
||||||
// onTap: () => _aboutController.tapOnVersion(),
|
onTap: Utils.checkUpdate,
|
||||||
|
onLongPress: () =>
|
||||||
|
Utils.copyText(_aboutController.currentVersion.value),
|
||||||
title: const Text('当前版本'),
|
title: const Text('当前版本'),
|
||||||
leading: const Icon(Icons.commit_outlined),
|
leading: const Icon(Icons.commit_outlined),
|
||||||
trailing: Text(_aboutController.currentVersion.value,
|
trailing: Text(
|
||||||
style: subTitleStyle),
|
_aboutController.currentVersion.value,
|
||||||
|
style: subTitleStyle,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
@@ -100,6 +104,7 @@ Commit Hash: ${BuildConfig.commitHash}''',
|
|||||||
leading: const Icon(Icons.info_outline),
|
leading: const Icon(Icons.info_outline),
|
||||||
onTap: () => Utils.launchURL(
|
onTap: () => Utils.launchURL(
|
||||||
'https://github.com/bggRGjQaUbCoE/PiliPlus/commit/${BuildConfig.commitHash}'),
|
'https://github.com/bggRGjQaUbCoE/PiliPlus/commit/${BuildConfig.commitHash}'),
|
||||||
|
onLongPress: () => Utils.copyText(BuildConfig.commitHash),
|
||||||
),
|
),
|
||||||
// Obx(
|
// Obx(
|
||||||
// () => ListTile(
|
// () => ListTile(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import 'package:PiliPlus/pages/home/view.dart';
|
|||||||
import 'package:PiliPlus/pages/media/view.dart';
|
import 'package:PiliPlus/pages/media/view.dart';
|
||||||
import 'package:PiliPlus/utils/extension.dart';
|
import 'package:PiliPlus/utils/extension.dart';
|
||||||
import 'package:PiliPlus/utils/global_data.dart';
|
import 'package:PiliPlus/utils/global_data.dart';
|
||||||
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
@@ -41,6 +42,9 @@ class MainController extends GetxController {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
if (GStorage.autoUpdate) {
|
||||||
|
Utils.checkUpdate();
|
||||||
|
}
|
||||||
hideTabBar =
|
hideTabBar =
|
||||||
GStorage.setting.get(SettingBoxKey.hideTabBar, defaultValue: true);
|
GStorage.setting.get(SettingBoxKey.hideTabBar, defaultValue: true);
|
||||||
isLogin.value = GStorage.isLogin;
|
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/global_data.dart';
|
||||||
import 'package:PiliPlus/utils/recommend_filter.dart';
|
import 'package:PiliPlus/utils/recommend_filter.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:auto_orientation/auto_orientation.dart';
|
import 'package:auto_orientation/auto_orientation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -1886,4 +1887,17 @@ List<SettingsModel> get extraSettings => [
|
|||||||
setKey: SettingBoxKey.autoClearCache,
|
setKey: SettingBoxKey.autoClearCache,
|
||||||
defaultVal: false,
|
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;
|
val = value ?? !val;
|
||||||
|
|
||||||
await GStorage.setting.put(widget.setKey, val);
|
await GStorage.setting.put(widget.setKey, val);
|
||||||
// if (widget.setKey == SettingBoxKey.autoUpdate && value == true) {
|
|
||||||
// Utils.checkUpdate();
|
|
||||||
// }
|
|
||||||
widget.onChanged?.call(val);
|
widget.onChanged?.call(val);
|
||||||
if (widget.needReboot == true) {
|
if (widget.needReboot == true) {
|
||||||
SmartDialog.showToast('重启生效');
|
SmartDialog.showToast('重启生效');
|
||||||
|
|||||||
@@ -301,6 +301,9 @@ class GStorage {
|
|||||||
static bool get cdnSpeedTest =>
|
static bool get cdnSpeedTest =>
|
||||||
setting.get(SettingBoxKey.cdnSpeedTest, defaultValue: true);
|
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
|
static List<double> get dynamicDetailRatio => List<double>.from(setting
|
||||||
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
|
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
|
||||||
|
|
||||||
@@ -475,7 +478,7 @@ class SettingBoxKey {
|
|||||||
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',
|
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',
|
||||||
|
|
||||||
/// 其他
|
/// 其他
|
||||||
// autoUpdate = 'autoUpdate',
|
autoUpdate = 'autoUpdate',
|
||||||
autoClearCache = 'autoClearCache',
|
autoClearCache = 'autoClearCache',
|
||||||
defaultShowComment = 'defaultShowComment',
|
defaultShowComment = 'defaultShowComment',
|
||||||
replySortType = 'replySortType',
|
replySortType = 'replySortType',
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
import 'package:PiliPlus/build_config.dart';
|
||||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.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/constants.dart';
|
||||||
import 'package:PiliPlus/http/init.dart';
|
import 'package:PiliPlus/http/init.dart';
|
||||||
import 'package:PiliPlus/http/member.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/login.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.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 {
|
static Future checkUpdate() async {
|
||||||
// SmartDialog.dismiss();
|
SmartDialog.dismiss();
|
||||||
// var currentInfo = await PackageInfo.fromPlatform();
|
try {
|
||||||
// var result = await Request().get(Api.latestApp, extra: {'ua': 'mob'});
|
dynamic res = await Request().get(Api.latestApp, extra: {'ua': 'mob'});
|
||||||
// if (result.data.isEmpty) {
|
if (res.data.isEmpty) {
|
||||||
// SmartDialog.showToast('检查更新失败,github接口未返回数据,请检查网络');
|
SmartDialog.showToast('检查更新失败,GitHub接口未返回数据,请检查网络');
|
||||||
// return false;
|
return;
|
||||||
// }
|
}
|
||||||
// LatestDataModel data = LatestDataModel.fromJson(result.data[0]);
|
DateTime latest = DateTime.parse(res.data[0]['created_at']);
|
||||||
// String buildNumber = currentInfo.buildNumber;
|
latest = latest.copyWith(hour: latest.hour + 8);
|
||||||
// String remoteVersion = data.tagName!;
|
DateTime current = DateTime.parse(BuildConfig.buildTime);
|
||||||
// if (Platform.isAndroid) {
|
if (current.compareTo(latest) < 0) {
|
||||||
// buildNumber = buildNumber.substring(0, buildNumber.length - 1);
|
SmartDialog.show(
|
||||||
// } else if (Platform.isIOS) {
|
animationType: SmartAnimationType.centerFade_otherSlide,
|
||||||
// remoteVersion = remoteVersion.replaceAll('-beta', '');
|
builder: (context) {
|
||||||
// }
|
return AlertDialog(
|
||||||
// bool isUpdate =
|
title: const Text('🎉 发现新版本 '),
|
||||||
// Utils.needUpdate("${currentInfo.version}+$buildNumber", remoteVersion);
|
content: SizedBox(
|
||||||
// if (isUpdate) {
|
height: 280,
|
||||||
// SmartDialog.show(
|
child: SingleChildScrollView(
|
||||||
// animationType: SmartAnimationType.centerFade_otherSlide,
|
child: Column(
|
||||||
// builder: (context) {
|
mainAxisSize: MainAxisSize.min,
|
||||||
// return AlertDialog(
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
// title: const Text('🎉 发现新版本 '),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
// content: SizedBox(
|
children: [
|
||||||
// height: 280,
|
Text(
|
||||||
// child: SingleChildScrollView(
|
'${res.data[0]['tag_name']}',
|
||||||
// child: Column(
|
style: const TextStyle(fontSize: 20),
|
||||||
// mainAxisSize: MainAxisSize.min,
|
),
|
||||||
// mainAxisAlignment: MainAxisAlignment.start,
|
const SizedBox(height: 8),
|
||||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
Text('${res.data[0]['body']}'),
|
||||||
// children: [
|
TextButton(
|
||||||
// Text(
|
onPressed: () {
|
||||||
// data.tagName!,
|
launchURL(
|
||||||
// style: const TextStyle(fontSize: 20),
|
'https://github.com/bggRGjQaUbCoE/PiliPlus/commits/main');
|
||||||
// ),
|
},
|
||||||
// const SizedBox(height: 8),
|
child: Text(
|
||||||
// Text(data.body!),
|
"点此查看完整更新(即commit)内容",
|
||||||
// TextButton(
|
style: TextStyle(
|
||||||
// onPressed: () {
|
color: Theme.of(context).colorScheme.primary,
|
||||||
// launchUrl(
|
),
|
||||||
// Uri.parse(
|
),
|
||||||
// "https://github.com/bggRGjQaUbCoE/PiliPlus/commits/main/"),
|
),
|
||||||
// mode: LaunchMode.externalApplication,
|
],
|
||||||
// );
|
),
|
||||||
// },
|
),
|
||||||
// child: Text(
|
),
|
||||||
// "点此查看完整更新(即commit)内容",
|
actions: [
|
||||||
// style: TextStyle(
|
TextButton(
|
||||||
// color: Theme.of(context).colorScheme.primary),
|
onPressed: () {
|
||||||
// )),
|
SmartDialog.dismiss();
|
||||||
// ],
|
GStorage.setting.put(SettingBoxKey.autoUpdate, false);
|
||||||
// ),
|
},
|
||||||
// ),
|
child: Text(
|
||||||
// ),
|
'不再提醒',
|
||||||
// actions: [
|
style: TextStyle(
|
||||||
// TextButton(
|
color: Theme.of(context).colorScheme.outline,
|
||||||
// onPressed: () {
|
),
|
||||||
// GStorage.setting.put(SettingBoxKey.autoUpdate, false);
|
),
|
||||||
// SmartDialog.dismiss();
|
),
|
||||||
// },
|
TextButton(
|
||||||
// child: Text(
|
onPressed: SmartDialog.dismiss,
|
||||||
// '不再提醒',
|
child: Text(
|
||||||
// style:
|
'取消',
|
||||||
// TextStyle(color: Theme.of(context).colorScheme.outline),
|
style: TextStyle(
|
||||||
// ),
|
color: Theme.of(context).colorScheme.outline,
|
||||||
// ),
|
),
|
||||||
// TextButton(
|
),
|
||||||
// onPressed: () => SmartDialog.dismiss(),
|
),
|
||||||
// child: Text(
|
TextButton(
|
||||||
// '取消',
|
onPressed: () {
|
||||||
// style:
|
onDownload(res.data[0]);
|
||||||
// TextStyle(color: Theme.of(context).colorScheme.outline),
|
},
|
||||||
// ),
|
child: const Text('Github'),
|
||||||
// ),
|
),
|
||||||
// TextButton(
|
],
|
||||||
// onPressed: () => matchVersion(data),
|
);
|
||||||
// child: const Text('Github'),
|
},
|
||||||
// ),
|
);
|
||||||
// ],
|
}
|
||||||
// );
|
} catch (e) {
|
||||||
// },
|
debugPrint('failed to check update: $e');
|
||||||
// );
|
}
|
||||||
// }
|
}
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 下载适用于当前系统的安装包
|
// 下载适用于当前系统的安装包
|
||||||
// static Future matchVersion(data) async {
|
static Future onDownload(data) async {
|
||||||
// await SmartDialog.dismiss();
|
await SmartDialog.dismiss();
|
||||||
// // 获取设备信息
|
try {
|
||||||
// DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
void download(plat) {
|
||||||
// if (Platform.isAndroid) {
|
if (data['assets'].isNotEmpty) {
|
||||||
// AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
for (dynamic i in data['assets']) {
|
||||||
// // [arm64-v8a]
|
if (i['name'].contains(plat)) {
|
||||||
// String abi = androidInfo.supportedAbis.first;
|
launchURL(i['browser_download_url']);
|
||||||
// late String downloadUrl;
|
break;
|
||||||
// if (data.assets.isNotEmpty) {
|
}
|
||||||
// for (var i in data.assets) {
|
}
|
||||||
// if (i.downloadUrl.contains(abi)) {
|
}
|
||||||
// downloadUrl = i.downloadUrl;
|
}
|
||||||
// }
|
|
||||||
// }
|
if (Platform.isAndroid) {
|
||||||
// // 应用外下载
|
// 获取设备信息
|
||||||
// launchURL(downloadUrl);
|
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) {
|
static tampToSeektime(number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user