custom user agent
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/core/routing/routes.dart';
|
||||
import 'package:lensai/extensions/nullable.dart';
|
||||
@@ -10,6 +12,7 @@ import 'package:lensai/features/user/data/models/engine_settings.dart';
|
||||
import 'package:lensai/features/user/data/models/general_settings.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/engine_settings.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/general_settings.dart';
|
||||
import 'package:universal_io/io.dart';
|
||||
|
||||
class WebEngineSettingsScreen extends HookConsumerWidget {
|
||||
const WebEngineSettingsScreen();
|
||||
@@ -19,6 +22,11 @@ class WebEngineSettingsScreen extends HookConsumerWidget {
|
||||
final generalSettings = ref.watch(generalSettingsRepositoryProvider);
|
||||
final engineSettings = ref.watch(engineSettingsRepositoryProvider);
|
||||
|
||||
final userAgentTextController = useTextEditingController(
|
||||
text: engineSettings.userAgent,
|
||||
keys: [engineSettings.userAgent],
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Web Engine Settings')),
|
||||
body: FadingScroll(
|
||||
@@ -297,6 +305,56 @@ class WebEngineSettingsScreen extends HookConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(MdiIcons.cardAccountDetails),
|
||||
title: TextField(
|
||||
controller: userAgentTextController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Custom User Agent',
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
hintText: 'Mozilla/5.0 …',
|
||||
),
|
||||
onSubmitted: (value) async {
|
||||
await ref
|
||||
.read(saveEngineSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.userAgent(value),
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
final restart = await showDialog<bool>(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: const Text('User Agent Changed'),
|
||||
content: const Text(
|
||||
'The app needs to restart for the new user agent to take effect',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.pop(false);
|
||||
},
|
||||
child: const Text('Later'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.pop(true);
|
||||
},
|
||||
child: const Text('Restart Now'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (restart == true) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Web Engine Hardening'),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
|
||||
@@ -46,6 +46,7 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
|
||||
required super.cookieBannerHandlingGlobalRules,
|
||||
required super.cookieBannerHandlingGlobalRulesSubFrames,
|
||||
required super.webContentIsolationStrategy,
|
||||
required super.userAgent,
|
||||
});
|
||||
|
||||
EngineSettings.withDefaults({
|
||||
@@ -59,6 +60,7 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
|
||||
bool? cookieBannerHandlingGlobalRules,
|
||||
bool? cookieBannerHandlingGlobalRulesSubFrames,
|
||||
WebContentIsolationStrategy? webContentIsolationStrategy,
|
||||
super.userAgent,
|
||||
}) : super(
|
||||
javascriptEnabled: javascriptEnabled ?? true,
|
||||
trackingProtectionPolicy:
|
||||
@@ -97,5 +99,6 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
|
||||
super.cookieBannerHandlingGlobalRules,
|
||||
super.cookieBannerHandlingGlobalRulesSubFrames,
|
||||
super.webContentIsolationStrategy,
|
||||
super.userAgent,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ abstract class _$EngineSettingsCWProxy {
|
||||
WebContentIsolationStrategy? webContentIsolationStrategy,
|
||||
);
|
||||
|
||||
EngineSettings userAgent(String? userAgent);
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `EngineSettings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
@@ -56,6 +58,7 @@ abstract class _$EngineSettingsCWProxy {
|
||||
bool? cookieBannerHandlingGlobalRules,
|
||||
bool? cookieBannerHandlingGlobalRulesSubFrames,
|
||||
WebContentIsolationStrategy? webContentIsolationStrategy,
|
||||
String? userAgent,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,6 +121,9 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
|
||||
WebContentIsolationStrategy? webContentIsolationStrategy,
|
||||
) => this(webContentIsolationStrategy: webContentIsolationStrategy);
|
||||
|
||||
@override
|
||||
EngineSettings userAgent(String? userAgent) => this(userAgent: userAgent);
|
||||
|
||||
@override
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `EngineSettings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
@@ -138,6 +144,7 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
|
||||
Object? cookieBannerHandlingGlobalRulesSubFrames =
|
||||
const $CopyWithPlaceholder(),
|
||||
Object? webContentIsolationStrategy = const $CopyWithPlaceholder(),
|
||||
Object? userAgent = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return EngineSettings(
|
||||
javascriptEnabled:
|
||||
@@ -193,6 +200,11 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
|
||||
? _value.webContentIsolationStrategy
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: webContentIsolationStrategy as WebContentIsolationStrategy?,
|
||||
userAgent:
|
||||
userAgent == const $CopyWithPlaceholder()
|
||||
? _value.userAgent
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: userAgent as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -239,11 +251,13 @@ EngineSettings _$EngineSettingsFromJson(Map<String, dynamic> json) =>
|
||||
_$WebContentIsolationStrategyEnumMap,
|
||||
json['webContentIsolationStrategy'],
|
||||
),
|
||||
userAgent: json['userAgent'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$EngineSettingsToJson(
|
||||
EngineSettings instance,
|
||||
) => <String, dynamic>{
|
||||
'userAgent': instance.userAgent,
|
||||
'javascriptEnabled': instance.javascriptEnabled,
|
||||
'trackingProtectionPolicy':
|
||||
_$TrackingProtectionPolicyEnumMap[instance.trackingProtectionPolicy]!,
|
||||
|
||||
@@ -82,6 +82,10 @@ class EngineSettingsRepository extends _$EngineSettingsRepository {
|
||||
DriftSqlType.string,
|
||||
db.typeMapping,
|
||||
),
|
||||
'userAgent': settings['userAgent']?.readAs(
|
||||
DriftSqlType.string,
|
||||
db.typeMapping,
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'engine_settings.dart';
|
||||
// **************************************************************************
|
||||
|
||||
String _$engineSettingsRepositoryHash() =>
|
||||
r'bd255f91f7cee702d9cfcb10bfdf3cd013234901';
|
||||
r'87e308c8bd4390d1d5c401532a0c35cd96f6176e';
|
||||
|
||||
/// See also [EngineSettingsRepository].
|
||||
@ProviderFor(EngineSettingsRepository)
|
||||
|
||||
Reference in New Issue
Block a user