This commit is contained in:
Fabian Freund
2025-09-10 07:32:52 +02:00
parent dce15e2381
commit 839824b573
15 changed files with 336 additions and 64 deletions
@@ -27,6 +27,7 @@ import 'package:rxdart/rxdart.dart';
import 'package:weblibre/core/logger.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/providers/lifecycle.dart';
import 'package:weblibre/features/tor/utils/tor_entrypoint.dart';
import 'package:weblibre/features/user/domain/repositories/tor_settings.dart';
part 'tor_proxy.g.dart';
@@ -105,6 +106,18 @@ class TorProxyService extends _$TorProxyService {
if (currentPort == null || forceReconnect) {
state = const AsyncLoading();
final torSettings = await ref
.read(torSettingsRepositoryProvider.notifier)
.fetchSettings();
if (torSettings.autoConfig) {
final moat = MoatService();
final config = await moat.autoConf();
todo
}
await _tor.start();
_enableHeartbeatTimer();
}
@@ -1,26 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'tor_proxy.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$torProxyServiceHash() => r'f991652e4e228d3e7fdc09a6088b6c5427d6231c';
/// See also [TorProxyService].
@ProviderFor(TorProxyService)
final torProxyServiceProvider =
AsyncNotifierProvider<TorProxyService, int?>.internal(
TorProxyService.new,
name: r'torProxyServiceProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$torProxyServiceHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef _$TorProxyService = AsyncNotifier<int?>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
@@ -22,8 +22,8 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/settings/presentation/controllers/save_settings.dart';
import 'package:weblibre/features/tor/domain/services/tor_proxy.dart';
import 'package:weblibre/features/user/data/models/general_settings.dart';
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
import 'package:weblibre/features/user/data/models/tor_settings.dart';
import 'package:weblibre/features/user/domain/repositories/tor_settings.dart';
import 'package:weblibre/presentation/hooks/on_initialization.dart';
import 'package:weblibre/presentation/icons/tor_icons.dart';
@@ -33,11 +33,7 @@ class TorProxyScreen extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final torProxyPort = ref.watch(torProxyServiceProvider);
final proxyPrivateTabsTor = ref.watch(
generalSettingsWithDefaultsProvider.select(
(value) => value.proxyPrivateTabsTor,
),
);
final torSettings = ref.watch(torSettingsWithDefaultsProvider);
useOnInitialization(() async {
await ref.read(torProxyServiceProvider.notifier).requestSync();
@@ -136,7 +132,7 @@ class TorProxyScreen extends HookConsumerWidget {
}
return null; // Use the default color.
}),
value: proxyPrivateTabsTor,
value: torSettings.proxyPrivateTabsTor,
title: const Text('Proxy Private Tabs'),
subtitle: const Text(
'When enabled, all Private Tabs will be tunneled through Tor',
@@ -144,9 +140,7 @@ class TorProxyScreen extends HookConsumerWidget {
secondary: const Icon(MdiIcons.arrowDecision),
onChanged: (value) async {
await ref
.read(
saveGeneralSettingsControllerProvider.notifier,
)
.read(saveTorSettingsControllerProvider.notifier)
.save(
(currentSettings) => currentSettings.copyWith
.proxyPrivateTabsTor(value),
@@ -154,6 +148,53 @@ class TorProxyScreen extends HookConsumerWidget {
},
),
),
ListTileTheme(
iconColor: Colors.white,
textColor: Colors.white,
child: SwitchListTile.adaptive(
inactiveThumbColor: Colors.white,
activeColor: const Color(0xFF68B030),
trackColor: WidgetStateProperty.resolveWith<Color?>((
Set<WidgetState> states,
) {
if (states.isEmpty) {
return const Color(0xFF333A41);
}
return null; // Use the default color.
}),
trackOutlineColor:
WidgetStateProperty.resolveWith<Color?>((
Set<WidgetState> states,
) {
if (states.isEmpty) {
return Colors.white;
}
return null; // Use the default color.
}),
thumbIcon: WidgetStateProperty.resolveWith<Icon?>((
Set<WidgetState> states,
) {
if (states.contains(WidgetState.selected)) {
return const Icon(MdiIcons.arrowDecisionAuto);
}
return null; // Use the default color.
}),
value: torSettings.autoConfig,
title: const Text('Configure Transport Automatically'),
subtitle: const Text(
'From some locations, it is necessary to use a pluggable transport to connect to the Tor network that is otherwise blocked. Turn off automatic configuration to manually configure how Tor connects.',
),
secondary: const Icon(MdiIcons.arrowDecision),
onChanged: (value) async {
await ref
.read(saveTorSettingsControllerProvider.notifier)
.save(
(currentSettings) =>
currentSettings.copyWith.autoConfig(value),
);
},
),
),
],
),
),