下载管理器 操作更新

This commit is contained in:
xkeyC 2024-02-24 14:57:52 +08:00
parent e0ca3377ac
commit 3b025e7b3e
3 changed files with 58 additions and 8 deletions

View File

@ -14,6 +14,34 @@ class DownloadsUI extends BaseUI<DownloadsUIModel> {
content: Column(
children: [
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
for (final item in <MapEntry<String, IconData>, String>{
if (model.tasks.isNotEmpty)
const MapEntry("pause_all", FluentIcons.pause): "暂停全部"
else
const MapEntry("resume_all", FluentIcons.download): "恢复全部",
const MapEntry("cancel_all", FluentIcons.cancel): "取消全部",
}.entries)
Padding(
padding: const EdgeInsets.only(left: 6, right: 6),
child: Button(
child: Padding(
padding: const EdgeInsets.all(4),
child: Row(
children: [
Icon(item.key.value),
const SizedBox(width: 6),
Text(item.value),
],
),
),
onPressed: () => model.onTapButton(item.key.key)),
),
const SizedBox(width: 12),
],
),
Expanded(
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
@ -26,8 +54,11 @@ class DownloadsUI extends BaseUI<DownloadsUIModel> {
Column(
children: [
Container(
padding: const EdgeInsets.only(
left: 24, right: 24, top: 12, bottom: 12),
padding: EdgeInsets.only(
left: 24,
right: 24,
top: index == 0 ? 0 : 12,
bottom: 12),
margin: const EdgeInsets.only(top: 6, bottom: 6),
child: Row(
children: [
@ -150,8 +181,7 @@ class DownloadsUI extends BaseUI<DownloadsUIModel> {
size: 14,
),
text: const Text('打开文件夹'),
onPressed: () =>
model.openFolder(task)),
onPressed: () => model.openFolder(task)),
],
),
const SizedBox(width: 12),

View File

@ -31,7 +31,29 @@ class DownloadsUIModel extends BaseUIModel {
_listenDownloader();
}
onTapButton(String key) {}
onTapButton(String key) async {
switch (key) {
case "pause_all":
await Aria2cManager.aria2c.pauseAll();
return;
case "resume_all":
await Aria2cManager.aria2c.unpauseAll();
return;
case "cancel_all":
final userOK = await showConfirmDialogs(
context!, "确认取消全部任务?", const Text("如果文件不再需要,你可能需要手动删除下载文件。"));
if (userOK == true) {
try {
for (var value in [...tasks, ...waitingTasks]) {
await Aria2cManager.aria2c.remove(value.gid!);
}
} catch (e) {
dPrint("DownloadsUIModel cancel_all Error: $e");
}
}
return;
}
}
_listenDownloader() async {
try {
@ -122,7 +144,7 @@ class DownloadsUIModel extends BaseUIModel {
await Future.delayed(const Duration(milliseconds: 300));
if (gid != null) {
final ok = await showConfirmDialogs(
context!, "确认取消下载?", const Text("你可能需要手动删除下载文件。"));
context!, "确认取消下载?", const Text("如果文件不再需要,你可能需要手动删除下载文件。"));
if (ok == true) {
await Aria2cManager.aria2c.remove(gid);
}

View File

@ -384,13 +384,11 @@ class ToolsUIModel extends BaseUIModel {
try {
final b64Str = base64Encode(btData.data!);
dPrint(b64Str);
final gid = await Aria2cManager.aria2c
.addTorrent(b64Str, extraParams: {"dir": savePath});
_working = false;
dPrint("Aria2cManager.aria2c.addUri resp === $gid");
await Aria2cManager.aria2c.saveSession();
await showToast(context!, "创建下载任务成功!");
BaseUIContainer(
uiCreate: () => DownloadsUI(),
modelCreate: () => DownloadsUIModel()).push(context!);