Files
umbrix/lib/features/settings/widgets/general_setting_tiles.dart
2026-01-15 12:28:40 +03:00

157 lines
6.1 KiB
Dart

import 'dart:io';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:hiddify/core/haptic/haptic_service.dart';
import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/core/preferences/general_preferences.dart';
import 'package:hiddify/features/auto_start/notifier/auto_start_notifier.dart';
import 'package:hiddify/features/common/general_pref_tiles.dart';
import 'package:hiddify/features/config_option/data/config_option_repository.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class GeneralSettingTiles extends HookConsumerWidget {
const GeneralSettingTiles({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
return Column(
children: [
// UMBRIX: Язык и тема перенесены в левое меню
const EnableAnalyticsPrefTile(),
SwitchListTile(
title: Text(t.config.blockAds),
subtitle: Text(
t.config.blockAdsWarning.subtitle,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
secondary: const Icon(FluentIcons.shield_prohibited_24_regular),
value: ref.watch(ConfigOptions.blockAds),
onChanged: (value) async {
if (value) {
// Показываем предупреждение при включении
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
icon: const Icon(Icons.warning_amber_rounded, size: 48),
title: Text(t.config.bypassLanWarning.title),
content: Text(
t.config.blockAdsWarning.message,
style: const TextStyle(fontSize: 14),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(t.config.bypassLanWarning.cancel),
),
FilledButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(t.config.bypassLanWarning.enable),
),
],
),
);
if (confirmed == true) {
ref.read(ConfigOptions.blockAds.notifier).update(true);
}
} else {
ref.read(ConfigOptions.blockAds.notifier).update(false);
}
},
),
SwitchListTile(
title: Text(t.config.bypassLan),
subtitle: Text(
t.config.bypassLanWarning.subtitle,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
secondary: const Icon(FluentIcons.home_24_regular),
value: ref.watch(ConfigOptions.bypassLan),
onChanged: (value) async {
if (value) {
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
icon: const Icon(Icons.warning_amber_rounded, size: 48),
title: Text(t.config.bypassLanWarning.title),
content: Text(
t.config.bypassLanWarning.message,
style: const TextStyle(fontSize: 14),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(t.config.bypassLanWarning.cancel),
),
FilledButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(t.config.bypassLanWarning.enable),
),
],
),
);
if (confirmed == true) {
ref.read(ConfigOptions.bypassLan.notifier).update(true);
}
} else {
ref.read(ConfigOptions.bypassLan.notifier).update(false);
}
},
),
SwitchListTile(
title: Text(t.settings.general.autoIpCheck),
secondary: const Icon(FluentIcons.globe_search_24_regular),
value: ref.watch(Preferences.autoCheckIp),
onChanged: ref.read(Preferences.autoCheckIp.notifier).update,
),
if (Platform.isAndroid) ...[
SwitchListTile(
title: Text(t.settings.general.dynamicNotification),
secondary: const Icon(FluentIcons.top_speed_24_regular),
value: ref.watch(Preferences.dynamicNotification),
onChanged: (value) async {
await ref.read(Preferences.dynamicNotification.notifier).update(value);
},
),
SwitchListTile(
title: Text(t.settings.general.hapticFeedback),
secondary: const Icon(FluentIcons.phone_vibrate_24_regular),
value: ref.watch(hapticServiceProvider),
onChanged: ref.read(hapticServiceProvider.notifier).updatePreference,
),
],
if (PlatformUtils.isDesktop) ...[
const ClosingPrefTile(),
SwitchListTile(
title: Text(t.settings.general.autoStart),
value: ref.watch(autoStartNotifierProvider).asData!.value,
onChanged: (value) async {
if (value) {
await ref.read(autoStartNotifierProvider.notifier).enable();
} else {
await ref.read(autoStartNotifierProvider.notifier).disable();
}
},
),
SwitchListTile(
title: Text(t.settings.general.silentStart),
value: ref.watch(Preferences.silentStart),
onChanged: (value) async {
await ref.read(Preferences.silentStart.notifier).update(value);
},
),
],
],
);
}
}