From 99dc1aef42ffb343b85234a81f43928f27bad422 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 7 Aug 2023 11:06:44 -0600 Subject: [PATCH] add tor pref --- lib/main.dart | 7 ++++--- lib/utilities/prefs.dart | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0392accfb..2eb63fdb0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -168,9 +168,10 @@ void main() async { await Hive.openBox(DB.boxNamePrefs); await Prefs.instance.init(); - // TODO create tor pref in Prefs - const useTor = true; // get from prefs - if (useTor) { + // TODO remove this!!!! + Prefs.instance.useTor = true; + + if (Prefs.instance.useTor) { await TorService.sharedInstance.start(); } diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index 7c306bfe5..f5a04a6f9 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -60,6 +60,7 @@ class Prefs extends ChangeNotifier { _systemBrightnessDarkThemeId = await _getSystemBrightnessDarkTheme(); await _setAmountUnits(); await _setMaxDecimals(); + _useTor = await _getUseTor(); _initialized = true; } @@ -869,4 +870,28 @@ class Prefs extends ChangeNotifier { _amountDecimals[coin] = decimals; } } + + // enabled tor + + bool _useTor = false; + + bool get useTor => _useTor; + + set useTor(bool useTor) { + if (_useTor != useTor) { + DB.instance.put( + boxName: DB.boxNamePrefs, + key: "useTor", + value: useTor, + ); + _useTor = useTor; + notifyListeners(); + } + } + + Future _getUseTor() async { + return await DB.instance + .get(boxName: DB.boxNamePrefs, key: "useTor") as bool? ?? + false; + } }