From 77fa3e06ae444eb70902e2e87a1232d221c673f2 Mon Sep 17 00:00:00 2001 From: fosse Date: Tue, 19 Dec 2023 20:05:43 -0500 Subject: [PATCH] tor updates --- lib/entities/preferences_key.dart | 1 + lib/src/screens/settings/tor_page.dart | 60 +++++++++++++++----------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/lib/entities/preferences_key.dart b/lib/entities/preferences_key.dart index 67f1aca97..004b26384 100644 --- a/lib/entities/preferences_key.dart +++ b/lib/entities/preferences_key.dart @@ -21,6 +21,7 @@ class PreferencesKey { static const disableSellKey = 'disable_sell'; static const defaultBuyProvider = 'default_buy_provider'; static const currentFiatApiModeKey = 'current_fiat_api_mode'; + static const shouldStartTorOnLaunch = 'start_tor_on_launch'; static const allowBiometricalAuthenticationKey = 'allow_biometrical_authentication'; static const useTOTP2FA = 'use_totp_2fa'; static const failedTotpTokenTrials = 'failed_token_trials'; diff --git a/lib/src/screens/settings/tor_page.dart b/lib/src/screens/settings/tor_page.dart index cbdff80ec..863be3b9e 100644 --- a/lib/src/screens/settings/tor_page.dart +++ b/lib/src/screens/settings/tor_page.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/store/app_store.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:tor/tor.dart'; class TorPage extends BasePage { @@ -41,16 +42,16 @@ class _TorPageBodyState extends State { }); await Tor.init(); - + // Start the proxy await Tor.instance.start(); - + // Toggle started flag. setState(() { torEnabled = Tor.instance.enabled; connecting = false; }); - + final node = widget.appStore.settingsStore.getCurrentNode(widget.appStore.wallet!.type); if (node.socksProxyAddress?.isEmpty ?? true) { node.socksProxyAddress = "${InternetAddress.loopbackIPv4.address}:${Tor.instance.port}"; @@ -61,21 +62,17 @@ class _TorPageBodyState extends State { } Future endTor() async { - // Start the proxy Tor.instance.disable(); - - // Toggle started flag. setState(() { - torEnabled = Tor.instance.enabled; // Update flag + torEnabled = Tor.instance.enabled; }); - print('Done awaiting; tor should be stopped'); } - + @override void initState() { super.initState(); - + torEnabled = Tor.instance.enabled; } @@ -86,16 +83,38 @@ class _TorPageBodyState extends State { super.dispose(); } + Future toggleStartup(bool? value) async { + if (value == null) { + return; + } + widget.appStore.settingsStore.shouldStartTorOnLaunch = value; + } + @override Widget build(BuildContext context) { return SingleChildScrollView( - child: Container( - padding: const EdgeInsets.all(10), - child: connecting - ? ConnectingScreen() - : torEnabled - ? DisconnectScreen(disconnect: endTor) - : ConnectScreen(connect: startTor), + child: Column( + children: [ + Container( + padding: const EdgeInsets.all(10), + child: connecting + ? ConnectingScreen() + : torEnabled + ? DisconnectScreen(disconnect: endTor) + : ConnectScreen(connect: startTor), + ), + Observer(builder: (_) { + return Row( + children: [ + Checkbox( + onChanged: toggleStartup, + value: widget.appStore.settingsStore.shouldStartTorOnLaunch, + ), + Text("Auto start Tor on app launch"), + ], + ); + }), + ], ), ); } @@ -160,13 +179,6 @@ class ConnectScreen extends StatelessWidget { ), ), ), - Text("Auto start Tor on app launch"), - Checkbox( - onChanged: (bool? value) { - print('value: $value'); - }, - value: null, - ), ], ), );