add tor pref

This commit is contained in:
julian 2023-08-07 11:06:44 -06:00
parent 5aea9d6a2a
commit 99dc1aef42
2 changed files with 29 additions and 3 deletions

View file

@ -168,9 +168,10 @@ void main() async {
await Hive.openBox<dynamic>(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();
}

View file

@ -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<dynamic>(
boxName: DB.boxNamePrefs,
key: "useTor",
value: useTor,
);
_useTor = useTor;
notifyListeners();
}
}
Future<bool> _getUseTor() async {
return await DB.instance
.get<dynamic>(boxName: DB.boxNamePrefs, key: "useTor") as bool? ??
false;
}
}