LCOV - code coverage report
Current view: top level - lib/views - torstatusview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 118 0.0 %
Date: 2026-07-15 19:28:30 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:cwtch/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(title: Text(AppLocalizations.of(context)!.torNetworkStatus)),
      36           0 :       body: _buildSettingsList(),
      37             :     );
      38             :   }
      39             : 
      40           0 :   Widget _buildSettingsList() {
      41           0 :     return Consumer<Settings>(
      42           0 :       builder: (context, settings, child) {
      43             :         // We don't want these to update on edit...only on construction...
      44           0 :         if (torSocksPortController.text.isEmpty) {
      45           0 :           torConfigController.text = settings.torConfig;
      46           0 :           torSocksPortController.text = settings.socksPort.toString();
      47           0 :           torControlPortController.text = settings.controlPort.toString();
      48             :         }
      49           0 :         return Consumer<TorStatus>(
      50           0 :           builder: (context, torStatus, child) {
      51           0 :             return LayoutBuilder(
      52           0 :               builder: (BuildContext context, BoxConstraints viewportConstraints) {
      53           0 :                 return Scrollbar(
      54             :                   trackVisibility: true,
      55           0 :                   controller: torScrollContoller,
      56           0 :                   child: SingleChildScrollView(
      57             :                     clipBehavior: Clip.antiAlias,
      58           0 :                     child: ConstrainedBox(
      59           0 :                       constraints: BoxConstraints(minHeight: viewportConstraints.maxHeight),
      60           0 :                       child: Column(
      61           0 :                         children: [
      62           0 :                           ListTile(
      63           0 :                             leading: TorIcon(),
      64           0 :                             title: Text(AppLocalizations.of(context)!.torStatus),
      65           0 :                             subtitle: Text(torStatus.progress == 100 ? AppLocalizations.of(context)!.networkStatusOnline : torStatus.status),
      66           0 :                             trailing: ElevatedButton(
      67           0 :                               child: Text(AppLocalizations.of(context)!.resetTor),
      68           0 :                               onPressed: () {
      69           0 :                                 Provider.of<FlwtchState>(context, listen: false).cwtch.ResetTor();
      70             :                               },
      71             :                             ),
      72             :                           ),
      73           0 :                           ListTile(
      74           0 :                             title: Text(AppLocalizations.of(context)!.torVersion),
      75           0 :                             subtitle: SelectableText(torStatus.version),
      76           0 :                             leading: Icon(CwtchIcons.info_24px, color: settings.current().mainTextColor),
      77             :                           ),
      78           0 :                           SwitchListTile(
      79           0 :                             title: Text(AppLocalizations.of(context)!.torSettingsEnableCache),
      80           0 :                             subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledCacheDescription),
      81           0 :                             value: settings.useTorCache,
      82           0 :                             onChanged: (bool value) {
      83           0 :                               settings.useTorCache = value;
      84           0 :                               saveSettings(context);
      85             :                             },
      86           0 :                             activeTrackColor: settings.theme.defaultButtonColor,
      87           0 :                             inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
      88           0 :                             secondary: Icon(Icons.cached, color: settings.current().mainTextColor),
      89             :                           ),
      90           0 :                           SwitchListTile(
      91           0 :                             title: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvanced),
      92           0 :                             subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvancedDescription),
      93           0 :                             value: settings.allowAdvancedTorConfig,
      94           0 :                             onChanged: (bool value) {
      95           0 :                               settings.allowAdvancedTorConfig = value;
      96           0 :                               saveSettings(context);
      97             :                             },
      98           0 :                             activeTrackColor: settings.theme.defaultButtonColor,
      99           0 :                             inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     100           0 :                             secondary: Icon(CwtchIcons.settings_24px, color: settings.current().mainTextColor),
     101             :                           ),
     102           0 :                           Visibility(
     103           0 :                             visible: settings.allowAdvancedTorConfig,
     104           0 :                             child: Column(
     105           0 :                               children: [
     106           0 :                                 ListTile(
     107           0 :                                   title: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPort),
     108           0 :                                   subtitle: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPortDescription),
     109           0 :                                   leading: Icon(CwtchIcons.swap_horiz_24px, color: settings.current().mainTextColor),
     110           0 :                                   trailing: Container(
     111           0 :                                     width: MediaQuery.of(context).size.width / 4,
     112           0 :                                     child: CwtchTextField(
     113             :                                       number: true,
     114           0 :                                       controller: torSocksPortController,
     115           0 :                                       validator: (value) {
     116             :                                         try {
     117           0 :                                           var port = int.parse(value);
     118           0 :                                           if (port > 0 && port < 65536) {
     119             :                                             return null;
     120             :                                           } else {
     121           0 :                                             return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     122             :                                           }
     123             :                                         } catch (e) {
     124           0 :                                           return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     125             :                                         }
     126             :                                       },
     127           0 :                                       onChanged: (String socksPort) {
     128             :                                         try {
     129           0 :                                           var port = int.parse(socksPort);
     130           0 :                                           if (port > 0 && port < 65536) {
     131           0 :                                             settings.socksPort = int.parse(socksPort);
     132           0 :                                             saveSettings(context);
     133             :                                           }
     134             :                                         } catch (e) {}
     135             :                                       },
     136             :                                     ),
     137             :                                   ),
     138             :                                 ),
     139           0 :                                 ListTile(
     140           0 :                                   title: Text(AppLocalizations.of(context)!.torSettingsCustomControlPort),
     141           0 :                                   subtitle: Text(AppLocalizations.of(context)!.torSettingsCustomControlPortDescription),
     142           0 :                                   leading: Icon(CwtchIcons.swap_horiz_24px, color: settings.current().mainTextColor),
     143           0 :                                   trailing: Container(
     144           0 :                                     width: MediaQuery.of(context).size.width / 4,
     145           0 :                                     child: CwtchTextField(
     146             :                                       number: true,
     147           0 :                                       controller: torControlPortController,
     148           0 :                                       validator: (value) {
     149             :                                         try {
     150           0 :                                           var port = int.parse(value);
     151           0 :                                           if (port > 0 && port < 65536) {
     152             :                                             return null;
     153             :                                           } else {
     154           0 :                                             return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     155             :                                           }
     156             :                                         } catch (e) {
     157           0 :                                           return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
     158             :                                         }
     159             :                                       },
     160           0 :                                       onChanged: (String controlPort) {
     161             :                                         try {
     162           0 :                                           var port = int.parse(controlPort);
     163           0 :                                           if (port > 0 && port < 65536) {
     164           0 :                                             settings.controlPort = int.parse(controlPort);
     165           0 :                                             saveSettings(context);
     166             :                                           }
     167             :                                         } catch (e) {}
     168             :                                       },
     169             :                                     ),
     170             :                                   ),
     171             :                                 ),
     172           0 :                                 SwitchListTile(
     173           0 :                                   title: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfiguration, style: TextStyle(color: settings.current().mainTextColor)),
     174           0 :                                   subtitle: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfigurastionDescription),
     175           0 :                                   value: settings.useCustomTorConfig,
     176           0 :                                   onChanged: (bool value) {
     177           0 :                                     settings.useCustomTorConfig = value;
     178           0 :                                     saveSettings(context);
     179             :                                   },
     180           0 :                                   activeTrackColor: settings.theme.defaultButtonColor,
     181           0 :                                   inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     182           0 :                                   secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
     183             :                                 ),
     184           0 :                                 Visibility(
     185           0 :                                   visible: settings.useCustomTorConfig,
     186           0 :                                   child: Padding(
     187           0 :                                     padding: EdgeInsets.all(5),
     188           0 :                                     child: CwtchTextField(
     189           0 :                                       controller: torConfigController,
     190             :                                       multiLine: true,
     191           0 :                                       onChanged: (torConfig) {
     192           0 :                                         settings.torConfig = torConfig;
     193           0 :                                         saveSettings(context);
     194             :                                       },
     195             :                                     ),
     196             :                                   ),
     197             :                                 ),
     198             :                               ],
     199             :                             ),
     200             :                           ),
     201             :                         ],
     202             :                       ),
     203             :                     ),
     204             :                   ),
     205             :                 );
     206             :               },
     207             :             );
     208             :           },
     209             :         );
     210             :       },
     211             :     );
     212             :   }
     213             : }

Generated by: LCOV version 1.14