mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-12 19:33:41 +00:00
feat: support more configurations (#281)
This commit is contained in:
14 files changed
+145
-94
No files matched your search
@@ -30,6 +30,8 @@ class ProtocolConfig {
|
||||
|
||||
@JsonSerializable()
|
||||
class HttpConfig {
|
||||
String userAgent =
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36';
|
||||
int connections = 0;
|
||||
|
||||
HttpConfig();
|
||||
@@ -41,6 +43,7 @@ class HttpConfig {
|
||||
|
||||
@JsonSerializable()
|
||||
class BtConfig {
|
||||
int listenPort = 0;
|
||||
List<String> trackers = [];
|
||||
|
||||
BtConfig();
|
||||
|
||||
@@ -33,19 +33,23 @@ Map<String, dynamic> _$ProtocolConfigToJson(ProtocolConfig instance) =>
|
||||
'bt': instance.bt.toJson(),
|
||||
};
|
||||
|
||||
HttpConfig _$HttpConfigFromJson(Map<String, dynamic> json) =>
|
||||
HttpConfig()..connections = json['connections'] as int;
|
||||
HttpConfig _$HttpConfigFromJson(Map<String, dynamic> json) => HttpConfig()
|
||||
..userAgent = json['userAgent'] as String
|
||||
..connections = json['connections'] as int;
|
||||
|
||||
Map<String, dynamic> _$HttpConfigToJson(HttpConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'userAgent': instance.userAgent,
|
||||
'connections': instance.connections,
|
||||
};
|
||||
|
||||
BtConfig _$BtConfigFromJson(Map<String, dynamic> json) => BtConfig()
|
||||
..listenPort = json['listenPort'] as int
|
||||
..trackers =
|
||||
(json['trackers'] as List<dynamic>).map((e) => e as String).toList();
|
||||
|
||||
Map<String, dynamic> _$BtConfigToJson(BtConfig instance) => <String, dynamic>{
|
||||
'listenPort': instance.listenPort,
|
||||
'trackers': instance.trackers,
|
||||
};
|
||||
|
||||
|
||||
@@ -315,6 +315,7 @@ class AppController extends GetxController with WindowListener, TrayListener {
|
||||
result.addAll(trackers);
|
||||
} catch (e) {
|
||||
logger.w("subscribe trackers fail, url: $u", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
btExtConfig.subscribeTrackers.clear();
|
||||
|
||||
@@ -96,6 +96,24 @@ class SettingView extends GetView<SettingController> {
|
||||
|
||||
// http config items start
|
||||
final httpConfig = downloaderCfg.value.protocolConfig.http;
|
||||
final buildHttpUa =
|
||||
_buildConfigItem('User-Agent', () => httpConfig.userAgent, (Key key) {
|
||||
final uaController = TextEditingController(text: httpConfig.userAgent);
|
||||
uaController.addListener(() async {
|
||||
if (uaController.text.isNotEmpty &&
|
||||
uaController.text != httpConfig.userAgent) {
|
||||
httpConfig.userAgent = uaController.text;
|
||||
|
||||
await debounceSave();
|
||||
}
|
||||
});
|
||||
|
||||
return TextField(
|
||||
key: key,
|
||||
focusNode: FocusNode(),
|
||||
controller: uaController,
|
||||
);
|
||||
});
|
||||
final buildHttpConnections = _buildConfigItem(
|
||||
'connections', () => httpConfig.connections.toString(), (Key key) {
|
||||
final connectionsController =
|
||||
@@ -122,8 +140,32 @@ class SettingView extends GetView<SettingController> {
|
||||
});
|
||||
|
||||
// bt config items start
|
||||
final btConfig = downloaderCfg.value.protocolConfig.bt;
|
||||
final btExtConfig = downloaderCfg.value.extra.bt;
|
||||
final buildBtListenPort = _buildConfigItem(
|
||||
'port', () => btConfig.listenPort.toString(), (Key key) {
|
||||
final listenPortController =
|
||||
TextEditingController(text: btConfig.listenPort.toString());
|
||||
listenPortController.addListener(() async {
|
||||
if (listenPortController.text.isNotEmpty &&
|
||||
listenPortController.text != btConfig.listenPort.toString()) {
|
||||
btConfig.listenPort = int.parse(listenPortController.text);
|
||||
|
||||
await debounceSave();
|
||||
}
|
||||
});
|
||||
|
||||
return TextField(
|
||||
key: key,
|
||||
focusNode: FocusNode(),
|
||||
controller: listenPortController,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
NumericalRangeFormatter(min: 0, max: 65535),
|
||||
],
|
||||
);
|
||||
});
|
||||
final buildBtTrackerSubscribeUrls = _buildConfigItem(
|
||||
'subscribeTracker',
|
||||
() => 'items'.trParams(
|
||||
@@ -479,6 +521,7 @@ class SettingView extends GetView<SettingController> {
|
||||
Card(
|
||||
child: Column(
|
||||
children: _addDivider([
|
||||
buildHttpUa(),
|
||||
buildHttpConnections(),
|
||||
]),
|
||||
)),
|
||||
@@ -486,6 +529,7 @@ class SettingView extends GetView<SettingController> {
|
||||
Card(
|
||||
child: Column(
|
||||
children: _addDivider([
|
||||
buildBtListenPort(),
|
||||
buildBtTrackerSubscribeUrls(),
|
||||
buildBtTrackers(),
|
||||
]),
|
||||
|
||||
Reference in new issue
Block a user