feat: 检查更新
This commit is contained in:
@ -4,12 +4,14 @@ class LatestDataModel {
|
|||||||
this.tagName,
|
this.tagName,
|
||||||
this.createdAt,
|
this.createdAt,
|
||||||
this.assets,
|
this.assets,
|
||||||
|
this.body,
|
||||||
});
|
});
|
||||||
|
|
||||||
String? url;
|
String? url;
|
||||||
String? tagName;
|
String? tagName;
|
||||||
String? createdAt;
|
String? createdAt;
|
||||||
List? assets;
|
List? assets;
|
||||||
|
String? body;
|
||||||
|
|
||||||
LatestDataModel.fromJson(Map<String, dynamic> json) {
|
LatestDataModel.fromJson(Map<String, dynamic> json) {
|
||||||
url = json['url'];
|
url = json['url'];
|
||||||
@ -17,6 +19,7 @@ class LatestDataModel {
|
|||||||
createdAt = json['created_at'];
|
createdAt = json['created_at'];
|
||||||
assets =
|
assets =
|
||||||
json['assets'].map<AssetItem>((e) => AssetItem.fromJson(e)).toList();
|
json['assets'].map<AssetItem>((e) => AssetItem.fromJson(e)).toList();
|
||||||
|
body = json['body'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
import 'package:pilipala/http/index.dart';
|
import 'package:pilipala/http/index.dart';
|
||||||
import 'package:pilipala/models/github/latest.dart';
|
import 'package:pilipala/models/github/latest.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
@ -165,7 +164,7 @@ class AboutController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取啊当前版本
|
// 获取当前版本
|
||||||
Future getCurrentApp() async {
|
Future getCurrentApp() async {
|
||||||
var result = await PackageInfo.fromPlatform();
|
var result = await PackageInfo.fromPlatform();
|
||||||
currentVersion.value = result.version;
|
currentVersion.value = result.version;
|
||||||
|
|||||||
@ -2,9 +2,12 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/pages/dynamics/index.dart';
|
import 'package:pilipala/pages/dynamics/index.dart';
|
||||||
import 'package:pilipala/pages/home/view.dart';
|
import 'package:pilipala/pages/home/view.dart';
|
||||||
import 'package:pilipala/pages/media/index.dart';
|
import 'package:pilipala/pages/media/index.dart';
|
||||||
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
import 'package:pilipala/utils/utils.dart';
|
||||||
|
|
||||||
class MainController extends GetxController {
|
class MainController extends GetxController {
|
||||||
List<Widget> pages = <Widget>[
|
List<Widget> pages = <Widget>[
|
||||||
@ -49,4 +52,13 @@ class MainController extends GetxController {
|
|||||||
].obs;
|
].obs;
|
||||||
final StreamController<bool> bottomBarStream =
|
final StreamController<bool> bottomBarStream =
|
||||||
StreamController<bool>.broadcast();
|
StreamController<bool>.broadcast();
|
||||||
|
Box setting = GStrorage.setting;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
if (setting.get(SettingBoxKey.autoUpdate, defaultValue: false)) {
|
||||||
|
Utils.checkUpdata();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
lib/pages/setting/extra_setting.dart
Normal file
37
lib/pages/setting/extra_setting.dart
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
|
import 'widgets/switch_item.dart';
|
||||||
|
|
||||||
|
class ExtraSetting extends StatefulWidget {
|
||||||
|
const ExtraSetting({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ExtraSetting> createState() => _ExtraSettingState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExtraSettingState extends State<ExtraSetting> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
centerTitle: false,
|
||||||
|
titleSpacing: 0,
|
||||||
|
title: Text(
|
||||||
|
'其他设置',
|
||||||
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
children: const [
|
||||||
|
SetSwitchItem(
|
||||||
|
title: '检查更新',
|
||||||
|
subTitle: '每次启动时检查是否需要更新',
|
||||||
|
setKey: SettingBoxKey.autoUpdate,
|
||||||
|
defaultVal: false,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -34,11 +34,11 @@ class SettingPage extends StatelessWidget {
|
|||||||
dense: false,
|
dense: false,
|
||||||
title: const Text('外观设置'),
|
title: const Text('外观设置'),
|
||||||
),
|
),
|
||||||
// ListTile(
|
ListTile(
|
||||||
// onTap: () {},
|
onTap: () => Get.toNamed('/extraSetting'),
|
||||||
// dense: false,
|
dense: false,
|
||||||
// title: const Text('其他设置'),
|
title: const Text('其他设置'),
|
||||||
// ),
|
),
|
||||||
Obx(
|
Obx(
|
||||||
() => Visibility(
|
() => Visibility(
|
||||||
visible: settingController.userLogin.value,
|
visible: settingController.userLogin.value,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
import 'package:pilipala/utils/utils.dart';
|
||||||
|
|
||||||
class SetSwitchItem extends StatefulWidget {
|
class SetSwitchItem extends StatefulWidget {
|
||||||
final String? title;
|
final String? title;
|
||||||
@ -61,6 +62,9 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
|
|||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
val = value;
|
val = value;
|
||||||
Setting.put(widget.setKey, value);
|
Setting.put(widget.setKey, value);
|
||||||
|
if (widget.setKey == SettingBoxKey.autoUpdate && value == true) {
|
||||||
|
Utils.checkUpdata();
|
||||||
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import 'package:pilipala/pages/member/index.dart';
|
|||||||
import 'package:pilipala/pages/preview/index.dart';
|
import 'package:pilipala/pages/preview/index.dart';
|
||||||
import 'package:pilipala/pages/search/index.dart';
|
import 'package:pilipala/pages/search/index.dart';
|
||||||
import 'package:pilipala/pages/searchResult/index.dart';
|
import 'package:pilipala/pages/searchResult/index.dart';
|
||||||
|
import 'package:pilipala/pages/setting/extra_setting.dart';
|
||||||
import 'package:pilipala/pages/setting/play_setting.dart';
|
import 'package:pilipala/pages/setting/play_setting.dart';
|
||||||
import 'package:pilipala/pages/setting/privacy_setting.dart';
|
import 'package:pilipala/pages/setting/privacy_setting.dart';
|
||||||
import 'package:pilipala/pages/setting/style_setting.dart';
|
import 'package:pilipala/pages/setting/style_setting.dart';
|
||||||
@ -80,7 +81,8 @@ class Routes {
|
|||||||
GetPage(name: '/styleSetting', page: () => const StyleSetting()),
|
GetPage(name: '/styleSetting', page: () => const StyleSetting()),
|
||||||
// 隐私设置
|
// 隐私设置
|
||||||
GetPage(name: '/privacySetting', page: () => const PrivacySetting()),
|
GetPage(name: '/privacySetting', page: () => const PrivacySetting()),
|
||||||
|
// 其他设置
|
||||||
|
GetPage(name: '/extraSetting', page: () => const ExtraSetting()),
|
||||||
//
|
//
|
||||||
GetPage(name: '/blackListPage', page: () => const BlackListPage()),
|
GetPage(name: '/blackListPage', page: () => const BlackListPage()),
|
||||||
// 关于
|
// 关于
|
||||||
|
|||||||
@ -119,6 +119,7 @@ class SettingBoxKey {
|
|||||||
static const String fullScreenMode = 'fullScreenMode';
|
static const String fullScreenMode = 'fullScreenMode';
|
||||||
|
|
||||||
static const String blackMidsList = 'blackMidsList';
|
static const String blackMidsList = 'blackMidsList';
|
||||||
|
static const String autoUpdate = 'autoUpdate';
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalCacheKey {
|
class LocalCacheKey {
|
||||||
|
|||||||
@ -4,8 +4,14 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get_utils/get_utils.dart';
|
import 'package:get/get_utils/get_utils.dart';
|
||||||
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:pilipala/http/index.dart';
|
||||||
|
import 'package:pilipala/models/github/latest.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
static Future<String> getCookiePath() async {
|
static Future<String> getCookiePath() async {
|
||||||
@ -194,4 +200,55 @@ class Utils {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查更新
|
||||||
|
static Future<bool> checkUpdata() async {
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
var currentInfo = await PackageInfo.fromPlatform();
|
||||||
|
var result = await Request().get(Api.latestApp);
|
||||||
|
LatestDataModel data = LatestDataModel.fromJson(result.data);
|
||||||
|
bool isUpdate = Utils.needUpdate(currentInfo.version, data.tagName!);
|
||||||
|
if (isUpdate) {
|
||||||
|
SmartDialog.show(
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('🎉 发现新版本 '),
|
||||||
|
content: 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!),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => SmartDialog.dismiss(),
|
||||||
|
child: Text(
|
||||||
|
'稍后',
|
||||||
|
style:
|
||||||
|
TextStyle(color: Theme.of(context).colorScheme.outline),
|
||||||
|
)),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await SmartDialog.dismiss();
|
||||||
|
launchUrl(
|
||||||
|
Uri.parse(
|
||||||
|
'https://github.com/guozhigq/pilipala/releases'),
|
||||||
|
mode: LaunchMode.externalApplication,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('去下载')),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user