From 45946ddc1a3fc67ffb0af14b390ee12b61da1217 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Wed, 19 Oct 2022 19:29:05 +0200 Subject: [PATCH] Added cache config dns --- lib/l10n/app_en.arb | 11 +- lib/l10n/app_es.arb | 11 +- lib/screens/settings/dns/cache_config.dart | 119 +++++++++++++++++++++ lib/screens/settings/dns/dns.dart | 13 +++ 4 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 lib/screens/settings/dns/cache_config.dart diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4b13044..5c202ab 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -453,5 +453,14 @@ "nullIp": "Null IP", "nullIpDescription": "Respond with zero IP address (0.0.0.0 for A; :: for AAAA)", "customIp": "Custom IP", - "customIpDescription": "Respond with a manually set IP address" + "customIpDescription": "Respond with a manually set IP address", + "dnsCacheConfig": "DNS cache configuration", + "cacheSize": "Cache size", + "inBytes": "In bytes", + "overrideMinimumTtl": "Override minimum TTL", + "overrideMinimumTtlDescription": "Extend short time-to-live values (seconds) received from the upstream server when caching DNS responses.", + "overrideMaximumTtl": "Override maximum TTL", + "overrideMaximumTtlDescription": "Set a maximum time-to-live value (seconds) for entries in the DNS cache.", + "optimisticCaching": "Optimistic caching", + "optimisticCachingDescription": "Make AdGuard Home respond from the cache even when the entries are expired and also try to refresh them." } \ No newline at end of file diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index c5f138e..e590707 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -453,5 +453,14 @@ "nullIp": "IP nula", "nullIpDescription": "Responde con dirección IP cero (0.0.0.0 para A; :: para AAAA)", "customIp": "IP personalizada", - "customIpDescription": "Responde con una dirección IP establecida manualmente." + "customIpDescription": "Responde con una dirección IP establecida manualmente.", + "dnsCacheConfig": "Configuración de la caché DNS", + "cacheSize": "Tamaño de la caché", + "inBytes": "En bytes", + "overrideMinimumTtl": "Anular TTL mínimo", + "overrideMinimumTtlDescription": "Amplía el corto tiempo de vida (segundos) de los valores recibidos del servidor DNS de subida al almacenar en caché las respuestas DNS.", + "overrideMaximumTtl": "Anular TTL máximo", + "overrideMaximumTtlDescription": "Establece un valor de tiempo de vida (segundos) máximo para las entradas en la caché DNS.", + "optimisticCaching": "Optimistic caching", + "optimisticCachingDescription": "Haz que AdGuard Home responda desde la caché incluso cuando las entradas estén expiradas y también intente actualizarlas." } \ No newline at end of file diff --git a/lib/screens/settings/dns/cache_config.dart b/lib/screens/settings/dns/cache_config.dart new file mode 100644 index 0000000..253a96f --- /dev/null +++ b/lib/screens/settings/dns/cache_config.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart'; + +class CacheConfigDnsScreen extends StatefulWidget { + const CacheConfigDnsScreen({Key? key}) : super(key: key); + + @override + State createState() => _CacheConfigDnsScreenState(); +} + +class _CacheConfigDnsScreenState extends State { + final TextEditingController cacheSizeController = TextEditingController(); + String? cacheSizeError; + + final TextEditingController overrideMinTtlController = TextEditingController(); + String? overrideMinTtlError; + + final TextEditingController overrideMaxTtlController = TextEditingController(); + String? overrideMaxTtlError; + + bool optimisticCache = false; + + @override + Widget build(BuildContext context) { + + Widget numericField({ + required TextEditingController controller, + required String label, + String? helper, + String? error, + required void Function(String) onChanged, + }) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: TextFormField( + controller: overrideMinTtlController, + onChanged: onChanged, + decoration: InputDecoration( + prefixIcon: const Icon(Icons.timer_rounded), + border: const OutlineInputBorder( + borderRadius: BorderRadius.all( + Radius.circular(10) + ) + ), + errorText: error, + helperText: helper, + helperMaxLines: 10, + labelText: label, + ), + keyboardType: TextInputType.number, + ), + ); + } + + return Scaffold( + appBar: AppBar( + title: Text(AppLocalizations.of(context)!.dnsCacheConfig), + ), + body: ListView( + padding: const EdgeInsets.only(top: 10), + children: [ + numericField( + controller: cacheSizeController, + label: AppLocalizations.of(context)!.cacheSize, + helper: AppLocalizations.of(context)!.inBytes, + error: cacheSizeError, + onChanged: (value) { + if (int.tryParse(value) != null) { + setState(() => cacheSizeError = null); + } + else { + setState(() => cacheSizeError = AppLocalizations.of(context)!.valueNotNumber); + } + } + ), + const SizedBox(height: 30), + numericField( + controller: overrideMinTtlController, + label: AppLocalizations.of(context)!.overrideMinimumTtl, + helper: AppLocalizations.of(context)!.overrideMinimumTtlDescription, + error: overrideMinTtlError, + onChanged: (value) { + if (int.tryParse(value) != null) { + setState(() => overrideMinTtlError = null); + } + else { + setState(() => overrideMinTtlError = AppLocalizations.of(context)!.valueNotNumber); + } + } + ), + const SizedBox(height: 30), + numericField( + controller: overrideMaxTtlController, + label: AppLocalizations.of(context)!.overrideMaximumTtl, + helper: AppLocalizations.of(context)!.overrideMaximumTtlDescription, + error: overrideMaxTtlError, + onChanged: (value) { + if (int.tryParse(value) != null) { + setState(() => overrideMaxTtlError = null); + } + else { + setState(() => overrideMaxTtlError = AppLocalizations.of(context)!.valueNotNumber); + } + } + ), + const SizedBox(height: 10), + CustomSwitchListTile( + value: optimisticCache, + onChanged: (value) => setState(() => optimisticCache = value), + title: AppLocalizations.of(context)!.optimisticCaching, + subtitle: AppLocalizations.of(context)!.optimisticCachingDescription, + ) + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/screens/settings/dns/dns.dart b/lib/screens/settings/dns/dns.dart index f9ee4f5..0446b4c 100644 --- a/lib/screens/settings/dns/dns.dart +++ b/lib/screens/settings/dns/dns.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:adguard_home_manager/screens/settings/dns/cache_config.dart'; import 'package:adguard_home_manager/screens/settings/dns/dns_server_settings.dart'; import 'package:adguard_home_manager/screens/settings/dns/bootstrap_dns.dart'; import 'package:adguard_home_manager/screens/settings/dns/private_reverse_servers.dart'; @@ -65,6 +66,18 @@ class DnsSettings extends StatelessWidget { builder: (context) => const DnsServerSettingsScreen() )), ), + ListTile( + title: Text( + AppLocalizations.of(context)!.dnsCacheConfig, + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.normal + ), + ), + onTap: () => Navigator.push(context, MaterialPageRoute( + builder: (context) => const CacheConfigDnsScreen() + )), + ), ], ), );