feat: add config for auto-torrent (#1219)

This commit is contained in:
Copilot authored and GitHub committed 2026-01-22 22:18:34 +08:00
1 parent a3c1f84c2c
commit 7b840b4261
31 files changed
+742 -131

No files matched your search

@@ -26,7 +26,7 @@ class CreateController extends GetxController
@override
void onInit() {
super.onInit();
advancedTabController = TabController(length: 3, vsync: this);
advancedTabController = TabController(length: 2, vsync: this);
directDownload.value = Get.find<AppController>()
.downloaderConfig
.value
@@ -62,6 +62,8 @@ class CreateView extends GetView<CreateController> {
final _availableSchemes = ["http:", "https:", "magnet:"];
final _skipVerifyCertController = false.obs;
final _autoTorrentController = Rxn<bool>();
final _deleteTorrentAfterDownloadController = Rxn<bool>();
final _autoExtractController = Rxn<bool>();
final _deleteAfterExtractController = Rxn<bool>();
@@ -81,11 +83,6 @@ class CreateView extends GetView<CreateController> {
final downloadDir = appController.downloaderConfig.value.downloadDir;
_pathController.text = renderPathPlaceholders(downloadDir);
}
// Initialize archive settings from global config if not already set
_autoExtractController.value ??=
appController.downloaderConfig.value.archive.autoExtract;
_deleteAfterExtractController.value ??=
appController.downloaderConfig.value.archive.deleteAfterExtract;
// Handle pending create task from deep link
final CreateTask? routerParams = Get.rootDelegate.arguments();
@@ -509,20 +506,17 @@ class CreateView extends GetView<CreateController> {
const Divider(),
TabBar(
controller: controller.advancedTabController,
tabs: [
const Tab(
tabs: const [
Tab(
text: 'HTTP',
),
const Tab(
Tab(
text: 'BitTorrent',
),
Tab(
text: 'archives'.tr,
)
],
),
DefaultTabController(
length: 3,
length: 2,
child: ContentSizeTabBarView(
controller:
controller.advancedTabController,
@@ -605,21 +599,52 @@ class CreateView extends GetView<CreateController> {
),
),
),
],
),
Column(
children: [
TextFormField(
controller: _btTrackerController,
maxLines: 5,
decoration: InputDecoration(
labelText: 'Trackers',
hintText: 'addTrackerHit'.tr,
)),
],
),
Column(
children: [
// AutoTorrent options
Padding(
padding:
const EdgeInsets.only(top: 10),
child: CompactCheckbox(
label: 'autoTorrentEnable'.tr,
value: _autoTorrentController
.value ??
false,
onChanged: (bool? value) {
_autoTorrentController.value =
value ?? false;
},
textStyle: const TextStyle(
color: Colors.grey,
),
),
),
Obx(
() => Visibility(
visible: _autoTorrentController
.value ??
false,
child: Padding(
padding: const EdgeInsets.only(
top: 10, left: 20),
child: CompactCheckbox(
label:
'autoTorrentDeleteAfterDownload'
.tr,
value:
_deleteTorrentAfterDownloadController
.value ??
false,
onChanged: (bool? value) {
_deleteTorrentAfterDownloadController
.value = value ?? false;
},
textStyle: const TextStyle(
color: Colors.grey,
),
),
),
),
),
// AutoExtract options
Padding(
padding:
const EdgeInsets.only(top: 10),
@@ -647,7 +672,7 @@ class CreateView extends GetView<CreateController> {
Padding(
padding:
const EdgeInsets.only(
top: 10),
top: 10, left: 20),
child: TextFormField(
controller:
_archivePasswordController,
@@ -666,7 +691,7 @@ class CreateView extends GetView<CreateController> {
Padding(
padding:
const EdgeInsets.only(
top: 10),
top: 10, left: 20),
child: CompactCheckbox(
label:
'deleteAfterExtract'
@@ -691,7 +716,18 @@ class CreateView extends GetView<CreateController> {
),
),
],
)
),
Column(
children: [
TextFormField(
controller: _btTrackerController,
maxLines: 5,
decoration: InputDecoration(
labelText: 'Trackers',
hintText: 'addTrackerHit'.tr,
)),
],
),
],
),
)
@@ -892,8 +928,9 @@ class CreateView extends GetView<CreateController> {
Object? parseReqOptsExtra() {
return OptsExtraHttp()
..connections = int.tryParse(_connectionsController.text) ?? 0
..autoTorrent = true
..autoExtract = _autoExtractController.value ?? false
..autoTorrent = _autoTorrentController.value
..deleteTorrentAfterDownload = _deleteTorrentAfterDownloadController.value
..autoExtract = _autoExtractController.value
..archivePassword = _archivePasswordController.text
..deleteAfterExtract = _deleteAfterExtractController.value ?? false;
}
@@ -169,19 +169,19 @@ class SettingView extends GetView<SettingController> {
);
});
// New: Auto Delete Torrents
final buildAutoDeleteTorrents = _buildConfigItem('autoDeleteTorrents', () {
return appController.downloaderConfig.value.autoDeleteTorrents
// AutoTorrent: Enable auto create BT tasks from .torrent files
final buildAutoTorrentEnable = _buildConfigItem('autoTorrentEnable', () {
return appController.downloaderConfig.value.autoTorrent.enable
? 'on'.tr
: 'off'.tr;
}, (Key key) {
return Container(
alignment: Alignment.centerLeft,
child: Switch(
value: appController.downloaderConfig.value.autoDeleteTorrents,
value: appController.downloaderConfig.value.autoTorrent.enable,
onChanged: (bool value) async {
appController.downloaderConfig.update((val) {
val!.autoDeleteTorrents = value;
val!.autoTorrent.enable = value;
});
await debounceSave();
},
@@ -189,19 +189,44 @@ class SettingView extends GetView<SettingController> {
);
});
// New: Auto Clean Missing Files
final buildAutoCleanMissingFiles = _buildConfigItem('autoCleanMissingFiles', () {
return appController.downloaderConfig.value.autoCleanMissingFiles
// AutoTorrent: Delete .torrent file after BT task creation
final buildAutoTorrentDeleteAfterDownload =
_buildConfigItem('autoTorrentDeleteAfterDownload', () {
return appController
.downloaderConfig.value.autoTorrent.deleteAfterDownload
? 'on'.tr
: 'off'.tr;
}, (Key key) {
return Container(
alignment: Alignment.centerLeft,
child: Switch(
value: appController.downloaderConfig.value.autoCleanMissingFiles,
value: appController
.downloaderConfig.value.autoTorrent.deleteAfterDownload,
onChanged: (bool value) async {
appController.downloaderConfig.update((val) {
val!.autoCleanMissingFiles = value;
val!.autoTorrent.deleteAfterDownload = value;
});
await debounceSave();
},
),
);
});
// New: Auto Delete Missing File Tasks
final buildAutoDeleteMissingFileTasks =
_buildConfigItem('autoDeleteMissingFileTasks', () {
return appController.downloaderConfig.value.autoDeleteMissingFileTasks
? 'on'.tr
: 'off'.tr;
}, (Key key) {
return Container(
alignment: Alignment.centerLeft,
child: Switch(
value:
appController.downloaderConfig.value.autoDeleteMissingFileTasks,
onChanged: (bool value) async {
appController.downloaderConfig.update((val) {
val!.autoDeleteMissingFileTasks = value;
});
await debounceSave();
},
@@ -1454,8 +1479,13 @@ class SettingView extends GetView<SettingController> {
buildMaxRunning(),
buildDefaultDirectDownload(),
buildAutoStartTasks(),
buildAutoDeleteTorrents(),
buildAutoCleanMissingFiles(),
buildAutoTorrentEnable(),
Obx(() => Visibility(
visible: appController.downloaderConfig.value
.autoTorrent.enable,
child: buildAutoTorrentDeleteAfterDownload(),
)),
buildAutoDeleteMissingFileTasks(),
buildBrowserExtension(),
buildAutoStartup(),
buildMenubarMode(),
@@ -1466,7 +1496,11 @@ class SettingView extends GetView<SettingController> {
child: Column(
children: _addDivider([
buildAutoExtract(),
buildDeleteAfterExtract(),
Obx(() => Visibility(
visible: appController.downloaderConfig.value
.archive.autoExtract,
child: buildDeleteAfterExtract(),
)),
]),
)),
const Text('HTTP'),
@@ -1990,4 +2024,4 @@ extension ProxyMode on ProxyConfig {
break;
}
}
}
}