更改更新数据获取地址
This commit is contained in:
3 files changed
+11
-13
No files matched your search
@@ -87,7 +87,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
file.delete()
|
file.delete()
|
||||||
|
|
||||||
val connection = java.net.URL(url).openConnection()
|
val connection = java.net.URL(url).openConnection()
|
||||||
connection.setRequestProperty("User-Agent", "MCServerManager")
|
connection.setRequestProperty("User-Agent", "ZVManager")
|
||||||
connection.connectTimeout = 15_000
|
connection.connectTimeout = 15_000
|
||||||
connection.readTimeout = 30_000
|
connection.readTimeout = 30_000
|
||||||
val total = connection.contentLengthLong
|
val total = connection.contentLengthLong
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class CommandPresetService {
|
|||||||
QuickCommandPreset(label: '设为白天', command: 'time set day'),
|
QuickCommandPreset(label: '设为白天', command: 'time set day'),
|
||||||
QuickCommandPreset(label: '设为黑夜', command: 'time set night'),
|
QuickCommandPreset(label: '设为黑夜', command: 'time set night'),
|
||||||
QuickCommandPreset(label: '和平难度', command: 'difficulty peaceful'),
|
QuickCommandPreset(label: '和平难度', command: 'difficulty peaceful'),
|
||||||
QuickCommandPreset(label: '生存模式', command: 'gamemode survival'),
|
|
||||||
QuickCommandPreset(label: '白名单列表', command: 'whitelist list'),
|
QuickCommandPreset(label: '白名单列表', command: 'whitelist list'),
|
||||||
QuickCommandPreset(label: '在线公告', command: 'say 服务器已在线,欢迎游玩!'),
|
QuickCommandPreset(label: '在线公告', command: 'say 服务器已在线,欢迎游玩!'),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ class UpdateService {
|
|||||||
|
|
||||||
/// Gitee 仓库最新发布信息地址
|
/// Gitee 仓库最新发布信息地址
|
||||||
static const _updateInfoUrl =
|
static const _updateInfoUrl =
|
||||||
'https://gitee.com/api/v5/repos/venti1112/mcserver_manager/releases/latest';
|
'https://gitee.com/api/v5/repos/driftinblock/zvmanager/releases/latest';
|
||||||
|
|
||||||
/// Android 原生下载安装通道
|
/// Android 原生下载安装通道
|
||||||
static const _channel = MethodChannel('mc_server_manager/update');
|
static const _channel = MethodChannel('mc_server_manager/update');
|
||||||
|
|
||||||
/// 下载进度事件通道(原生推送)
|
/// 下载进度事件通道(原生推送)
|
||||||
static const _progressChannel = EventChannel('mc_server_manager/down_progress');
|
static const _progressChannel =
|
||||||
|
EventChannel('mc_server_manager/down_progress');
|
||||||
|
|
||||||
/// 是否正在下载,用于防止重复触发并发下载到同一文件。
|
/// 是否正在下载,用于防止重复触发并发下载到同一文件。
|
||||||
static bool _downloading = false;
|
static bool _downloading = false;
|
||||||
@@ -50,8 +51,7 @@ class UpdateService {
|
|||||||
final json = jsonDecode(body) as Map<String, dynamic>;
|
final json = jsonDecode(body) as Map<String, dynamic>;
|
||||||
// Gitee 发布接口的 tag_name 形如 "v1.3.0",去掉开头的 "v" 用于版本号对比
|
// Gitee 发布接口的 tag_name 形如 "v1.3.0",去掉开头的 "v" 用于版本号对比
|
||||||
final tag = json['tag_name'] as String? ?? '';
|
final tag = json['tag_name'] as String? ?? '';
|
||||||
final latestVersion =
|
final latestVersion = tag.startsWith('v') ? tag.substring(1) : tag;
|
||||||
tag.startsWith('v') ? tag.substring(1) : tag;
|
|
||||||
|
|
||||||
// 从 assets 中筛选 APK 安装包,取其直链与文件名
|
// 从 assets 中筛选 APK 安装包,取其直链与文件名
|
||||||
String downloadUrl = '';
|
String downloadUrl = '';
|
||||||
@@ -60,8 +60,7 @@ class UpdateService {
|
|||||||
for (final item in assets) {
|
for (final item in assets) {
|
||||||
final name = (item as Map<String, dynamic>)['name'] as String? ?? '';
|
final name = (item as Map<String, dynamic>)['name'] as String? ?? '';
|
||||||
if (name.endsWith('.apk')) {
|
if (name.endsWith('.apk')) {
|
||||||
downloadUrl =
|
downloadUrl = (item['browser_download_url'] as String? ??
|
||||||
(item['browser_download_url'] as String? ??
|
|
||||||
item['download_url'] as String? ??
|
item['download_url'] as String? ??
|
||||||
'');
|
'');
|
||||||
apkName = name;
|
apkName = name;
|
||||||
@@ -97,7 +96,8 @@ class UpdateService {
|
|||||||
? '最新版本: ${info.latestVersion}\n当前版本: $currentVersion'
|
? '最新版本: ${info.latestVersion}\n当前版本: $currentVersion'
|
||||||
: '当前版本 $currentVersion 已是最新'),
|
: '当前版本 $currentVersion 已是最新'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('关闭')),
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context), child: const Text('关闭')),
|
||||||
if (hasUpdate)
|
if (hasUpdate)
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -112,7 +112,8 @@ class UpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 调用 Android 原生下载 APK 并调起系统安装器;下载期间展示不可关闭的进度弹窗,失败提示错误。
|
/// 调用 Android 原生下载 APK 并调起系统安装器;下载期间展示不可关闭的进度弹窗,失败提示错误。
|
||||||
static Future<void> downloadAndInstall(BuildContext context, UpdateInfo info) async {
|
static Future<void> downloadAndInstall(
|
||||||
|
BuildContext context, UpdateInfo info) async {
|
||||||
if (_downloading) {
|
if (_downloading) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('正在下载,请稍候…')),
|
const SnackBar(content: Text('正在下载,请稍候…')),
|
||||||
@@ -162,9 +163,7 @@ class UpdateService {
|
|||||||
CircularProgressIndicator(value: value),
|
CircularProgressIndicator(value: value),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
percent == null
|
percent == null ? '正在下载安装包…' : '下载中:$percent%',
|
||||||
? '正在下载安装包…'
|
|
||||||
: '下载中:$percent%',
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in new issue
Block a user