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 : appBar: AppBar(
35 0 : title: Text(AppLocalizations.of(context)!.torNetworkStatus),
36 : ),
37 0 : body: _buildSettingsList(),
38 : );
39 : }
40 :
41 0 : Widget _buildSettingsList() {
42 0 : return Consumer<Settings>(builder: (
43 : context,
44 : settings,
45 : child,
46 : ) {
47 : // We don't want these to update on edit...only on construction...
48 0 : if (torSocksPortController.text.isEmpty) {
49 0 : torConfigController.text = settings.torConfig;
50 0 : torSocksPortController.text = settings.socksPort.toString();
51 0 : torControlPortController.text = settings.controlPort.toString();
52 : }
53 0 : return Consumer<TorStatus>(builder: (context, torStatus, child) {
54 0 : return LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
55 0 : return Scrollbar(
56 : trackVisibility: true,
57 0 : controller: torScrollContoller,
58 0 : child: SingleChildScrollView(
59 : clipBehavior: Clip.antiAlias,
60 0 : child: ConstrainedBox(
61 0 : constraints: BoxConstraints(
62 0 : minHeight: viewportConstraints.maxHeight,
63 : ),
64 0 : child: Column(children: [
65 0 : ListTile(
66 0 : leading: TorIcon(),
67 0 : title: Text(AppLocalizations.of(context)!.torStatus),
68 0 : subtitle: Text(torStatus.progress == 100 ? AppLocalizations.of(context)!.networkStatusOnline : torStatus.status),
69 0 : trailing: ElevatedButton(
70 0 : child: Text(AppLocalizations.of(context)!.resetTor),
71 0 : onPressed: () {
72 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ResetTor();
73 : },
74 : ),
75 : ),
76 0 : ListTile(
77 0 : title: Text(AppLocalizations.of(context)!.torVersion),
78 0 : subtitle: SelectableText(torStatus.version),
79 0 : leading: Icon(CwtchIcons.info_24px, color: settings.current().mainTextColor),
80 : ),
81 0 : SwitchListTile(
82 0 : title: Text(AppLocalizations.of(context)!.torSettingsEnableCache),
83 0 : subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledCacheDescription),
84 0 : value: settings.useTorCache,
85 0 : onChanged: (bool value) {
86 0 : settings.useTorCache = value;
87 0 : saveSettings(context);
88 : },
89 0 : activeTrackColor: settings.theme.defaultButtonColor,
90 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
91 0 : secondary: Icon(Icons.cached, color: settings.current().mainTextColor),
92 : ),
93 0 : SwitchListTile(
94 0 : title: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvanced),
95 0 : subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvancedDescription),
96 0 : value: settings.allowAdvancedTorConfig,
97 0 : onChanged: (bool value) {
98 0 : settings.allowAdvancedTorConfig = value;
99 0 : saveSettings(context);
100 : },
101 0 : activeTrackColor: settings.theme.defaultButtonColor,
102 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
103 0 : secondary: Icon(CwtchIcons.settings_24px, color: settings.current().mainTextColor),
104 : ),
105 0 : Visibility(
106 0 : visible: settings.allowAdvancedTorConfig,
107 0 : child: Column(children: [
108 0 : ListTile(
109 0 : title: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPort),
110 0 : subtitle: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPortDescription),
111 0 : leading: Icon(CwtchIcons.swap_horiz_24px, color: settings.current().mainTextColor),
112 0 : trailing: Container(
113 0 : width: MediaQuery.of(context).size.width / 4,
114 0 : child: CwtchTextField(
115 : number: true,
116 0 : controller: torSocksPortController,
117 0 : validator: (value) {
118 : try {
119 0 : var port = int.parse(value);
120 0 : if (port > 0 && port < 65536) {
121 : return null;
122 : } else {
123 0 : return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
124 : }
125 : } catch (e) {
126 0 : return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
127 : }
128 : },
129 0 : onChanged: (String socksPort) {
130 : try {
131 0 : var port = int.parse(socksPort);
132 0 : if (port > 0 && port < 65536) {
133 0 : settings.socksPort = int.parse(socksPort);
134 0 : saveSettings(context);
135 : }
136 : } catch (e) {}
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 0 : SwitchListTile(
171 0 : title: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfiguration, style: TextStyle(color: settings.current().mainTextColor)),
172 0 : subtitle: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfigurastionDescription),
173 0 : value: settings.useCustomTorConfig,
174 0 : onChanged: (bool value) {
175 0 : settings.useCustomTorConfig = value;
176 0 : saveSettings(context);
177 : },
178 0 : activeTrackColor: settings.theme.defaultButtonColor,
179 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
180 0 : secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
181 : ),
182 0 : Visibility(
183 0 : visible: settings.useCustomTorConfig,
184 0 : child: Padding(
185 0 : padding: EdgeInsets.all(5),
186 0 : child: CwtchTextField(
187 0 : controller: torConfigController,
188 : multiLine: true,
189 0 : onChanged: (torConfig) {
190 0 : settings.torConfig = torConfig;
191 0 : saveSettings(context);
192 : },
193 : )))
194 : ]))
195 : ]))));
196 : });
197 : });
198 : });
199 : }
200 : }
|