tor lifecycle management

This commit is contained in:
Fabian Freund
2025-03-16 20:55:33 +01:00
parent 6830d94bac
commit 9bc9c53559
10 changed files with 176 additions and 24 deletions
@@ -12,24 +12,28 @@ class StartProxyController extends _$StartProxyController {
// ignore: document_ignores is used for dialog
// ignore: avoid_build_context_in_providers
Future<void> maybeStartProxy(BuildContext context) async {
final torProxyRunning = ref.read(torProxyServiceProvider);
final torProxyRunning =
await ref.read(torProxyServiceProvider.notifier).requestSync();
if (torProxyRunning.valueOrNull == null) {
final result = await showDialog<bool>(
context: context,
builder: (context) {
return TorDialog();
},
);
if (torProxyRunning == null) {
if (context.mounted) {
final result = await showDialog<bool>(
context: context,
builder: (context) {
return TorDialog();
},
);
if (result == true) {
final connection = ref.read(torProxyServiceProvider.notifier).connect();
if (result == true) {
final connection =
ref.read(torProxyServiceProvider.notifier).connect();
ref
.read(overlayControllerProvider.notifier)
.show(Positioned(top: 0, left: 0, child: TorNotification()));
ref
.read(overlayControllerProvider.notifier)
.show(Positioned(top: 0, left: 0, child: TorNotification()));
await connection;
await connection;
}
}
}
}
@@ -7,7 +7,7 @@ part of 'start_tor_proxy.dart';
// **************************************************************************
String _$startProxyControllerHash() =>
r'7ba8d6eded4664a8aa3eb1360926c56e9185cac9';
r'b83cdc1b6d1c358a2042ff2b7cc2f19f82e5d5ed';
/// See also [StartProxyController].
@ProviderFor(StartProxyController)
@@ -3,6 +3,7 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/features/tor/domain/services/tor_proxy.dart';
import 'package:lensai/presentation/hooks/on_initialization.dart';
class TorProxyScreen extends HookConsumerWidget {
const TorProxyScreen();
@@ -11,6 +12,10 @@ class TorProxyScreen extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final torProxyPort = ref.watch(torProxyServiceProvider);
useOnInitialization(() async {
await ref.read(torProxyServiceProvider.notifier).requestSync();
});
return Scaffold(
appBar: AppBar(title: const Text('Tor Proxy')),
body: ColoredBox(