From 6e625e2c7483a14d831e802c1357443c2752e450 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 7 Sep 2023 09:20:45 -0600 Subject: [PATCH] add tor status change event and fire on pref changed --- .../global/tor_status_changed_event.dart | 28 +++++++++++++++++++ lib/utilities/prefs.dart | 14 ++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 lib/services/event_bus/events/global/tor_status_changed_event.dart diff --git a/lib/services/event_bus/events/global/tor_status_changed_event.dart b/lib/services/event_bus/events/global/tor_status_changed_event.dart new file mode 100644 index 000000000..cf9cac5ee --- /dev/null +++ b/lib/services/event_bus/events/global/tor_status_changed_event.dart @@ -0,0 +1,28 @@ +/* + * This file is part of Stack Wallet. + * + * Copyright (c) 2023 Cypher Stack + * All Rights Reserved. + * The code is distributed under GPLv3 license, see LICENSE file for details. + * Generated by Cypher Stack on 2023-05-26 + * + */ + +import 'package:stackwallet/utilities/logger.dart'; + +enum TorStatus { enabled, disabled } + +class TorStatusChangedEvent { + String? message; + TorStatus status; + + TorStatusChangedEvent({ + required this.status, + this.message, + }) { + Logging.instance.log( + "TorStatusChangedEvent changed to \"$status\" with message: $message", + level: LogLevel.Warning, + ); + } +} diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index f5a04a6f9..d9a2192be 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -10,6 +10,8 @@ import 'package:flutter/cupertino.dart'; import 'package:stackwallet/db/hive/db.dart'; +import 'package:stackwallet/services/event_bus/events/global/tor_status_changed_event.dart'; +import 'package:stackwallet/services/event_bus/global_event_bus.dart'; import 'package:stackwallet/utilities/amount/amount_unit.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/backup_frequency_type.dart'; @@ -886,12 +888,20 @@ class Prefs extends ChangeNotifier { ); _useTor = useTor; notifyListeners(); + GlobalEventBus.instance.fire( + TorStatusChangedEvent( + status: useTor ? TorStatus.enabled : TorStatus.disabled, + message: "useTor updated in prefs", + ), + ); } } Future _getUseTor() async { - return await DB.instance - .get(boxName: DB.boxNamePrefs, key: "useTor") as bool? ?? + return await DB.instance.get( + boxName: DB.boxNamePrefs, + key: "useTor", + ) as bool? ?? false; } }