reset direct dns when region change
This commit is contained in:
@@ -106,12 +106,36 @@ class PreferencesNotifier<T, P> extends StateNotifier<T> {
|
|||||||
static StateNotifierProvider<PreferencesNotifier<T, P>, T> create<T, P>(
|
static StateNotifierProvider<PreferencesNotifier<T, P>, T> create<T, P>(
|
||||||
String key,
|
String key,
|
||||||
T defaultValue, {
|
T defaultValue, {
|
||||||
|
T Function(Ref ref)? defaultValueFunction,
|
||||||
T Function(P value)? mapFrom,
|
T Function(P value)? mapFrom,
|
||||||
P Function(T value)? mapTo,
|
P Function(T value)? mapTo,
|
||||||
bool Function(T value)? validator,
|
bool Function(T value)? validator,
|
||||||
T? overrideValue,
|
T? overrideValue,
|
||||||
}) =>
|
}) =>
|
||||||
StateNotifierProvider(
|
StateNotifierProvider(
|
||||||
|
(ref) => PreferencesNotifier._(
|
||||||
|
ref: ref,
|
||||||
|
entry: PreferencesEntry<T, P>(
|
||||||
|
preferences: ref.read(sharedPreferencesProvider).requireValue,
|
||||||
|
key: key,
|
||||||
|
defaultValue: defaultValueFunction?.call(ref) ?? defaultValue,
|
||||||
|
mapFrom: mapFrom,
|
||||||
|
mapTo: mapTo,
|
||||||
|
validator: validator,
|
||||||
|
),
|
||||||
|
overrideValue: overrideValue,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
static AutoDisposeStateNotifierProvider<PreferencesNotifier<T, P>, T> createAutoDispose<T, P>(
|
||||||
|
String key,
|
||||||
|
T defaultValue, {
|
||||||
|
T Function(P value)? mapFrom,
|
||||||
|
P Function(T value)? mapTo,
|
||||||
|
bool Function(T value)? validator,
|
||||||
|
T? overrideValue,
|
||||||
|
}) =>
|
||||||
|
StateNotifierProvider.autoDispose(
|
||||||
(ref) => PreferencesNotifier._(
|
(ref) => PreferencesNotifier._(
|
||||||
ref: ref,
|
ref: ref,
|
||||||
entry: PreferencesEntry<T, P>(
|
entry: PreferencesEntry<T, P>(
|
||||||
@@ -126,30 +150,6 @@ class PreferencesNotifier<T, P> extends StateNotifier<T> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
static AutoDisposeStateNotifierProvider<PreferencesNotifier<T, P>, T>
|
|
||||||
createAutoDispose<T, P>(
|
|
||||||
String key,
|
|
||||||
T defaultValue, {
|
|
||||||
T Function(P value)? mapFrom,
|
|
||||||
P Function(T value)? mapTo,
|
|
||||||
bool Function(T value)? validator,
|
|
||||||
T? overrideValue,
|
|
||||||
}) =>
|
|
||||||
StateNotifierProvider.autoDispose(
|
|
||||||
(ref) => PreferencesNotifier._(
|
|
||||||
ref: ref,
|
|
||||||
entry: PreferencesEntry<T, P>(
|
|
||||||
preferences: ref.read(sharedPreferencesProvider).requireValue,
|
|
||||||
key: key,
|
|
||||||
defaultValue: defaultValue,
|
|
||||||
mapFrom: mapFrom,
|
|
||||||
mapTo: mapTo,
|
|
||||||
validator: validator,
|
|
||||||
),
|
|
||||||
overrideValue: overrideValue,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
P raw() {
|
P raw() {
|
||||||
final value = overrideValue ?? state;
|
final value = overrideValue ?? state;
|
||||||
if (entry.mapTo != null) return entry.mapTo!(value);
|
if (entry.mapTo != null) return entry.mapTo!(value);
|
||||||
|
|||||||
@@ -84,8 +84,11 @@ class RegionPrefTile extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
if (selectedRegion != null) {
|
if (selectedRegion != null) {
|
||||||
// await ref.read(Preferences.region.notifier).update(selectedRegion);
|
// await ref.read(Preferences.region.notifier).update(selectedRegion);
|
||||||
|
|
||||||
await ref.watch(ConfigOptions.region.notifier).update(selectedRegion);
|
await ref.watch(ConfigOptions.region.notifier).update(selectedRegion);
|
||||||
|
|
||||||
|
await ref.watch(ConfigOptions.directDnsAddress.notifier).reset();
|
||||||
|
|
||||||
// await ref.read(configOptionNotifierProvider.notifier).build();
|
// await ref.read(configOptionNotifierProvider.notifier).build();
|
||||||
// await ref.watch(ConfigOptions.resolveDestination.notifier).update(!ref.watch(ConfigOptions.resolveDestination.notifier).raw());
|
// await ref.watch(ConfigOptions.resolveDestination.notifier).update(!ref.watch(ConfigOptions.resolveDestination.notifier).raw());
|
||||||
//for reload config
|
//for reload config
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ abstract class ConfigOptions {
|
|||||||
static final directDnsAddress = PreferencesNotifier.create<String, String>(
|
static final directDnsAddress = PreferencesNotifier.create<String, String>(
|
||||||
"direct-dns-address",
|
"direct-dns-address",
|
||||||
"1.1.1.1",
|
"1.1.1.1",
|
||||||
|
defaultValueFunction: (ref) => ref.read(region) == Region.cn ? "223.5.5.5" : "1.1.1.1",
|
||||||
validator: (value) => value.isNotBlank,
|
validator: (value) => value.isNotBlank,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ class ConfigOptionsPage extends HookConsumerWidget {
|
|||||||
choices: Region.values,
|
choices: Region.values,
|
||||||
title: t.settings.general.region,
|
title: t.settings.general.region,
|
||||||
presentChoice: (value) => value.present(t),
|
presentChoice: (value) => value.present(t),
|
||||||
|
onChanged: (val) => ref.watch(ConfigOptions.directDnsAddress.notifier).reset(),
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
title: Text(experimental(t.config.blockAds)),
|
title: Text(experimental(t.config.blockAds)),
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class ChoicePreferenceWidget<T> extends StatelessWidget {
|
|||||||
required this.title,
|
required this.title,
|
||||||
required this.presentChoice,
|
required this.presentChoice,
|
||||||
this.validateInput,
|
this.validateInput,
|
||||||
|
this.onChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
final T selected;
|
final T selected;
|
||||||
@@ -70,7 +71,7 @@ class ChoicePreferenceWidget<T> extends StatelessWidget {
|
|||||||
final String title;
|
final String title;
|
||||||
final String Function(T value) presentChoice;
|
final String Function(T value) presentChoice;
|
||||||
final bool Function(String value)? validateInput;
|
final bool Function(String value)? validateInput;
|
||||||
|
final ValueChanged<T>? onChanged;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@@ -88,7 +89,9 @@ class ChoicePreferenceWidget<T> extends StatelessWidget {
|
|||||||
if (selection == null) {
|
if (selection == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await preferences.update(selection);
|
final out = await preferences.update(selection);
|
||||||
|
onChanged?.call(selection);
|
||||||
|
return out;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ class IntroPage extends HookConsumerWidget with PresLogger {
|
|||||||
'Timezone Region: ${regionLocale.region} Locale: ${regionLocale.locale}',
|
'Timezone Region: ${regionLocale.region} Locale: ${regionLocale.locale}',
|
||||||
);
|
);
|
||||||
await ref.read(ConfigOptions.region.notifier).update(regionLocale.region);
|
await ref.read(ConfigOptions.region.notifier).update(regionLocale.region);
|
||||||
|
await ref.watch(ConfigOptions.directDnsAddress.notifier).reset();
|
||||||
await ref.read(localePreferencesProvider.notifier).changeLocale(regionLocale.locale);
|
await ref.read(localePreferencesProvider.notifier).changeLocale(regionLocale.locale);
|
||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user