improve hardening options
This commit is contained in:
@@ -10,12 +10,16 @@ class PreferenceSettingGroup with FastEquatable {
|
|||||||
|
|
||||||
final Map<String, PreferenceSetting> settings;
|
final Map<String, PreferenceSetting> settings;
|
||||||
|
|
||||||
bool get isActive => settings.values.every(
|
bool get isActiveOrOptional => settings.values.every(
|
||||||
(setting) => setting.requireUserOptIn || setting.isActive,
|
(setting) => setting.requireUserOptIn || setting.isActive,
|
||||||
);
|
);
|
||||||
|
|
||||||
bool get isPartlyActive => settings.values.any((setting) => setting.isActive);
|
bool get isPartlyActive => settings.values.any((setting) => setting.isActive);
|
||||||
|
|
||||||
|
bool get hasInactiveOptional => settings.values.any(
|
||||||
|
(setting) => !setting.isActive && setting.requireUserOptIn,
|
||||||
|
);
|
||||||
|
|
||||||
PreferenceSettingGroup({required this.description, required this.settings});
|
PreferenceSettingGroup({required this.description, required this.settings});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class WebEngineHardeningScreen extends HookConsumerWidget {
|
|||||||
final allGroupsActive = useMemoized(
|
final allGroupsActive = useMemoized(
|
||||||
() =>
|
() =>
|
||||||
preferenceGroups.valueOrNull?.values.every(
|
preferenceGroups.valueOrNull?.values.every(
|
||||||
(element) => element.isActive,
|
(element) => element.isActiveOrOptional,
|
||||||
) ??
|
) ??
|
||||||
false,
|
false,
|
||||||
[EquatableValue(preferenceGroups.valueOrNull)],
|
[EquatableValue(preferenceGroups.valueOrNull)],
|
||||||
@@ -78,9 +78,12 @@ class WebEngineHardeningScreen extends HookConsumerWidget {
|
|||||||
subtitle: group.value.description.mapNotNull(
|
subtitle: group.value.description.mapNotNull(
|
||||||
(description) => Text(description),
|
(description) => Text(description),
|
||||||
),
|
),
|
||||||
leading: HardeningGroupIcon(
|
leading: Badge(
|
||||||
isActive: group.value.isActive,
|
isLabelVisible: group.value.hasInactiveOptional,
|
||||||
isPartlyActive: group.value.isPartlyActive,
|
child: HardeningGroupIcon(
|
||||||
|
isActive: group.value.isActiveOrOptional,
|
||||||
|
isPartlyActive: group.value.isPartlyActive,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
trailing: const Icon(Icons.chevron_right),
|
trailing: const Icon(Icons.chevron_right),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class WebEngineHardeningGroupScreen extends HookConsumerWidget {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: SwitchListTile(
|
child: SwitchListTile(
|
||||||
value: group.isActive,
|
value: group.isActiveOrOptional,
|
||||||
title: Text(
|
title: Text(
|
||||||
groupName,
|
groupName,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -86,8 +86,42 @@ class WebEngineHardeningGroupScreen extends HookConsumerWidget {
|
|||||||
child: SwitchListTile(
|
child: SwitchListTile(
|
||||||
value: setting.value.isActive,
|
value: setting.value.isActive,
|
||||||
title: Text(setting.value.title ?? setting.key),
|
title: Text(setting.value.title ?? setting.key),
|
||||||
subtitle: setting.value.description.mapNotNull(
|
subtitle: Text.rich(
|
||||||
(description) => Text(description),
|
TextSpan(
|
||||||
|
children: [
|
||||||
|
if (setting.value.requireUserOptIn)
|
||||||
|
WidgetSpan(
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
vertical: 2,
|
||||||
|
),
|
||||||
|
margin: const EdgeInsets.only(
|
||||||
|
right: 8,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.error,
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'Optional',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color:
|
||||||
|
theme.colorScheme.onError,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (setting.value.description != null)
|
||||||
|
TextSpan(
|
||||||
|
text: setting.value.description,
|
||||||
|
// style: theme.textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
secondary: HardeningGroupIcon(
|
secondary: HardeningGroupIcon(
|
||||||
isActive: setting.value.isActive,
|
isActive: setting.value.isActive,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
|
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
|
||||||
|
|
||||||
final _apiInstance = GeckoPrefApi();
|
final _apiInstance = GeckoPrefApi();
|
||||||
@@ -16,7 +18,7 @@ class GeckoPrefService {
|
|||||||
final value = switch (pref.value) {
|
final value = switch (pref.value) {
|
||||||
final bool x => '$x',
|
final bool x => '$x',
|
||||||
final int x => '$x',
|
final int x => '$x',
|
||||||
final String x => "'$x'", //Use single ticks to allow json
|
final String x => jsonEncode(x),
|
||||||
_ => throw Exception('Unknow pref type'),
|
_ => throw Exception('Unknow pref type'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user