remove tor service status getter

This commit is contained in:
sneurlax 2023-09-08 10:30:49 -05:00
parent 3e9a225470
commit cf27dd9252
3 changed files with 16 additions and 24 deletions

View file

@ -72,7 +72,7 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
_torConnectionStatusSubscription; _torConnectionStatusSubscription;
/// The current status of the Tor connection. /// The current status of the Tor connection.
TorConnectionStatus _torConnectionStatus = TorConnectionStatus.disconnected; late TorConnectionStatus _torConnectionStatus;
/// Builds the tor icon based on the current status. /// Builds the tor icon based on the current status.
Widget _buildTorIcon(TorConnectionStatus status) { Widget _buildTorIcon(TorConnectionStatus status) {
@ -176,6 +176,11 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
// Initialize the global event bus. // Initialize the global event bus.
eventBus = GlobalEventBus.instance; eventBus = GlobalEventBus.instance;
// Initialize the TorConnectionStatus.
_torConnectionStatus = TorService.sharedInstance.enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
// Subscribe to the TorConnectionStatusChangedEvent. // Subscribe to the TorConnectionStatusChangedEvent.
_torConnectionStatusSubscription = _torConnectionStatusSubscription =
eventBus.on<TorConnectionStatusChangedEvent>().listen( eventBus.on<TorConnectionStatusChangedEvent>().listen(
@ -271,7 +276,7 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
.watch(selectedSettingsMenuItemStateProvider.state) .watch(selectedSettingsMenuItemStateProvider.state)
.state = 4; .state = 4;
}, },
child: _buildTorIcon(TorService.sharedInstance.status)), child: _buildTorIcon(_torConnectionStatus)),
), ),
const SizedBox( const SizedBox(
height: 40, height: 40,

View file

@ -52,8 +52,10 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
_torConnectionStatusSubscription; _torConnectionStatusSubscription;
/// The current status of the Tor connection. /// The current status of the Tor connection.
TorConnectionStatus _torConnectionStatus = TorConnectionStatus.disconnected; late TorConnectionStatus _torConnectionStatus =
TorConnectionStatus.disconnected;
/// Build the connect/disconnect button.
Widget _buildConnectButton(TorConnectionStatus status) { Widget _buildConnectButton(TorConnectionStatus status) {
switch (status) { switch (status) {
case TorConnectionStatus.disconnected: case TorConnectionStatus.disconnected:
@ -99,6 +101,11 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
// Initialize the global event bus. // Initialize the global event bus.
eventBus = GlobalEventBus.instance; eventBus = GlobalEventBus.instance;
// Set the initial Tor connection status.
_torConnectionStatus = TorService.sharedInstance.enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
// Subscribe to the TorConnectionStatusChangedEvent. // Subscribe to the TorConnectionStatusChangedEvent.
_torConnectionStatusSubscription = _torConnectionStatusSubscription =
eventBus.on<TorConnectionStatusChangedEvent>().listen( eventBus.on<TorConnectionStatusChangedEvent>().listen(
@ -259,7 +266,7 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
), ),
Padding( Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: _buildConnectButton(TorService.sharedInstance.status), child: _buildConnectButton(_torConnectionStatus),
), ),
const SizedBox( const SizedBox(
height: 30, height: 30,

View file

@ -17,14 +17,6 @@ class TorService {
/// Getter for the enabled flag. /// Getter for the enabled flag.
bool get enabled => _enabled; bool get enabled => _enabled;
/// The current status of the Tor connection.
TorConnectionStatus _status = TorConnectionStatus.disconnected;
/// Getter for the status.
///
/// Used mostly to indicate "Connected" status in the UI.
TorConnectionStatus get status => _status;
TorService._(); TorService._();
/// Singleton instance of the TorService. /// Singleton instance of the TorService.
@ -49,9 +41,6 @@ class TorService {
/// ///
/// Returns a Future that completes when the Tor service has started. /// Returns a Future that completes when the Tor service has started.
Future<void> start() async { Future<void> start() async {
// Set the status to connecting.
_status = TorConnectionStatus.connecting;
if (_enabled) { if (_enabled) {
// already started so just return // already started so just return
// could throw an exception here or something so the caller // could throw an exception here or something so the caller
@ -74,9 +63,6 @@ class TorService {
// has started successfully // has started successfully
_enabled = true; _enabled = true;
// Set the status to connected.
_status = TorConnectionStatus.connected;
// Fire a TorConnectionStatusChangedEvent on the event bus. // Fire a TorConnectionStatusChangedEvent on the event bus.
GlobalEventBus.instance.fire( GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent( TorConnectionStatusChangedEvent(
@ -91,9 +77,6 @@ class TorService {
); );
// _enabled should already be false // _enabled should already be false
// Set the status to disconnected.
_status = TorConnectionStatus.disconnected;
// Fire a TorConnectionStatusChangedEvent on the event bus. // Fire a TorConnectionStatusChangedEvent on the event bus.
GlobalEventBus.instance.fire( GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent( TorConnectionStatusChangedEvent(
@ -106,9 +89,6 @@ class TorService {
} }
Future<void> stop() async { Future<void> stop() async {
// Set the status to disconnected.
_status = TorConnectionStatus.disconnected;
if (!_enabled) { if (!_enabled) {
// already stopped so just return // already stopped so just return
// could throw an exception here or something so the caller // could throw an exception here or something so the caller