feat: add option to control whether to deleted task

This commit is contained in:
Simon Ding
2024-07-30 21:55:54 +08:00
parent 3525d1bb83
commit 769f217506
17 changed files with 402 additions and 102 deletions

View File

@@ -200,7 +200,8 @@ class DownloadClient {
String? url;
String? user;
String? password;
bool? removeCompletedDownloads;
bool? removeFailedDownloads;
DownloadClient(
{this.id,
this.enable,
@@ -208,7 +209,9 @@ class DownloadClient {
this.implementation,
this.url,
this.user,
this.password});
this.password,
this.removeCompletedDownloads,
this.removeFailedDownloads});
DownloadClient.fromJson(Map<String, dynamic> json) {
id = json['id'];
@@ -218,6 +221,8 @@ class DownloadClient {
url = json['url'];
user = json['user'];
password = json['password'];
removeCompletedDownloads = json["remove_completed_downloads"] ?? false;
removeFailedDownloads = json["remove_failed_downloads"] ?? false;
}
Map<String, dynamic> toJson() {
@@ -229,6 +234,8 @@ class DownloadClient {
data['url'] = url;
data['user'] = user;
data['password'] = password;
data["remove_completed_downloads"] = removeCompletedDownloads;
data["remove_failed_downloads"] = removeFailedDownloads;
return data;
}
}

View File

@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@@ -53,7 +55,9 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
"url": client.url,
"user": client.user,
"password": client.password,
"impl": "transmission"
"impl": "transmission",
"remove_completed_downloads": client.removeCompletedDownloads,
"remove_failed_downloads": client.removeFailedDownloads,
},
child: Column(
children: [
@@ -82,6 +86,12 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: FormBuilderValidators.required(),
),
FormBuilderSwitch(
name: "remove_completed_downloads",
title: const Text("任务完成后删除")),
FormBuilderSwitch(
name: "remove_failed_downloads",
title: const Text("任务失败后删除")),
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Column(
@@ -137,7 +147,9 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
implementation: values["impl"],
url: values["url"],
user: _enableAuth ? values["user"] : null,
password: _enableAuth ? values["password"] : null));
password: _enableAuth ? values["password"] : null,
removeCompletedDownloads: values["remove_completed_downloads"],
removeFailedDownloads: values["remove_failed_downloads"]));
} else {
throw "validation_error";
}