fix lints
This commit is contained in:
@@ -17,51 +17,49 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/controllers/overlay.dart';
|
||||
import 'package:weblibre/features/tor/domain/services/tor_proxy.dart';
|
||||
import 'package:weblibre/features/tor/presentation/widgets/tor_dialog.dart';
|
||||
import 'package:weblibre/features/tor/presentation/widgets/tor_notification.dart';
|
||||
|
||||
part 'start_tor_proxy.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class StartProxyController extends _$StartProxyController {
|
||||
// ignore: document_ignores is used for dialog
|
||||
// ignore: avoid_build_context_in_providers
|
||||
Future<void> maybeStartProxy(BuildContext context) async {
|
||||
Future<bool> shouldPromptProxyStart() async {
|
||||
final currentStatus = await ref
|
||||
.read(torProxyServiceProvider.notifier)
|
||||
.requestSync();
|
||||
|
||||
if (!currentStatus.isRunning) {
|
||||
if (context.mounted) {
|
||||
final result = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const TorDialog();
|
||||
},
|
||||
);
|
||||
return !currentStatus.isRunning;
|
||||
}
|
||||
|
||||
if (result == true) {
|
||||
final connection = ref
|
||||
.read(torProxyServiceProvider.notifier)
|
||||
.startOrReconfigure(reconfigureIfRunning: false);
|
||||
Future<void> startProxy() async {
|
||||
if (state) return;
|
||||
|
||||
ref
|
||||
.read(overlayControllerProvider.notifier)
|
||||
.show(
|
||||
(context) =>
|
||||
Positioned(top: 0, left: 0, child: TorNotification()),
|
||||
);
|
||||
state = true;
|
||||
|
||||
await connection;
|
||||
}
|
||||
}
|
||||
try {
|
||||
final connection = ref
|
||||
.read(torProxyServiceProvider.notifier)
|
||||
.startOrReconfigure(reconfigureIfRunning: false);
|
||||
|
||||
ref
|
||||
.read(overlayControllerProvider.notifier)
|
||||
.show(
|
||||
(context) =>
|
||||
const Positioned(top: 0, left: 0, child: TorNotification()),
|
||||
);
|
||||
|
||||
await connection;
|
||||
} finally {
|
||||
state = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {}
|
||||
bool build() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ part of 'start_tor_proxy.dart';
|
||||
final startProxyControllerProvider = StartProxyControllerProvider._();
|
||||
|
||||
final class StartProxyControllerProvider
|
||||
extends $NotifierProvider<StartProxyController, void> {
|
||||
extends $NotifierProvider<StartProxyController, bool> {
|
||||
StartProxyControllerProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
@@ -33,28 +33,28 @@ final class StartProxyControllerProvider
|
||||
StartProxyController create() => StartProxyController();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
Override overrideWithValue(bool value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
providerOverride: $SyncValueProvider<bool>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$startProxyControllerHash() =>
|
||||
r'13c6ad9611a2f9525689d370a0511274aa9c0f03';
|
||||
r'899b585bf7f220251ac92f11c79537cc07723241';
|
||||
|
||||
abstract class _$StartProxyController extends $Notifier<void> {
|
||||
void build();
|
||||
abstract class _$StartProxyController extends $Notifier<bool> {
|
||||
bool build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final ref = this.ref as $Ref<bool, bool>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
AnyNotifier<bool, bool>,
|
||||
bool,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
|
||||
@@ -30,6 +30,7 @@ const automaticCountry = '';
|
||||
|
||||
class CountryPickerScreen extends HookWidget {
|
||||
const CountryPickerScreen({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.selectedCountryCode,
|
||||
});
|
||||
@@ -51,20 +52,16 @@ class CountryPickerScreen extends HookWidget {
|
||||
country.countryCode ??
|
||||
'Unnamed Country';
|
||||
return (alpha2Code: country.alpha2Code, label: label);
|
||||
}).toList()
|
||||
..sort((a, b) => a.label.compareTo(b.label));
|
||||
}).toList()..sort((a, b) => a.label.compareTo(b.label));
|
||||
});
|
||||
|
||||
final filteredCountries = useMemoized(
|
||||
() {
|
||||
if (searchQuery.value.isEmpty) return countries;
|
||||
final query = searchQuery.value.toLowerCase();
|
||||
return countries
|
||||
.where((c) => c.label.toLowerCase().contains(query))
|
||||
.toList();
|
||||
},
|
||||
[searchQuery.value, countries],
|
||||
);
|
||||
final filteredCountries = useMemoized(() {
|
||||
if (searchQuery.value.isEmpty) return countries;
|
||||
final query = searchQuery.value.toLowerCase();
|
||||
return countries
|
||||
.where((c) => c.label.toLowerCase().contains(query))
|
||||
.toList();
|
||||
}, [searchQuery.value, countries]);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -95,7 +92,7 @@ class CountryPickerScreen extends HookWidget {
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 0),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
onChanged: (value) => searchQuery.value = value,
|
||||
),
|
||||
|
||||
@@ -24,9 +24,9 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/core/design/app_colors.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/settings/presentation/controllers/save_settings.dart';
|
||||
import 'package:weblibre/features/tor/domain/services/tor_proxy.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/tor/presentation/screens/country_picker.dart';
|
||||
import 'package:weblibre/features/user/data/models/tor_settings.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/tor_settings.dart';
|
||||
@@ -34,7 +34,7 @@ import 'package:weblibre/presentation/hooks/on_initialization.dart';
|
||||
import 'package:weblibre/utils/ui_helper.dart';
|
||||
|
||||
class TorProxyScreen extends HookConsumerWidget {
|
||||
const TorProxyScreen();
|
||||
const TorProxyScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
@@ -465,7 +465,8 @@ class TorProxyScreen extends HookConsumerWidget {
|
||||
),
|
||||
ListTile(
|
||||
enabled: !torIsBusy,
|
||||
leading: torSettings.entryNodeCountry.mapNotNull(
|
||||
leading:
|
||||
torSettings.entryNodeCountry.mapNotNull(
|
||||
(code) => CountryFlag.fromCountryCode(
|
||||
code,
|
||||
theme: const EmojiTheme(size: 28),
|
||||
@@ -486,8 +487,9 @@ class TorProxyScreen extends HookConsumerWidget {
|
||||
$extra: torSettings.entryNodeCountry,
|
||||
).push<String>(context);
|
||||
if (result == null) return;
|
||||
final value =
|
||||
result == automaticCountry ? null : result;
|
||||
final value = result == automaticCountry
|
||||
? null
|
||||
: result;
|
||||
await ref
|
||||
.read(saveTorSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
@@ -498,7 +500,8 @@ class TorProxyScreen extends HookConsumerWidget {
|
||||
),
|
||||
ListTile(
|
||||
enabled: !torIsBusy,
|
||||
leading: torSettings.exitNodeCountry.mapNotNull(
|
||||
leading:
|
||||
torSettings.exitNodeCountry.mapNotNull(
|
||||
(code) => CountryFlag.fromCountryCode(
|
||||
code,
|
||||
theme: const EmojiTheme(size: 28),
|
||||
@@ -519,8 +522,9 @@ class TorProxyScreen extends HookConsumerWidget {
|
||||
$extra: torSettings.exitNodeCountry,
|
||||
).push<String>(context);
|
||||
if (result == null) return;
|
||||
final value =
|
||||
result == automaticCountry ? null : result;
|
||||
final value = result == automaticCountry
|
||||
? null
|
||||
: result;
|
||||
await ref
|
||||
.read(saveTorSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
|
||||
@@ -23,7 +23,7 @@ import 'package:weblibre/core/design/app_colors.dart';
|
||||
import 'package:weblibre/presentation/icons/tor_icons.dart';
|
||||
|
||||
class TorDialog extends StatelessWidget {
|
||||
const TorDialog();
|
||||
const TorDialog({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -26,6 +26,8 @@ import 'package:weblibre/presentation/icons/tor_icons.dart';
|
||||
import 'package:weblibre/presentation/widgets/animate_gradient_shader.dart';
|
||||
|
||||
class TorNotification extends HookConsumerWidget {
|
||||
const TorNotification({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final appColors = AppColors.of(context);
|
||||
|
||||
Reference in New Issue
Block a user