2022-01-12 22:03:56 +00:00
|
|
|
import 'package:cwtch/cwtch_icons_icons.dart';
|
|
|
|
import 'package:cwtch/settings.dart';
|
|
|
|
import 'package:cwtch/widgets/textfield.dart';
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cwtch/torstatus.dart';
|
|
|
|
import 'package:cwtch/widgets/tor_icon.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
import '../main.dart';
|
2022-01-12 22:03:56 +00:00
|
|
|
import 'globalsettingsview.dart';
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
/// Tor Status View provides all info on Tor network state and the (future) ability to configure the network in a variety
|
|
|
|
/// of ways (restart, enable bridges, enable pluggable transports etc)
|
|
|
|
class TorStatusView extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_TorStatusView createState() => _TorStatusView();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TorStatusView extends State<TorStatusView> {
|
2022-01-12 22:03:56 +00:00
|
|
|
TextEditingController torSocksPortController = TextEditingController();
|
|
|
|
TextEditingController torControlPortController = TextEditingController();
|
|
|
|
TextEditingController torConfigController = TextEditingController();
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(AppLocalizations.of(context)!.torNetworkStatus),
|
|
|
|
),
|
|
|
|
body: _buildSettingsList(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildSettingsList() {
|
2022-01-12 22:03:56 +00:00
|
|
|
return Consumer<Settings>(builder: (
|
|
|
|
context,
|
|
|
|
settings,
|
|
|
|
child,
|
|
|
|
) {
|
|
|
|
// We don't want these to update on edit...only on construction...
|
|
|
|
if (torSocksPortController.text.isEmpty) {
|
|
|
|
torConfigController.text = settings.torConfig;
|
|
|
|
torSocksPortController.text = settings.socksPort.toString();
|
|
|
|
torControlPortController.text = settings.controlPort.toString();
|
|
|
|
}
|
|
|
|
return Consumer<TorStatus>(builder: (context, torStatus, child) {
|
|
|
|
return LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
|
|
|
|
return Scrollbar(
|
|
|
|
isAlwaysShown: true,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minHeight: viewportConstraints.maxHeight,
|
|
|
|
),
|
|
|
|
child: Column(children: [
|
|
|
|
ListTile(
|
|
|
|
leading: TorIcon(),
|
|
|
|
title: Text(AppLocalizations.of(context)!.torStatus),
|
|
|
|
subtitle: Text(torStatus.progress == 100 ? AppLocalizations.of(context)!.networkStatusOnline : torStatus.status),
|
|
|
|
trailing: ElevatedButton(
|
|
|
|
child: Text(AppLocalizations.of(context)!.resetTor),
|
|
|
|
onPressed: () {
|
|
|
|
Provider.of<FlwtchState>(context, listen: false).cwtch.ResetTor();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.torVersion),
|
|
|
|
subtitle: SelectableText(torStatus.version),
|
|
|
|
leading: Icon(CwtchIcons.info_24px, color: settings.current().mainTextColor),
|
|
|
|
),
|
2022-01-18 21:17:27 +00:00
|
|
|
SwitchListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.torSettingsEnableCache),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledCacheDescription),
|
|
|
|
value: settings.useTorCache,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
settings.useTorCache = value;
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(Icons.cached, color: settings.current().mainTextColor),
|
|
|
|
),
|
2022-01-12 22:03:56 +00:00
|
|
|
SwitchListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvanced),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.torSettingsEnabledAdvancedDescription),
|
|
|
|
value: settings.allowAdvancedTorConfig,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
settings.allowAdvancedTorConfig = value;
|
|
|
|
saveSettings(context);
|
2021-06-24 23:10:45 +00:00
|
|
|
},
|
2022-01-12 22:03:56 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.settings_24px, color: settings.current().mainTextColor),
|
2021-06-24 23:10:45 +00:00
|
|
|
),
|
2022-01-12 22:03:56 +00:00
|
|
|
Visibility(
|
|
|
|
visible: settings.allowAdvancedTorConfig,
|
|
|
|
child: Column(children: [
|
|
|
|
ListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPort),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.torSettingsCustomSocksPortDescription),
|
|
|
|
leading: Icon(CwtchIcons.swap_horiz_24px, color: settings.current().mainTextColor),
|
|
|
|
trailing: Container(
|
2022-01-12 23:15:58 +00:00
|
|
|
width: 300,
|
2022-01-12 22:03:56 +00:00
|
|
|
child: CwtchTextField(
|
2022-01-12 23:15:58 +00:00
|
|
|
number: true,
|
2022-01-12 22:03:56 +00:00
|
|
|
controller: torSocksPortController,
|
2022-01-12 23:15:58 +00:00
|
|
|
validator: (value) {
|
|
|
|
try {
|
|
|
|
var port = int.parse(value);
|
|
|
|
if (port > 0 && port < 65536) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2022-01-12 23:28:33 +00:00
|
|
|
return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
|
2022-01-12 23:15:58 +00:00
|
|
|
}
|
2022-01-12 23:28:33 +00:00
|
|
|
} catch (e) {
|
|
|
|
return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
|
2022-01-12 23:15:58 +00:00
|
|
|
}
|
|
|
|
},
|
2022-01-12 22:03:56 +00:00
|
|
|
onChanged: (String socksPort) {
|
|
|
|
try {
|
2022-01-12 23:15:58 +00:00
|
|
|
var port = int.parse(socksPort);
|
|
|
|
if (port > 0 && port < 65536) {
|
|
|
|
settings.socksPort = int.parse(socksPort);
|
|
|
|
saveSettings(context);
|
|
|
|
}
|
2022-01-12 22:03:56 +00:00
|
|
|
} catch (e) {}
|
|
|
|
},
|
|
|
|
))),
|
|
|
|
ListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.torSettingsCustomControlPort),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.torSettingsCustomControlPortDescription),
|
|
|
|
leading: Icon(CwtchIcons.swap_horiz_24px, color: settings.current().mainTextColor),
|
|
|
|
trailing: Container(
|
2022-01-12 23:15:58 +00:00
|
|
|
width: 300,
|
2022-01-12 22:03:56 +00:00
|
|
|
child: CwtchTextField(
|
2022-01-12 23:15:58 +00:00
|
|
|
number: true,
|
2022-01-12 22:03:56 +00:00
|
|
|
controller: torControlPortController,
|
2022-01-12 23:15:58 +00:00
|
|
|
validator: (value) {
|
|
|
|
try {
|
|
|
|
var port = int.parse(value);
|
|
|
|
if (port > 0 && port < 65536) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2022-01-12 23:28:33 +00:00
|
|
|
return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
|
2022-01-12 23:15:58 +00:00
|
|
|
}
|
2022-01-12 23:28:33 +00:00
|
|
|
} catch (e) {
|
|
|
|
return AppLocalizations.of(context)!.torSettingsErrorSettingPort;
|
2022-01-12 23:15:58 +00:00
|
|
|
}
|
|
|
|
},
|
2022-01-12 22:03:56 +00:00
|
|
|
onChanged: (String controlPort) {
|
|
|
|
try {
|
2022-01-12 23:15:58 +00:00
|
|
|
var port = int.parse(controlPort);
|
|
|
|
if (port > 0 && port < 65536) {
|
2022-01-12 23:28:33 +00:00
|
|
|
settings.controlPort = int.parse(controlPort);
|
2022-01-12 23:15:58 +00:00
|
|
|
saveSettings(context);
|
|
|
|
}
|
2022-01-12 22:03:56 +00:00
|
|
|
} catch (e) {}
|
|
|
|
},
|
|
|
|
))),
|
|
|
|
SwitchListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfiguration, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.torSettingsUseCustomTorServiceConfigurastionDescription),
|
|
|
|
value: settings.useCustomTorConfig,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
settings.useCustomTorConfig = value;
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
|
|
|
|
),
|
2022-01-12 22:41:17 +00:00
|
|
|
Visibility(
|
|
|
|
visible: settings.useCustomTorConfig,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.all(5),
|
|
|
|
child: CwtchTextField(
|
|
|
|
controller: torConfigController,
|
|
|
|
multiLine: true,
|
|
|
|
onChanged: (torConfig) {
|
|
|
|
settings.torConfig = torConfig;
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
)))
|
2022-01-12 22:03:56 +00:00
|
|
|
]))
|
|
|
|
]))));
|
|
|
|
});
|
2021-06-24 23:10:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|