LCOV - code coverage report
Current view: top level - lib/views - torstatusview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 115 0.0 %
Date: 2024-08-22 16:58:37 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/cwtch_icons_icons.dart';
       2             : import 'package:cwtch/settings.dart';
       3             : import 'package:cwtch/widgets/textfield.dart';
       4             : import 'package:flutter/material.dart';
       5             : import 'package:cwtch/torstatus.dart';
       6             : import 'package:cwtch/widgets/tor_icon.dart';
       7             : import 'package:provider/provider.dart';
       8             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
       9             : 
      10             : import '../main.dart';
      11             : import 'globalsettingsview.dart';
      12             : 
      13             : /// Tor Status View provides all info on Tor network state and the (future) ability to configure the network in a variety
      14             : /// of ways (restart, enable bridges, enable pluggable transports etc)
      15             : class TorStatusView extends StatefulWidget {
      16           0 :   @override
      17           0 :   _TorStatusView createState() => _TorStatusView();
      18             : }
      19             : 
      20             : class _TorStatusView extends State<TorStatusView> {
      21             :   TextEditingController torSocksPortController = TextEditingController();
      22             :   TextEditingController torControlPortController = TextEditingController();
      23             :   TextEditingController torConfigController = TextEditingController();
      24             :   ScrollController torScrollContoller = ScrollController();
      25             : 
      26           0 :   @override
      27             :   void dispose() {
      28           0 :     super.dispose();
      29             :   }
      30             : 
      31           0 :   @override
      32             :   Widget build(BuildContext context) {
      33           0 :     return Scaffold(
      34           0 :       backgroundColor: Provider.of<Settings>(context).theme.backgroundMainColor,
      35           0 :       appBar: AppBar(
      36           0 :         title: Text(AppLocalizations.of(context)!.torNetworkStatus),
      37             :       ),
      38           0 :       body: _buildSettingsList(),
      39             :     );
      40             :   }
      41             : 
      42           0 :   Widget _buildSettingsList() {
      43           0 :     return Consumer<Settings>(builder: (
      44             :       context,
      45             :       settings,
      46             :       child,
      47             :     ) {
      48             :       // We don't want these to update on edit...only on construction...
      49           0 :       if (torSocksPortController.text.isEmpty) {
      50           0 :         torConfigController.text = settings.torConfig;
      51           0 :         torSocksPortController.text = settings.socksPort.toString();
      52           0 :         torControlPortController.text = settings.controlPort.toString();
      53             :       }
      54           0 :       return Consumer<TorStatus>(builder: (context, torStatus, child) {
      55           0 :         return LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
      56           0 :           return Scrollbar(
      57             :               trackVisibility: true,
      58           0 :               controller: torScrollContoller,
      59           0 :               child: SingleChildScrollView(
      60             :                   clipBehavior: Clip.antiAlias,
      61           0 :                   child: ConstrainedBox(
      62           0 :                       constraints: BoxConstraints(
      63           0 :                         minHeight: viewportConstraints.maxHeight,
      64             :                       ),
      65           0 :                       child: Column(children: [
      66           0 :                         ListTile(
      67           0 :                           leading: TorIcon(),
      68           0 :                           title: Text(AppLocalizations.of(context)!.torStatus),
      69           0 :                           subtitle: Text(torStatus.progress == 100 ? AppLocalizations.of(context)!.networkStatusOnline : torStatus.status),
      70           0 :                           trailing: ElevatedButton(
      71           0 :                             child: Text(AppLocalizations.of(context)!.resetTor),
      72           0 :                             onPressed: () {
      73           0 :                               Provider.of<FlwtchState>(context, listen: false).cwtch.ResetTor();
      74             :                             },
      75             :                           ),
      76             :                         ),
      77           0 :                         ListTile(
      78           0 :                           title: Text(AppLocalizations.of(context)!.torVersion),
      79           0 :                           subtitle: SelectableText(torStatus.version),
      80           0 :                           leading: Icon(CwtchIcons.info_24px, color: settings.current().mainTextColor),
      81             :                         ),
      82           0 :                         SwitchListTile(
      83           0 :                           title: Text(AppLocalizations.of(context)!.torSettingsEnableCache),
      84           0 :                           subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledCacheDescription),
      85           0 :                           value: settings.useTorCache,
      86           0 :                           onChanged: (bool value) {
      87           0 :                             settings.useTorCache = value;
      88           0 :                             saveSettings(context);
      89             :                           },
      90           0 :                           activeTrackColor: settings.theme.defaultButtonColor,
      91           0 :                           inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
      92           0 :                           secondary: Icon(Icons.cached, color: settings.current().mainTextColor),
      93             :                         ),
      94           0 :                         SwitchListTile(
      95           0 :                           title: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvanced),
      96           0 :                           subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvancedDescription),
      97           0 :                           value: settings.allowAdvancedTorConfig,
      98           0 :                           onChanged: (bool value) {
      99           0 :                             settings.allowAdvancedTorConfig = value;
     100           0 :                             saveSettings(context);
     101             :                           },
     102           0 :                           activeTrackColor: settings.theme.defaultButtonColor,
     103           0 :                           inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     104           0 :                           secondary: Icon(CwtchIcons.settings_24px, color: settings.current().mainTextColor),
     105             :                         ),
     106           0 :                         Visibility(
     107           0 :                             visible: settings.allowAdvancedTorConfig,
     108           0 :                             child: Column(children: [
     109           0 :                               ListTile(
     110           0 :                                   title: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPort),
     111           0 :                                   subtitle: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPortDescription),
     112           0 :                                   leading: Icon(CwtchIcons.swap_horiz_24px, color: settings.current().mainTextColor),
     113           0 :                                   trailing: Container(
     114           0 :                                       width: MediaQuery.of(context).size.width / 4,
     115           0 :                                       child: CwtchTextField(
     116             :                                         number: true,
     117           0 :                                         controller: torSocksPortController,
     118           0 :                                         validator: (value) {
     119             :                                           try {
     120           0 :                                             var port = int.parse(value);
     121           0 :                                             if (port > 0 && port < 65536) {
     122             :                                               return null;
     123             :                                             } else {
     124           0 :                                               return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     125             :                                             }
     126             :                                           } catch (e) {
     127           0 :                                             return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     128             :                                           }
     129             :                                         },
     130           0 :                                         onChanged: (String socksPort) {
     131             :                                           try {
     132           0 :                                             var port = int.parse(socksPort);
     133           0 :                                             if (port > 0 && port < 65536) {
     134           0 :                                               settings.socksPort = int.parse(socksPort);
     135           0 :                                               saveSettings(context);
     136             :                                             }
     137             :                                           } catch (e) {}
     138             :                                         },
     139             :                                       ))),
     140           0 :                               ListTile(
     141           0 :                                   title: Text(AppLocalizations.of(context)!.torSettingsCustomControlPort),
     142           0 :                                   subtitle: Text(AppLocalizations.of(context)!.torSettingsCustomControlPortDescription),
     143           0 :                                   leading: Icon(CwtchIcons.swap_horiz_24px, color: settings.current().mainTextColor),
     144           0 :                                   trailing: Container(
     145           0 :                                       width: MediaQuery.of(context).size.width / 4,
     146           0 :                                       child: CwtchTextField(
     147             :                                         number: true,
     148           0 :                                         controller: torControlPortController,
     149           0 :                                         validator: (value) {
     150             :                                           try {
     151           0 :                                             var port = int.parse(value);
     152           0 :                                             if (port > 0 && port < 65536) {
     153             :                                               return null;
     154             :                                             } else {
     155           0 :                                               return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     156             :                                             }
     157             :                                           } catch (e) {
     158           0 :                                             return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     159             :                                           }
     160             :                                         },
     161           0 :                                         onChanged: (String controlPort) {
     162             :                                           try {
     163           0 :                                             var port = int.parse(controlPort);
     164           0 :                                             if (port > 0 && port < 65536) {
     165           0 :                                               settings.controlPort = int.parse(controlPort);
     166           0 :                                               saveSettings(context);
     167             :                                             }
     168             :                                           } catch (e) {}
     169             :                                         },
     170             :                                       ))),
     171           0 :                               SwitchListTile(
     172           0 :                                 title: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfiguration, style: TextStyle(color: settings.current().mainTextColor)),
     173           0 :                                 subtitle: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfigurastionDescription),
     174           0 :                                 value: settings.useCustomTorConfig,
     175           0 :                                 onChanged: (bool value) {
     176           0 :                                   settings.useCustomTorConfig = value;
     177           0 :                                   saveSettings(context);
     178             :                                 },
     179           0 :                                 activeTrackColor: settings.theme.defaultButtonColor,
     180           0 :                                 inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     181           0 :                                 secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
     182             :                               ),
     183           0 :                               Visibility(
     184           0 :                                   visible: settings.useCustomTorConfig,
     185           0 :                                   child: Padding(
     186           0 :                                       padding: EdgeInsets.all(5),
     187           0 :                                       child: CwtchTextField(
     188           0 :                                         controller: torConfigController,
     189             :                                         multiLine: true,
     190           0 :                                         onChanged: (torConfig) {
     191           0 :                                           settings.torConfig = torConfig;
     192           0 :                                           saveSettings(context);
     193             :                                         },
     194             :                                       )))
     195             :                             ]))
     196             :                       ]))));
     197             :         });
     198             :       });
     199             :     });
     200             :   }
     201             : }

Generated by: LCOV version 1.14