mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00:00
fix: tor switch properly dismisses fullscreen loading dialog
fix: connectToNode after tor startup on app start
This commit is contained in:
parent
98cab3e007
commit
07fd2dd8e1
3 changed files with 51 additions and 28 deletions
|
@ -27,22 +27,18 @@ class StartTorPage extends BasePage {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Observer(
|
Column(
|
||||||
builder: (_) {
|
children: [
|
||||||
return Column(
|
SizedBox(width: double.maxFinite),
|
||||||
children: [
|
if (startTorViewModel.isLoading) ...[
|
||||||
SizedBox(width: double.maxFinite),
|
CircularProgressIndicator(),
|
||||||
if (startTorViewModel.isLoading) ...[
|
SizedBox(height: 20),
|
||||||
CircularProgressIndicator(),
|
_buildWaitingText(context),
|
||||||
SizedBox(height: 20),
|
|
||||||
_buildWaitingText(context),
|
|
||||||
],
|
|
||||||
if (startTorViewModel.showOptions) ...[
|
|
||||||
_buildOptionsButtons(context),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
);
|
if (startTorViewModel.showOptions) ...[
|
||||||
},
|
_buildOptionsButtons(context),
|
||||||
|
],
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:cw_core/utils/proxy_wrapper.dart';
|
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||||
import 'package:cw_core/utils/print_verbose.dart';
|
import 'package:cw_core/utils/print_verbose.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:tor/tor.dart';
|
import 'package:tor/tor.dart';
|
||||||
|
|
||||||
bool didTorStart = false;
|
bool didTorStart = false;
|
||||||
|
@ -9,12 +13,13 @@ Future<void> ensureTorStopped({required BuildContext? context}) async {
|
||||||
printV("Tor hasn't been initialized yet, so it can't be stopped.");
|
printV("Tor hasn't been initialized yet, so it can't be stopped.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (context != null) showFullscreenDialog(context);
|
BuildContext? dialogContext;
|
||||||
|
if (context != null) dialogContext = await showFullscreenDialog(context);
|
||||||
didTorStart = false;
|
didTorStart = false;
|
||||||
printV("Stopping tor");
|
printV("Stopping tor");
|
||||||
await CakeTor.instance.stop();
|
await CakeTor.instance.stop();
|
||||||
printV("Tor stopped");
|
printV("Tor stopped");
|
||||||
if (context != null) dismissFullscreenDialog(context);
|
if (context != null) dismissFullscreenDialog(dialogContext!);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> ensureTorStarted({required BuildContext? context}) async {
|
Future<void> ensureTorStarted({required BuildContext? context}) async {
|
||||||
|
@ -22,22 +27,37 @@ Future<void> ensureTorStarted({required BuildContext? context}) async {
|
||||||
printV("Tor has already started");
|
printV("Tor has already started");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (context != null) showFullscreenDialog(context);
|
BuildContext? dialogContext;
|
||||||
|
if (context != null) dialogContext = await showFullscreenDialog(context);
|
||||||
didTorStart = true;
|
didTorStart = true;
|
||||||
printV("Initializing tor");
|
printV("Initializing tor");
|
||||||
await Tor.init();
|
await Tor.init();
|
||||||
printV("Starting tor");
|
printV("Starting tor");
|
||||||
|
// var rootToken = RootIsolateToken.instance!;
|
||||||
|
// await Isolate.run(() async {
|
||||||
|
// BackgroundIsolateBinaryMessenger.ensureInitialized(rootToken);
|
||||||
|
// await CakeTor.instance.start();
|
||||||
|
// });
|
||||||
|
// second start is fast but populates the values on current thread
|
||||||
await CakeTor.instance.start();
|
await CakeTor.instance.start();
|
||||||
printV("Tor started");
|
printV("Tor started");
|
||||||
if (context != null) dismissFullscreenDialog(context);
|
while (CakeTor.instance.port == -1) {
|
||||||
|
printV("Waiting for tor to start");
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
}
|
||||||
|
printV("Tor started on port ${CakeTor.instance.port}");
|
||||||
|
if (context != null) dismissFullscreenDialog(dialogContext!);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showFullscreenDialog(BuildContext context) async {
|
Future<BuildContext> showFullscreenDialog(BuildContext context) async {
|
||||||
await showDialog(
|
BuildContext? dialogContext;
|
||||||
context: context,
|
unawaited(
|
||||||
barrierDismissible: false,
|
showDialog(
|
||||||
builder: (context) {
|
context: context,
|
||||||
return PopScope(
|
barrierDismissible: false,
|
||||||
|
builder: (context) {
|
||||||
|
dialogContext = context;
|
||||||
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
|
@ -45,13 +65,17 @@ Future<void> showFullscreenDialog(BuildContext context) async {
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
return dialogContext!;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> dismissFullscreenDialog(BuildContext context) async {
|
Future<void> dismissFullscreenDialog(BuildContext context) async {
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
import 'package:cake_wallet/routes.dart';
|
import 'package:cake_wallet/routes.dart';
|
||||||
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/utils/tor.dart';
|
import 'package:cake_wallet/utils/tor.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -54,6 +55,8 @@ abstract class StartTorViewModelBase with Store {
|
||||||
}
|
}
|
||||||
await ensureTorStarted(context: null);
|
await ensureTorStarted(context: null);
|
||||||
didStartTor = true;
|
didStartTor = true;
|
||||||
|
final appStore = getIt.get<AppStore>();
|
||||||
|
appStore.wallet?.connectToNode(node: appStore.settingsStore.getCurrentNode(appStore.wallet!.type));
|
||||||
Navigator.pushReplacementNamed(context, Routes.login);
|
Navigator.pushReplacementNamed(context, Routes.login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue