mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
fire TorConnectionStatusChangedEvents from tor service
and move tor_service file and unableToConnect->disconnected
This commit is contained in:
parent
a8ed46d804
commit
2c77ac1b5d
9 changed files with 42 additions and 14 deletions
|
@ -17,9 +17,9 @@ import 'package:decimal/decimal.dart';
|
||||||
import 'package:event_bus/event_bus.dart';
|
import 'package:event_bus/event_bus.dart';
|
||||||
import 'package:stackwallet/electrumx_rpc/rpc.dart';
|
import 'package:stackwallet/electrumx_rpc/rpc.dart';
|
||||||
import 'package:stackwallet/exceptions/electrumx/no_such_transaction.dart';
|
import 'package:stackwallet/exceptions/electrumx/no_such_transaction.dart';
|
||||||
import 'package:stackwallet/networking/tor_service.dart';
|
|
||||||
import 'package:stackwallet/services/event_bus/events/global/tor_status_changed_event.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/services/event_bus/global_event_bus.dart';
|
||||||
|
import 'package:stackwallet/services/tor_service.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
|
@ -15,7 +15,7 @@ import 'dart:io';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:mutex/mutex.dart';
|
import 'package:mutex/mutex.dart';
|
||||||
import 'package:stackwallet/networking/socks_socket.dart';
|
import 'package:stackwallet/networking/socks_socket.dart';
|
||||||
import 'package:stackwallet/networking/tor_service.dart';
|
import 'package:stackwallet/services/tor_service.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ import 'package:stackwallet/models/models.dart';
|
||||||
import 'package:stackwallet/models/node_model.dart';
|
import 'package:stackwallet/models/node_model.dart';
|
||||||
import 'package:stackwallet/models/notification_model.dart';
|
import 'package:stackwallet/models/notification_model.dart';
|
||||||
import 'package:stackwallet/models/trade_wallet_lookup.dart';
|
import 'package:stackwallet/models/trade_wallet_lookup.dart';
|
||||||
import 'package:stackwallet/networking/tor_service.dart';
|
|
||||||
import 'package:stackwallet/pages/home_view/home_view.dart';
|
import 'package:stackwallet/pages/home_view/home_view.dart';
|
||||||
import 'package:stackwallet/pages/intro_view.dart';
|
import 'package:stackwallet/pages/intro_view.dart';
|
||||||
import 'package:stackwallet/pages/loading_view.dart';
|
import 'package:stackwallet/pages/loading_view.dart';
|
||||||
|
@ -60,6 +59,7 @@ import 'package:stackwallet/services/locale_service.dart';
|
||||||
import 'package:stackwallet/services/node_service.dart';
|
import 'package:stackwallet/services/node_service.dart';
|
||||||
import 'package:stackwallet/services/notifications_api.dart';
|
import 'package:stackwallet/services/notifications_api.dart';
|
||||||
import 'package:stackwallet/services/notifications_service.dart';
|
import 'package:stackwallet/services/notifications_service.dart';
|
||||||
|
import 'package:stackwallet/services/tor_service.dart';
|
||||||
import 'package:stackwallet/services/trade_service.dart';
|
import 'package:stackwallet/services/trade_service.dart';
|
||||||
import 'package:stackwallet/themes/theme_providers.dart';
|
import 'package:stackwallet/themes/theme_providers.dart';
|
||||||
import 'package:stackwallet/themes/theme_service.dart';
|
import 'package:stackwallet/themes/theme_service.dart';
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:socks5_proxy/socks_client.dart';
|
import 'package:socks5_proxy/socks_client.dart';
|
||||||
import 'package:stackwallet/networking/tor_service.dart';
|
import 'package:stackwallet/services/tor_service.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
|
||||||
// WIP wrapper layer
|
// WIP wrapper layer
|
||||||
|
|
|
@ -119,7 +119,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
||||||
|
|
||||||
Widget _buildTorIcon(TorConnectionStatus status) {
|
Widget _buildTorIcon(TorConnectionStatus status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case TorConnectionStatus.unableToConnect:
|
case TorConnectionStatus.disconnected:
|
||||||
return SvgPicture.asset(
|
return SvgPicture.asset(
|
||||||
Assets.svg.tor,
|
Assets.svg.tor,
|
||||||
color: Theme.of(context).extension<StackColors>()!.textSubtitle3,
|
color: Theme.of(context).extension<StackColors>()!.textSubtitle3,
|
||||||
|
@ -261,7 +261,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
.backgroundAppBar,
|
.backgroundAppBar,
|
||||||
icon: _buildTorIcon(TorConnectionStatus.unableToConnect),
|
icon: _buildTorIcon(TorConnectionStatus.disconnected),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.pushNamed(TorSettingsView.routeName);
|
.pushNamed(TorSettingsView.routeName);
|
||||||
|
|
|
@ -9,14 +9,15 @@
|
||||||
*/
|
*/
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
|
||||||
enum TorConnectionStatus { unableToConnect, connected, connecting }
|
enum TorConnectionStatus { disconnected, connecting, connected }
|
||||||
|
|
||||||
class TorConnectionStatusChangedEvent {
|
class TorConnectionStatusChangedEvent {
|
||||||
TorConnectionStatus newStatus;
|
TorConnectionStatus newStatus;
|
||||||
|
String message = "";
|
||||||
|
|
||||||
TorConnectionStatusChangedEvent(this.newStatus) {
|
TorConnectionStatusChangedEvent(this.newStatus, this.message) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"TorSyncStatusChangedEvent fired with arg newStatus = $newStatus",
|
"TorSyncStatusChangedEvent fired with arg newStatus = $newStatus ($message)",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@ class TorSettingsView extends ConsumerStatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
|
class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
|
||||||
TorConnectionStatus _networkStatus = TorConnectionStatus.unableToConnect;
|
TorConnectionStatus _networkStatus = TorConnectionStatus.disconnected;
|
||||||
|
|
||||||
Widget _buildTorIcon(TorConnectionStatus status) {
|
Widget _buildTorIcon(TorConnectionStatus status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case TorConnectionStatus.unableToConnect:
|
case TorConnectionStatus.disconnected:
|
||||||
return Stack(
|
return Stack(
|
||||||
alignment: AlignmentDirectional.center,
|
alignment: AlignmentDirectional.center,
|
||||||
children: [
|
children: [
|
||||||
|
@ -97,7 +97,7 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
|
||||||
|
|
||||||
Widget _buildTorStatus(TorConnectionStatus status) {
|
Widget _buildTorStatus(TorConnectionStatus status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case TorConnectionStatus.unableToConnect:
|
case TorConnectionStatus.disconnected:
|
||||||
return Text(
|
return Text(
|
||||||
"Disconnected",
|
"Disconnected",
|
||||||
style: STextStyles.itemSubtitle(context).copyWith(
|
style: STextStyles.itemSubtitle(context).copyWith(
|
||||||
|
|
|
@ -61,7 +61,7 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
|
||||||
|
|
||||||
Widget _buildTorIcon(TorConnectionStatus status) {
|
Widget _buildTorIcon(TorConnectionStatus status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case TorConnectionStatus.unableToConnect:
|
case TorConnectionStatus.disconnected:
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
@ -218,7 +218,7 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
|
||||||
.watch(selectedSettingsMenuItemStateProvider.state)
|
.watch(selectedSettingsMenuItemStateProvider.state)
|
||||||
.state = 4;
|
.state = 4;
|
||||||
},
|
},
|
||||||
child: _buildTorIcon(TorConnectionStatus.unableToConnect)),
|
child: _buildTorIcon(TorConnectionStatus.disconnected)),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 40,
|
height: 40,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:stackwallet/pages/home_view/sub_widgets/tor_connection_status_changed_event.dart';
|
||||||
|
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:tor/tor.dart';
|
import 'package:tor/tor.dart';
|
||||||
|
|
||||||
|
@ -34,15 +36,34 @@ class TorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
TorConnectionStatusChangedEvent(
|
||||||
|
TorConnectionStatus.connecting,
|
||||||
|
"Tor connection status changed: connecting",
|
||||||
|
),
|
||||||
|
);
|
||||||
await _tor.start();
|
await _tor.start();
|
||||||
// no exception or error so we can (probably?) assume tor
|
// no exception or error so we can (probably?) assume tor
|
||||||
// has started successfully
|
// has started successfully
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
TorConnectionStatusChangedEvent(
|
||||||
|
TorConnectionStatus.connected,
|
||||||
|
"Tor connection status changed: connect ($_enabled)",
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"TorService.start failed: $e\n$s",
|
"TorService.start failed: $e\n$s",
|
||||||
level: LogLevel.Warning,
|
level: LogLevel.Warning,
|
||||||
);
|
);
|
||||||
|
// _enabled should already be false
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
TorConnectionStatusChangedEvent(
|
||||||
|
TorConnectionStatus.disconnected,
|
||||||
|
"Tor connection status changed: $_enabled (failed)",
|
||||||
|
),
|
||||||
|
);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +82,12 @@ class TorService {
|
||||||
// no exception or error so we can (probably?) assume tor
|
// no exception or error so we can (probably?) assume tor
|
||||||
// has started successfully
|
// has started successfully
|
||||||
_enabled = false;
|
_enabled = false;
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
TorConnectionStatusChangedEvent(
|
||||||
|
TorConnectionStatus.disconnected,
|
||||||
|
"Tor connection status changed: $_enabled (disabled)",
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"TorService.stop failed: $e\n$s",
|
"TorService.stop failed: $e\n$s",
|
Loading…
Reference in a new issue