Backup before removing hiddify references
This commit is contained in:
@@ -5,7 +5,10 @@ import 'package:hiddify/core/preferences/actions_at_closing.dart';
|
||||
// import 'package:hiddify/core/model/region.dart';
|
||||
import 'package:hiddify/core/preferences/preferences_provider.dart';
|
||||
import 'package:hiddify/core/utils/preferences_utils.dart';
|
||||
import 'package:hiddify/features/connection/model/connection_status.dart';
|
||||
import 'package:hiddify/features/connection/notifier/connection_notifier.dart';
|
||||
import 'package:hiddify/features/per_app_proxy/model/per_app_proxy_mode.dart';
|
||||
import 'package:hiddify/features/profile/notifier/active_profile_notifier.dart';
|
||||
import 'package:hiddify/utils/platform_utils.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
@@ -33,7 +36,7 @@ abstract class Preferences {
|
||||
|
||||
static final perAppProxyMode = PreferencesNotifier.create<PerAppProxyMode, String>(
|
||||
"per_app_proxy_mode",
|
||||
PerAppProxyMode.off,
|
||||
PerAppProxyMode.exclude,
|
||||
mapFrom: PerAppProxyMode.values.byName,
|
||||
mapTo: (value) => value.name,
|
||||
);
|
||||
@@ -103,14 +106,45 @@ class PerAppProxyList extends _$PerAppProxyList {
|
||||
);
|
||||
|
||||
@override
|
||||
List<String> build() => ref.watch(Preferences.perAppProxyMode) == PerAppProxyMode.include ? _include.read() : _exclude.read();
|
||||
List<String> build() {
|
||||
// Слушаем изменения режима и перестраиваем список
|
||||
final mode = ref.watch(Preferences.perAppProxyMode);
|
||||
return mode == PerAppProxyMode.include ? _include.read() : _exclude.read();
|
||||
}
|
||||
|
||||
Future<void> update(List<String> value) {
|
||||
state = value;
|
||||
if (ref.read(Preferences.perAppProxyMode) == PerAppProxyMode.include) {
|
||||
return _include.write(value);
|
||||
Future<void> update(List<String> value) async {
|
||||
print('[PerAppProxyList] update() вызван с ${value.length} приложениями');
|
||||
final mode = ref.read(Preferences.perAppProxyMode);
|
||||
print('[PerAppProxyList] Текущий режим: $mode');
|
||||
|
||||
// Сначала сохраняем в SharedPreferences
|
||||
if (mode == PerAppProxyMode.include) {
|
||||
await _include.write(value);
|
||||
print('[PerAppProxyList] Записан include список: $value');
|
||||
} else {
|
||||
await _exclude.write(value);
|
||||
print('[PerAppProxyList] Записан exclude список: $value');
|
||||
}
|
||||
|
||||
// Затем обновляем локальное состояние
|
||||
state = value;
|
||||
print('[PerAppProxyList] State обновлён');
|
||||
|
||||
// Автоматически перезапускаем VPN если он активен
|
||||
print('[PerAppProxyList] Вызываю _reconnectVpnIfActive()');
|
||||
await _reconnectVpnIfActive();
|
||||
}
|
||||
|
||||
Future<void> _reconnectVpnIfActive() async {
|
||||
try {
|
||||
final connectionNotifier = await ref.read(connectionNotifierProvider.future);
|
||||
if (connectionNotifier is Connected) {
|
||||
final profile = await ref.read(activeProfileProvider.future);
|
||||
await ref.read(connectionNotifierProvider.notifier).reconnect(profile);
|
||||
}
|
||||
} catch (_) {
|
||||
// Игнорируем ошибки если connection provider не инициализирован
|
||||
}
|
||||
return _exclude.write(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,8 +159,22 @@ class ExcludedDomainsList extends _$ExcludedDomainsList {
|
||||
@override
|
||||
List<String> build() => _pref.read();
|
||||
|
||||
Future<void> update(List<String> value) {
|
||||
Future<void> update(List<String> value) async {
|
||||
state = value;
|
||||
return _pref.write(value);
|
||||
await _pref.write(value);
|
||||
// Автоматически перезапускаем VPN если он активен
|
||||
await _reconnectVpnIfActive();
|
||||
}
|
||||
|
||||
Future<void> _reconnectVpnIfActive() async {
|
||||
try {
|
||||
final connectionNotifier = await ref.read(connectionNotifierProvider.future);
|
||||
if (connectionNotifier is Connected) {
|
||||
final profile = await ref.read(activeProfileProvider.future);
|
||||
await ref.read(connectionNotifierProvider.notifier).reconnect(profile);
|
||||
}
|
||||
} catch (_) {
|
||||
// Игнорируем ошибки если connection provider не инициализирован
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user