mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-25 08:39:06 +00:00
tor updates
This commit is contained in:
parent
78ed679864
commit
77fa3e06ae
2 changed files with 37 additions and 24 deletions
|
@ -21,6 +21,7 @@ class PreferencesKey {
|
||||||
static const disableSellKey = 'disable_sell';
|
static const disableSellKey = 'disable_sell';
|
||||||
static const defaultBuyProvider = 'default_buy_provider';
|
static const defaultBuyProvider = 'default_buy_provider';
|
||||||
static const currentFiatApiModeKey = 'current_fiat_api_mode';
|
static const currentFiatApiModeKey = 'current_fiat_api_mode';
|
||||||
|
static const shouldStartTorOnLaunch = 'start_tor_on_launch';
|
||||||
static const allowBiometricalAuthenticationKey = 'allow_biometrical_authentication';
|
static const allowBiometricalAuthenticationKey = 'allow_biometrical_authentication';
|
||||||
static const useTOTP2FA = 'use_totp_2fa';
|
static const useTOTP2FA = 'use_totp_2fa';
|
||||||
static const failedTotpTokenTrials = 'failed_token_trials';
|
static const failedTotpTokenTrials = 'failed_token_trials';
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'dart:io';
|
||||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||||
import 'package:cake_wallet/store/app_store.dart';
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
import 'package:tor/tor.dart';
|
import 'package:tor/tor.dart';
|
||||||
|
|
||||||
class TorPage extends BasePage {
|
class TorPage extends BasePage {
|
||||||
|
@ -41,16 +42,16 @@ class _TorPageBodyState extends State<TorPageBody> {
|
||||||
});
|
});
|
||||||
|
|
||||||
await Tor.init();
|
await Tor.init();
|
||||||
|
|
||||||
// Start the proxy
|
// Start the proxy
|
||||||
await Tor.instance.start();
|
await Tor.instance.start();
|
||||||
|
|
||||||
// Toggle started flag.
|
// Toggle started flag.
|
||||||
setState(() {
|
setState(() {
|
||||||
torEnabled = Tor.instance.enabled;
|
torEnabled = Tor.instance.enabled;
|
||||||
connecting = false;
|
connecting = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
final node = widget.appStore.settingsStore.getCurrentNode(widget.appStore.wallet!.type);
|
final node = widget.appStore.settingsStore.getCurrentNode(widget.appStore.wallet!.type);
|
||||||
if (node.socksProxyAddress?.isEmpty ?? true) {
|
if (node.socksProxyAddress?.isEmpty ?? true) {
|
||||||
node.socksProxyAddress = "${InternetAddress.loopbackIPv4.address}:${Tor.instance.port}";
|
node.socksProxyAddress = "${InternetAddress.loopbackIPv4.address}:${Tor.instance.port}";
|
||||||
|
@ -61,21 +62,17 @@ class _TorPageBodyState extends State<TorPageBody> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> endTor() async {
|
Future<void> endTor() async {
|
||||||
// Start the proxy
|
|
||||||
Tor.instance.disable();
|
Tor.instance.disable();
|
||||||
|
|
||||||
// Toggle started flag.
|
|
||||||
setState(() {
|
setState(() {
|
||||||
torEnabled = Tor.instance.enabled; // Update flag
|
torEnabled = Tor.instance.enabled;
|
||||||
});
|
});
|
||||||
|
|
||||||
print('Done awaiting; tor should be stopped');
|
print('Done awaiting; tor should be stopped');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
torEnabled = Tor.instance.enabled;
|
torEnabled = Tor.instance.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,16 +83,38 @@ class _TorPageBodyState extends State<TorPageBody> {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> toggleStartup(bool? value) async {
|
||||||
|
if (value == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
widget.appStore.settingsStore.shouldStartTorOnLaunch = value;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Container(
|
child: Column(
|
||||||
padding: const EdgeInsets.all(10),
|
children: [
|
||||||
child: connecting
|
Container(
|
||||||
? ConnectingScreen()
|
padding: const EdgeInsets.all(10),
|
||||||
: torEnabled
|
child: connecting
|
||||||
? DisconnectScreen(disconnect: endTor)
|
? ConnectingScreen()
|
||||||
: ConnectScreen(connect: startTor),
|
: torEnabled
|
||||||
|
? DisconnectScreen(disconnect: endTor)
|
||||||
|
: ConnectScreen(connect: startTor),
|
||||||
|
),
|
||||||
|
Observer(builder: (_) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Checkbox(
|
||||||
|
onChanged: toggleStartup,
|
||||||
|
value: widget.appStore.settingsStore.shouldStartTorOnLaunch,
|
||||||
|
),
|
||||||
|
Text("Auto start Tor on app launch"),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -160,13 +179,6 @@ class ConnectScreen extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text("Auto start Tor on app launch"),
|
|
||||||
Checkbox(
|
|
||||||
onChanged: (bool? value) {
|
|
||||||
print('value: $value');
|
|
||||||
},
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue