feat: 下载队列进度条视图切换;设置新增用户须知入口;检查更新/创造者/开源许可合并至关于软件页
This commit is contained in:
1 parent
eb2f9e9ea7
commit
4277dc9f84
5 files changed
+248
-60
No files matched your search
@@ -405,6 +405,15 @@ class S {
|
||||
'目录下没有日志文件': 'No log files in this directory',
|
||||
'读取失败:{0}': 'Failed to read: {0}',
|
||||
'自动刷新并跟随底部(每 5 秒)': 'Auto refresh & follow bottom (every 5s)',
|
||||
'卡片视图': 'Card view',
|
||||
'进度条视图': 'Progress bar view',
|
||||
'用户须知': 'User Notice',
|
||||
'查看用户守则全部条款': 'View all terms of the user agreement',
|
||||
'关于软件': 'About',
|
||||
'版本、检查更新、创造者与开源许可': 'Version, updates, creators and licenses',
|
||||
'我知道了': 'Got it',
|
||||
'创造者': 'Creators',
|
||||
'ZV Manager 是一款 Minecraft 服务器远程管理工具,本软件与 Mojang、微软无任何隶属关系。': 'ZV Manager is a remote management tool for Minecraft servers. Not affiliated with Mojang or Microsoft.',
|
||||
};
|
||||
|
||||
static String t(String zh) => en ? (_en[zh] ?? zh) : zh;
|
||||
|
||||
@@ -5,7 +5,14 @@ import '../l10n/strings.dart';
|
||||
class UserAgreementDialog extends StatefulWidget {
|
||||
final VoidCallback onAgree;
|
||||
|
||||
const UserAgreementDialog({super.key, required this.onAgree});
|
||||
/// 只读模式:设置「用户须知」入口使用,无需倒计时/勾选,按钮直接关闭。
|
||||
final bool readOnly;
|
||||
|
||||
const UserAgreementDialog({super.key, required this.onAgree, this.readOnly = false});
|
||||
|
||||
/// 只读查看入口。
|
||||
static Widget readView() =>
|
||||
UserAgreementDialog(onAgree: () {}, readOnly: true);
|
||||
|
||||
@override
|
||||
State<UserAgreementDialog> createState() => _UserAgreementDialogState();
|
||||
@@ -13,6 +20,7 @@ class UserAgreementDialog extends StatefulWidget {
|
||||
|
||||
class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
||||
bool _isChecked = false;
|
||||
bool get _readOnly => widget.readOnly;
|
||||
|
||||
/// 强制阅读:倒计时 10 秒 + 滚动到底,两者都满足才能勾选同意。
|
||||
static const int _readSeconds = 10;
|
||||
@@ -24,6 +32,11 @@ class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.readOnly) {
|
||||
_countdown = 0;
|
||||
_readToEnd = true;
|
||||
return;
|
||||
}
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (t) {
|
||||
if (!mounted) return t.cancel();
|
||||
setState(() => _countdown--);
|
||||
@@ -48,9 +61,11 @@ class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
||||
}
|
||||
}
|
||||
|
||||
bool get _canAgree => _isChecked && _countdown <= 0 && _readToEnd;
|
||||
bool get _canAgree =>
|
||||
_readOnly || (_isChecked && _countdown <= 0 && _readToEnd);
|
||||
|
||||
String get _buttonLabel {
|
||||
if (_readOnly) return S.t('我知道了');
|
||||
if (_countdown > 0) return S.f('请仔细阅读守则({0}s)', [_countdown]);
|
||||
if (!_readToEnd) return S.t('请阅读至守则底部');
|
||||
return S.t('同意并进入');
|
||||
@@ -59,7 +74,7 @@ class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
canPop: _readOnly,
|
||||
child: Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
@@ -152,8 +167,8 @@ class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 同意勾选(倒计时结束且阅读到底后才可勾选)
|
||||
GestureDetector(
|
||||
// 同意勾选(倒计时结束且阅读到底后才可勾选);只读模式不显示
|
||||
if (!_readOnly) GestureDetector(
|
||||
onTap: _countdown <= 0 && _readToEnd
|
||||
? () {
|
||||
setState(() {
|
||||
@@ -197,7 +212,11 @@ class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton(
|
||||
onPressed: _canAgree ? widget.onAgree : null,
|
||||
onPressed: !_canAgree
|
||||
? null
|
||||
: (_readOnly
|
||||
? () => Navigator.of(context).pop()
|
||||
: widget.onAgree),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF28A745),
|
||||
disabledBackgroundColor: const Color(0xFFCCCCCC),
|
||||
|
||||
@@ -26,6 +26,9 @@ class _DownloadPageState extends State<DownloadPage> {
|
||||
static const _mcVersions = ['1.21.4', '1.21.1', '1.20.6', '1.20.4', '1.20.1', '1.19.4', '1.18.2', '1.16.5'];
|
||||
static const _loaders = ['fabric', 'forge', 'quilt', 'neoforge', 'paper', 'bukkit', 'spigot'];
|
||||
|
||||
/// 任务队列视图:false=卡片列表,true=进度条视图。
|
||||
bool _barView = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -78,6 +81,11 @@ class _DownloadPageState extends State<DownloadPage> {
|
||||
MaterialPageRoute(builder: (_) => const DownloadSettingsPage()),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(_barView ? Icons.view_list_outlined : Icons.equalizer),
|
||||
tooltip: _barView ? S.t('卡片视图') : S.t('进度条视图'),
|
||||
onPressed: () => setState(() => _barView = !_barView),
|
||||
),
|
||||
],
|
||||
bottom: const TabBar(tabs: [Tab(text: '搜索下载'), Tab(text: '任务队列')]),
|
||||
),
|
||||
@@ -235,12 +243,89 @@ class _DownloadPageState extends State<DownloadPage> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 进度条视图:每个任务一条横向进度条 + 百分比。
|
||||
Widget _buildBarList(DownloadProvider dp, List tasks) {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: tasks.length,
|
||||
itemBuilder: (context, i) {
|
||||
final t = tasks[i];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text('${i + 1}. ${t.fileName}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodyMedium),
|
||||
),
|
||||
Text('${(t.progress * 100).toStringAsFixed(0)}%',
|
||||
style: Theme.of(context).textTheme.bodySmall),
|
||||
const SizedBox(width: 4),
|
||||
_statusChip(t.status),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
LinearProgressIndicator(
|
||||
value: t.status == DownloadStatus.completed ? 1 : t.progress,
|
||||
minHeight: 8,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'${_fmt(t.receivedBytes)} / ${_fmt(t.totalBytes)}'
|
||||
'${t.status == DownloadStatus.running ? " · ${_fmt(t.speed)}/s" : ""}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
const Spacer(),
|
||||
if (t.status == DownloadStatus.running)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.pause, size: 20),
|
||||
tooltip: S.t('暂停'),
|
||||
onPressed: () => dp.manager.pause(t.id),
|
||||
),
|
||||
if (t.status == DownloadStatus.paused)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.play_arrow, size: 20),
|
||||
tooltip: S.t('继续'),
|
||||
onPressed: () => dp.manager.resume(t.id),
|
||||
),
|
||||
if (t.status == DownloadStatus.failed)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.replay, size: 20),
|
||||
tooltip: S.t('重试'),
|
||||
onPressed: () => dp.manager.retry(t.id),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
tooltip: S.t('取消'),
|
||||
onPressed: () => dp.manager.cancel(t.id),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (t.error != null)
|
||||
Text(t.error!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQueueTab(DownloadProvider dp) {
|
||||
return AnimatedBuilder(
|
||||
animation: dp.manager,
|
||||
builder: (context, _) {
|
||||
final tasks = dp.manager.tasks;
|
||||
if (tasks.isEmpty) return const Center(child: T('暂无下载任务'));
|
||||
if (_barView) return _buildBarList(dp, tasks);
|
||||
return ListView.builder(
|
||||
itemCount: tasks.length,
|
||||
itemBuilder: (context, i) {
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import '../../core/l10n/strings.dart';
|
||||
import '../../core/utils/update_service.dart';
|
||||
|
||||
/// 关于软件页:版本与检查更新 + 开发者信息 + 开源许可。
|
||||
class AboutPage extends StatefulWidget {
|
||||
const AboutPage({super.key});
|
||||
|
||||
@override
|
||||
State<AboutPage> createState() => _AboutPageState();
|
||||
}
|
||||
|
||||
class _AboutPageState extends State<AboutPage> {
|
||||
String _currentVersion = '';
|
||||
bool _checkingUpdate = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadVersion();
|
||||
}
|
||||
|
||||
Future<void> _loadVersion() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
if (mounted) setState(() => _currentVersion = info.version);
|
||||
}
|
||||
|
||||
Future<void> _checkUpdate() async {
|
||||
setState(() => _checkingUpdate = true);
|
||||
try {
|
||||
final updateInfo = await UpdateService.fetchInfo(userAgent: _currentVersion);
|
||||
if (!mounted) return;
|
||||
setState(() => _checkingUpdate = false);
|
||||
|
||||
if (updateInfo == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: T('获取更新信息失败')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateService.showUpdateDialog(context, updateInfo, _currentVersion);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _checkingUpdate = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(S.f('检查更新失败:{0}', [e]))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: T('关于软件')),
|
||||
body: ListView(
|
||||
children: [
|
||||
const SizedBox(height: 24),
|
||||
Column(
|
||||
children: [
|
||||
const Icon(Icons.extension, size: 64),
|
||||
const SizedBox(height: 8),
|
||||
T('ZV Manager', style: Theme.of(context).textTheme.titleLarge),
|
||||
Text(S.f('版本 {0}', [_currentVersion]),
|
||||
style: Theme.of(context).textTheme.bodySmall),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.system_update_outlined),
|
||||
title: T('检查更新'),
|
||||
trailing: _checkingUpdate
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Icon(Icons.chevron_right),
|
||||
onTap: _checkingUpdate ? null : _checkUpdate,
|
||||
),
|
||||
const Divider(),
|
||||
const ListTile(
|
||||
leading: Icon(Icons.person_outline),
|
||||
title: T('创造者'),
|
||||
subtitle: T('开发者:Z有3笔,协作者:venti1112'),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.fact_check_outlined),
|
||||
title: T('开源许可'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => showLicensePage(context: context),
|
||||
),
|
||||
const Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
S.t('ZV Manager 是一款 Minecraft 服务器远程管理工具,本软件与 Mojang、微软无任何隶属关系。'),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'dart:io';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/utils/update_service.dart';
|
||||
import '../../core/utils/background_service.dart';
|
||||
import '../../core/widgets/background_widget.dart';
|
||||
import '../../providers/theme_provider.dart';
|
||||
import '../../providers/wallpaper_provider.dart';
|
||||
import 'help_page.dart';
|
||||
import 'server_log_page.dart';
|
||||
import 'about_page.dart';
|
||||
import '../../core/widgets/user_agreement_dialog.dart';
|
||||
import 'download_settings_page.dart';
|
||||
import '../../providers/language_provider.dart';
|
||||
import '../../core/l10n/strings.dart';
|
||||
@@ -24,8 +24,6 @@ class SettingsPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SettingsPageState extends State<SettingsPage> {
|
||||
String _currentVersion = '';
|
||||
bool _checkingUpdate = false;
|
||||
String? _currentBgType;
|
||||
String? _currentBgPath;
|
||||
bool _videoSoundEnabled = false;
|
||||
@@ -33,16 +31,10 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadVersion();
|
||||
_loadCurrentBg();
|
||||
_loadVideoSound();
|
||||
}
|
||||
|
||||
Future<void> _loadVersion() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
if (mounted) setState(() => _currentVersion = info.version);
|
||||
}
|
||||
|
||||
Future<void> _loadCurrentBg() async {
|
||||
final data = await BackgroundService.getBackground();
|
||||
if (mounted) {
|
||||
@@ -58,30 +50,6 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
if (mounted) setState(() => _videoSoundEnabled = enabled);
|
||||
}
|
||||
|
||||
Future<void> _checkUpdate() async {
|
||||
setState(() => _checkingUpdate = true);
|
||||
try {
|
||||
final updateInfo = await UpdateService.fetchInfo(userAgent: _currentVersion);
|
||||
if (!mounted) return;
|
||||
setState(() => _checkingUpdate = false);
|
||||
|
||||
if (updateInfo == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: T('获取更新信息失败')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateService.showUpdateDialog(context, updateInfo, _currentVersion);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _checkingUpdate = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(S.f('检查更新失败:{0}', [e]))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 背景相关方法 ====================
|
||||
|
||||
void _showBackgroundPicker() {
|
||||
@@ -358,31 +326,30 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
// ---------- 检查更新 ----------
|
||||
// ---------- 用户须知 ----------
|
||||
ListTile(
|
||||
leading: const Icon(Icons.system_update_outlined),
|
||||
title: T('检查更新'),
|
||||
subtitle: Text(S.f('当前版本: {0}', [_currentVersion])),
|
||||
trailing: _checkingUpdate
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Icon(Icons.chevron_right),
|
||||
onTap: _checkingUpdate ? null : _checkUpdate,
|
||||
leading: const Icon(Icons.gavel_outlined),
|
||||
title: T('用户须知'),
|
||||
subtitle: T('查看用户守则全部条款'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => showDialog(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (_) => UserAgreementDialog.readView(),
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
// ---------- 关于 ----------
|
||||
const ListTile(
|
||||
leading: Icon(Icons.info_outline),
|
||||
title: T('关于'),
|
||||
subtitle: T('开发者:Z有3笔,协作者:venti1112'),
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
// ---------- 开源许可 ----------
|
||||
// ---------- 关于软件(检查更新 + 创造者 + 开源许可) ----------
|
||||
ListTile(
|
||||
leading: const Icon(Icons.fact_check_outlined),
|
||||
title: T('开源许可'),
|
||||
onTap: () => showLicensePage(context: context),
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: T('关于软件'),
|
||||
subtitle: T('版本、检查更新、创造者与开源许可'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const AboutPage()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user