api修改和更新检查器修改
modrinth_api.dart:拦截器改为只替换 options.baseUrl,path 保持相对 /v2/search、query 留在 queryParameters,避免"整串写回 path"导致的 host 缺失 + query 重复拼接。mirror_service.dart:新增 apiBase getter,返回当前镜像的 API base(official→api.modrinth.com、mcim→modrinth-api.mcimirror.top、custom→自定义 base) Signed-off-by: driftinblock <3480428251@qq.com>
This commit is contained in:
35 files changed
+4171
-1325
No files matched your search
@@ -1,9 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/download_provider.dart';
|
||||
|
||||
import '../../core/l10n/strings.dart';
|
||||
import '../../core/widgets/z_widgets.dart';
|
||||
import '../../providers/download_provider.dart';
|
||||
import '../../providers/wallpaper_provider.dart';
|
||||
|
||||
/// 下载与镜像设置页:镜像线路选择、测速自动选线、并发数(原下载页内设置移入此处)。
|
||||
///
|
||||
/// 版式:两组 ZL2 圆角面板。镜像线路用尾部圆形勾选钮表达单选,
|
||||
/// 比 RadioListTile 更紧凑,也与其他设置页的选中态语言一致。
|
||||
class DownloadSettingsPage extends StatefulWidget {
|
||||
const DownloadSettingsPage({super.key});
|
||||
|
||||
@@ -24,87 +30,102 @@ class _DownloadSettingsPageState extends State<DownloadSettingsPage> {
|
||||
Widget build(BuildContext context) {
|
||||
final dp = context.watch<DownloadProvider>();
|
||||
final mirror = dp.mirror;
|
||||
final hasWallpaper = context.watch<WallpaperProvider>().hasWallpaper;
|
||||
final st = ZStyle.of(context, hasWallpaper: hasWallpaper);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: T('下载与镜像设置')),
|
||||
backgroundColor: hasWallpaper ? Colors.transparent : null,
|
||||
appBar: ZAppBar(
|
||||
title: T('下载与镜像设置'),
|
||||
backgroundColor: hasWallpaper ? Colors.transparent : null,
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 28),
|
||||
children: [
|
||||
const SectionHeader('镜像线路'),
|
||||
RadioListTile<String>(
|
||||
title: T('MCIM 国内镜像(推荐)'),
|
||||
subtitle: T('modrinth.mcimirror.top,无需科学上网'),
|
||||
value: 'mcim',
|
||||
groupValue: mirror.currentId,
|
||||
onChanged: (v) async {
|
||||
await mirror.select(v!);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: T('Modrinth 官方'),
|
||||
subtitle: T('直连官方源,适合海外网络'),
|
||||
value: 'official',
|
||||
groupValue: mirror.currentId,
|
||||
onChanged: (v) async {
|
||||
await mirror.select(v!);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: T('自定义镜像'),
|
||||
subtitle: Text(mirror.currentId == 'custom' && mirror.customUrl.isNotEmpty
|
||||
? mirror.customUrl
|
||||
: '使用自建/第三方镜像地址'),
|
||||
value: 'custom',
|
||||
groupValue: mirror.currentId,
|
||||
onChanged: (v) async => {await _editCustomUrl(), setState(() {})},
|
||||
),
|
||||
ListTile(
|
||||
leading: _testing
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Icon(Icons.speed),
|
||||
title: T('一键测速并选择最快线路'),
|
||||
subtitle: Text(mirror.lastSpeedMs > 0
|
||||
? S.f('上次测速:{0}ms({1})', [mirror.lastSpeedMs, mirror.currentName])
|
||||
: '自动在官方与镜像之间选择延迟最低的线路'),
|
||||
onTap: _testing
|
||||
? null
|
||||
: () async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
setState(() => _testing = true);
|
||||
await mirror.autoSelect();
|
||||
if (!mounted) return;
|
||||
setState(() => _testing = false);
|
||||
messenger.showSnackBar(SnackBar(
|
||||
content: Text(S.f('已选择最快线路:{0}({1}ms)', [mirror.currentName, mirror.lastSpeedMs])),
|
||||
));
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
const SectionHeader('下载队列'),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.playlist_play),
|
||||
title: T('同时下载任务数'),
|
||||
subtitle: Text(S.f('当前:{0} 个(越大越占带宽,建议 1-3)', [dp.concurrency])),
|
||||
trailing: DropdownButton<int>(
|
||||
value: dp.concurrency,
|
||||
underline: const SizedBox.shrink(),
|
||||
items: const [1, 2, 3, 4, 5, 6]
|
||||
.map((n) => DropdownMenuItem(value: n, child: Text('$n')))
|
||||
.toList(),
|
||||
onChanged: (n) async {
|
||||
if (n == null) return;
|
||||
await dp.setConcurrency(n);
|
||||
// ---------- 镜像线路 ----------
|
||||
ZPanel(style: st, children: [
|
||||
_MirrorRow(
|
||||
style: st,
|
||||
title: 'MCIM 国内镜像(推荐)',
|
||||
subtitle: 'mod.mcimirror.top,无需科学上网',
|
||||
selected: mirror.currentId == 'mcim',
|
||||
onTap: () async {
|
||||
await mirror.select('mcim');
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
ZDivider(style: st),
|
||||
_MirrorRow(
|
||||
style: st,
|
||||
title: 'Modrinth 官方',
|
||||
subtitle: '直连官方源,适合海外网络',
|
||||
selected: mirror.currentId == 'official',
|
||||
onTap: () async {
|
||||
await mirror.select('official');
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
ZDivider(style: st),
|
||||
_MirrorRow(
|
||||
style: st,
|
||||
title: '自定义镜像',
|
||||
subtitle: mirror.currentId == 'custom' && mirror.customUrl.isNotEmpty
|
||||
? mirror.customUrl
|
||||
: '使用自建/第三方镜像地址',
|
||||
selected: mirror.currentId == 'custom',
|
||||
onTap: () async {
|
||||
await _editCustomUrl();
|
||||
if (mounted) setState(() {});
|
||||
},
|
||||
),
|
||||
ZDivider(style: st),
|
||||
ZRow(
|
||||
title: '一键测速并选择最快线路',
|
||||
subtitle: mirror.lastSpeedMs > 0
|
||||
? S.f('上次测速:{0}ms({1})',
|
||||
[mirror.lastSpeedMs, mirror.currentName])
|
||||
: '自动在官方与镜像之间选择延迟最低的线路',
|
||||
style: st,
|
||||
leading: Icon(Icons.speed, size: 20, color: st.subColor),
|
||||
trailing: _testing
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: null,
|
||||
onTap: _testing ? null : _autoSelect,
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 14),
|
||||
// ---------- 下载队列 ----------
|
||||
ZPanel(style: st, children: [
|
||||
ZRow(
|
||||
title: '同时下载任务数',
|
||||
subtitle: S.f('当前:{0} 个(越大越占带宽,建议 1-3)', [dp.concurrency]),
|
||||
style: st,
|
||||
leading: Icon(Icons.playlist_play, size: 20, color: st.subColor),
|
||||
trailing: DropdownButton<int>(
|
||||
value: dp.concurrency,
|
||||
underline: const SizedBox.shrink(),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
items: const [1, 2, 3, 4, 5, 6]
|
||||
.map((n) => DropdownMenuItem(value: n, child: Text('$n')))
|
||||
.toList(),
|
||||
onChanged: (n) async {
|
||||
if (n == null) return;
|
||||
await dp.setConcurrency(n);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: Text(
|
||||
'说明:下载完成的文件保存在应用目录 downloads/ 下;'
|
||||
'若服务器配置了 SSH,会自动上传到对应服务器的 mods/plugins 目录。',
|
||||
style: TextStyle(fontSize: 13),
|
||||
S.t('说明:下载完成的文件保存在应用目录 downloads/ 下;'
|
||||
'若服务器配置了 SSH,会自动上传到对应服务器的 mods/plugins 目录。'),
|
||||
style: TextStyle(fontSize: 12, height: 1.6, color: st.subColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -112,6 +133,21 @@ class _DownloadSettingsPageState extends State<DownloadSettingsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 测速并自动选线:过程中禁用点击,完成后用 SnackBar 告知结果。
|
||||
Future<void> _autoSelect() async {
|
||||
final dp = context.read<DownloadProvider>();
|
||||
final mirror = dp.mirror;
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
setState(() => _testing = true);
|
||||
await mirror.autoSelect();
|
||||
if (!mounted) return;
|
||||
setState(() => _testing = false);
|
||||
messenger.showSnackBar(SnackBar(
|
||||
content: Text(S.f('已选择最快线路:{0}({1}ms)',
|
||||
[mirror.currentName, mirror.lastSpeedMs])),
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> _editCustomUrl() async {
|
||||
final dp = context.read<DownloadProvider>();
|
||||
final ctrl = TextEditingController(text: dp.mirror.customUrl);
|
||||
@@ -125,7 +161,9 @@ class _DownloadSettingsPageState extends State<DownloadSettingsPage> {
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: T('取消')),
|
||||
FilledButton(onPressed: () => Navigator.pop(context, ctrl.text.trim()), child: T('确定')),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(context, ctrl.text.trim()),
|
||||
child: T('确定')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -135,19 +173,36 @@ class _DownloadSettingsPageState extends State<DownloadSettingsPage> {
|
||||
}
|
||||
}
|
||||
|
||||
class SectionHeader extends StatelessWidget {
|
||||
final String text;
|
||||
const SectionHeader(this.text, {super.key});
|
||||
/// 镜像线路单选行:右侧用圆形勾选钮表示当前生效线路。
|
||||
class _MirrorRow extends StatelessWidget {
|
||||
final ZStyle style;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _MirrorRow({
|
||||
required this.style,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 6),
|
||||
child: Text(text,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall
|
||||
?.copyWith(color: Theme.of(context).colorScheme.primary)),
|
||||
return ZRow(
|
||||
style: style,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
onTap: onTap,
|
||||
trailing: ZToggle(
|
||||
value: selected,
|
||||
size: 30,
|
||||
borderColor: style.subColor,
|
||||
// 单选:只允许从未选变选中,再点已选项不做取消
|
||||
onChanged: (_) => onTap(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user