diff --git a/lib/core/backup_service.dart b/lib/core/backup_service.dart index 7dd0b50f3..10aed11c2 100644 --- a/lib/core/backup_service.dart +++ b/lib/core/backup_service.dart @@ -220,6 +220,7 @@ class BackupService { final currentLanguageCode = data[PreferencesKey.currentLanguageCode] as String?; final displayActionListMode = data[PreferencesKey.displayActionListModeKey] as int?; final fiatApiMode = data[PreferencesKey.currentFiatApiModeKey] as int?; + final shouldStartTorOnLaunch = data[PreferencesKey.shouldStartTorOnLaunch] as bool?; final currentPinLength = data[PreferencesKey.currentPinLength] as int?; final currentTheme = data[PreferencesKey.currentTheme] as int?; final exchangeStatus = data[PreferencesKey.exchangeStatusKey] as int?; @@ -315,6 +316,11 @@ class BackupService { if (fiatApiMode != null) await _sharedPreferences.setInt(PreferencesKey.currentFiatApiModeKey, fiatApiMode); + + if (shouldStartTorOnLaunch != null) + await _sharedPreferences.setBool( + PreferencesKey.shouldStartTorOnLaunch, shouldStartTorOnLaunch); + if (autoGenerateSubaddressStatus != null) await _sharedPreferences.setInt( PreferencesKey.autoGenerateSubaddressStatusKey, autoGenerateSubaddressStatus); @@ -550,6 +556,8 @@ class BackupService { _sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority), PreferencesKey.currentFiatApiModeKey: _sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey), + PreferencesKey.shouldStartTorOnLaunch: + _sharedPreferences.getBool(PreferencesKey.shouldStartTorOnLaunch), PreferencesKey.selectedCake2FAPreset: _sharedPreferences.getInt(PreferencesKey.selectedCake2FAPreset), PreferencesKey.shouldRequireTOTP2FAForAccessingWallet: diff --git a/lib/src/screens/settings/tor_page.dart b/lib/src/screens/settings/tor_page.dart index 446726f4d..cbdff80ec 100644 --- a/lib/src/screens/settings/tor_page.dart +++ b/lib/src/screens/settings/tor_page.dart @@ -37,7 +37,7 @@ class _TorPageBodyState extends State { Future startTor() async { setState(() { - connecting = true; // Update flag + connecting = true; }); await Tor.init(); @@ -47,7 +47,7 @@ class _TorPageBodyState extends State { // Toggle started flag. setState(() { - torEnabled = Tor.instance.enabled; // Update flag + torEnabled = Tor.instance.enabled; connecting = false; }); @@ -160,6 +160,13 @@ class ConnectScreen extends StatelessWidget { ), ), ), + Text("Auto start Tor on app launch"), + Checkbox( + onChanged: (bool? value) { + print('value: $value'); + }, + value: null, + ), ], ), ); diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 4078827d0..72e19549b 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -55,6 +55,7 @@ abstract class SettingsStoreBase with Store { required bool initialDisableSell, required BuyProviderType initialDefaultBuyProvider, required FiatApiMode initialFiatMode, + required bool initialShouldStartTorOnLaunch, required bool initialAllowBiometricalAuthentication, required String initialTotpSecretKey, required bool initialUseTOTP2FA, @@ -114,6 +115,7 @@ abstract class SettingsStoreBase with Store { autoGenerateSubaddressStatus = initialAutoGenerateSubaddressStatus, moneroSeedType = initialMoneroSeedType, fiatApiMode = initialFiatMode, + shouldStartTorOnLaunch = initialShouldStartTorOnLaunch, allowBiometricalAuthentication = initialAllowBiometricalAuthentication, selectedCake2FAPreset = initialCake2FAPresetOptions, totpSecretKey = initialTotpSecretKey, @@ -179,7 +181,9 @@ abstract class SettingsStoreBase with Store { WalletType.values.forEach((walletType) { final key = 'defaultBuyProvider_${walletType.toString()}'; final providerIndex = sharedPreferences.getInt(key); - defaultBuyProviders[walletType] = providerIndex != null ? BuyProviderType.values[providerIndex] : BuyProviderType.AskEachTime; + defaultBuyProviders[walletType] = providerIndex != null + ? BuyProviderType.values[providerIndex] + : BuyProviderType.AskEachTime; }); reaction( @@ -247,15 +251,13 @@ abstract class SettingsStoreBase with Store { (bool disableSell) => sharedPreferences.setBool(PreferencesKey.disableSellKey, disableSell)); - reaction( - (_) => defaultBuyProviders.asObservable(), - (ObservableMap providers) { - providers.forEach((walletType, provider) { - final key = 'defaultBuyProvider_${walletType.toString()}'; - sharedPreferences.setInt(key, provider.index); - }); - } - ); + reaction((_) => defaultBuyProviders.asObservable(), + (ObservableMap providers) { + providers.forEach((walletType, provider) { + final key = 'defaultBuyProvider_${walletType.toString()}'; + sharedPreferences.setInt(key, provider.index); + }); + }); reaction( (_) => autoGenerateSubaddressStatus, @@ -272,6 +274,11 @@ abstract class SettingsStoreBase with Store { (FiatApiMode mode) => sharedPreferences.setInt(PreferencesKey.currentFiatApiModeKey, mode.serialize())); + reaction( + (_) => shouldStartTorOnLaunch, + (bool value) => + sharedPreferences.setBool(PreferencesKey.shouldStartTorOnLaunch, value)); + reaction((_) => currentTheme, (ThemeBase theme) => sharedPreferences.setInt(PreferencesKey.currentTheme, theme.raw)); @@ -486,6 +493,9 @@ abstract class SettingsStoreBase with Store { @observable FiatApiMode fiatApiMode; + @observable + bool shouldStartTorOnLaunch; + @observable bool shouldSaveRecipientAddress; @@ -574,7 +584,8 @@ abstract class SettingsStoreBase with Store { ObservableMap trocadorProviderStates = ObservableMap(); @observable - ObservableMap defaultBuyProviders = ObservableMap(); + ObservableMap defaultBuyProviders = + ObservableMap(); @observable SortBalanceBy sortBalanceBy; @@ -722,6 +733,7 @@ abstract class SettingsStoreBase with Store { final currentFiatApiMode = FiatApiMode.deserialize( raw: sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey) ?? FiatApiMode.enabled.raw); + final shouldStartTorOnLaunch = sharedPreferences.getBool(PreferencesKey.shouldStartTorOnLaunch) ?? false; final allowBiometricalAuthentication = sharedPreferences.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ?? false; final selectedCake2FAPreset = Cake2FAPresetsOptions.deserialize( @@ -899,6 +911,7 @@ abstract class SettingsStoreBase with Store { initialDisableSell: disableSell, initialDefaultBuyProvider: defaultBuyProvider, initialFiatMode: currentFiatApiMode, + initialShouldStartTorOnLaunch: shouldStartTorOnLaunch, initialAllowBiometricalAuthentication: allowBiometricalAuthentication, initialCake2FAPresetOptions: selectedCake2FAPreset, initialUseTOTP2FA: useTOTP2FA,