onboarding make ublock & engine hardenings default
This commit is contained in:
@@ -27,6 +27,7 @@ import 'package:weblibre/core/providers/router.dart';
|
|||||||
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_addon.dart';
|
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_addon.dart';
|
||||||
import 'package:weblibre/features/onboarding/domain/entities/onboarding_mode.dart';
|
import 'package:weblibre/features/onboarding/domain/entities/onboarding_mode.dart';
|
||||||
import 'package:weblibre/features/onboarding/domain/providers.dart';
|
import 'package:weblibre/features/onboarding/domain/providers.dart';
|
||||||
|
import 'package:weblibre/features/onboarding/presentation/onboarding_defaults.dart';
|
||||||
import 'package:weblibre/features/onboarding/presentation/pages/abstract/i_form_page.dart';
|
import 'package:weblibre/features/onboarding/presentation/pages/abstract/i_form_page.dart';
|
||||||
import 'package:weblibre/features/onboarding/presentation/pages/ai_configuration.dart';
|
import 'package:weblibre/features/onboarding/presentation/pages/ai_configuration.dart';
|
||||||
import 'package:weblibre/features/onboarding/presentation/pages/default_search.dart';
|
import 'package:weblibre/features/onboarding/presentation/pages/default_search.dart';
|
||||||
@@ -61,10 +62,20 @@ class OnboardingScreen extends HookConsumerWidget {
|
|||||||
final eulaAccepted = ref.watch(eulaAcceptedProvider);
|
final eulaAccepted = ref.watch(eulaAcceptedProvider);
|
||||||
final onboardingMode = ref.watch(onboardingModeProvider);
|
final onboardingMode = ref.watch(onboardingModeProvider);
|
||||||
|
|
||||||
|
final isFreshOnboarding = currentRevision < 0;
|
||||||
final isReturningUser = currentRevision == 2;
|
final isReturningUser = currentRevision == 2;
|
||||||
final showDetailedPages =
|
final showDetailedPages =
|
||||||
isReturningUser || onboardingMode == OnboardingMode.detailed;
|
isReturningUser || onboardingMode == OnboardingMode.detailed;
|
||||||
|
|
||||||
|
useEffect(() {
|
||||||
|
if (!isFreshOnboarding || onboardingMode == OnboardingMode.restore) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
unawaited(applyOnboardingPrivacyDefaults(ref));
|
||||||
|
return null;
|
||||||
|
}, [isFreshOnboarding, onboardingMode]);
|
||||||
|
|
||||||
final pages = useMemoized<List<Widget>>(() {
|
final pages = useMemoized<List<Widget>>(() {
|
||||||
switch (currentRevision) {
|
switch (currentRevision) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -195,36 +206,34 @@ class OnboardingScreen extends HookConsumerWidget {
|
|||||||
unawaited(
|
unawaited(
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute<void>(
|
MaterialPageRoute<void>(
|
||||||
builder: (_) =>
|
builder: (_) => ProfileRestoreScreen(
|
||||||
ProfileRestoreScreen(
|
backupFileUri: uri,
|
||||||
backupFileUri: uri,
|
forcedTarget:
|
||||||
forcedTarget:
|
RestoreTarget.createNew,
|
||||||
RestoreTarget.createNew,
|
onRestoreSuccess: (_, profile) async {
|
||||||
onRestoreSuccess:
|
await ref
|
||||||
(_, profile) async {
|
.read(
|
||||||
await ref
|
onboardingRepositoryProvider
|
||||||
.read(
|
.notifier,
|
||||||
onboardingRepositoryProvider
|
)
|
||||||
.notifier,
|
.pushRevision(
|
||||||
)
|
targetRevision,
|
||||||
.pushRevision(
|
);
|
||||||
targetRevision,
|
if (profile != null) {
|
||||||
);
|
await ref
|
||||||
if (profile != null) {
|
.read(
|
||||||
await ref
|
profileRepositoryProvider
|
||||||
.read(
|
.notifier,
|
||||||
profileRepositoryProvider
|
)
|
||||||
.notifier,
|
.switchProfile(
|
||||||
)
|
profile.id,
|
||||||
.switchProfile(
|
);
|
||||||
profile.id,
|
await exitApp(
|
||||||
);
|
ref.container,
|
||||||
await exitApp(
|
);
|
||||||
ref.container,
|
}
|
||||||
);
|
},
|
||||||
}
|
),
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -254,6 +263,8 @@ class OnboardingScreen extends HookConsumerWidget {
|
|||||||
.read(browserAddonServiceProvider.notifier)
|
.read(browserAddonServiceProvider.notifier)
|
||||||
.install('uBlock0@raymondhill.net'),
|
.install('uBlock0@raymondhill.net'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await applyOnboardingOptimizedUBlockDefaults(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ref
|
await ref
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024-2026 Fabian Freund.
|
||||||
|
*
|
||||||
|
* This file is part of WebLibre
|
||||||
|
* (see https://weblibre.eu).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:weblibre/core/logger.dart';
|
||||||
|
import 'package:weblibre/features/geckoview/features/preferences/data/repositories/preference_settings.dart';
|
||||||
|
import 'package:weblibre/features/geckoview/features/tabs/utils/setting_groups_serializer.dart';
|
||||||
|
import 'package:weblibre/features/user/data/models/engine_settings.dart';
|
||||||
|
import 'package:weblibre/features/user/data/models/ublock_filter_list_settings.dart';
|
||||||
|
import 'package:weblibre/features/user/data/providers/ublock_assets.dart';
|
||||||
|
import 'package:weblibre/features/user/domain/repositories/engine_settings.dart';
|
||||||
|
|
||||||
|
Future<void> applyOnboardingOptimizedUBlockDefaults(WidgetRef ref) async {
|
||||||
|
try {
|
||||||
|
final registry = await ref.read(ublockAssetsRegistryProvider.future);
|
||||||
|
final optimized = UBlockFilterListSettings.optimizedDefaults(registry);
|
||||||
|
|
||||||
|
await ref
|
||||||
|
.read(engineSettingsRepositoryProvider.notifier)
|
||||||
|
.updateSettings(
|
||||||
|
(current) => current.copyWith.ublockFilterListSettings(optimized),
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
logger.w(
|
||||||
|
'Failed applying optimized uBlock defaults during onboarding',
|
||||||
|
error: e,
|
||||||
|
stackTrace: s,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> applyOnboardingPrivacyDefaults(WidgetRef ref) async {
|
||||||
|
try {
|
||||||
|
await ref
|
||||||
|
.read(
|
||||||
|
unifiedPreferenceSettingsRepositoryProvider(
|
||||||
|
PreferencePartition.user,
|
||||||
|
).notifier,
|
||||||
|
)
|
||||||
|
.apply();
|
||||||
|
|
||||||
|
await ref
|
||||||
|
.read(engineSettingsRepositoryProvider.notifier)
|
||||||
|
.updateSettings(
|
||||||
|
(current) => current.copyWith(lnaEnabled: true, lnaBlocking: true),
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
logger.w(
|
||||||
|
'Failed applying privacy defaults during onboarding',
|
||||||
|
error: e,
|
||||||
|
stackTrace: s,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,13 +24,9 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:weblibre/core/logger.dart';
|
|
||||||
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_addon.dart';
|
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_addon.dart';
|
||||||
|
import 'package:weblibre/features/onboarding/presentation/onboarding_defaults.dart';
|
||||||
import 'package:weblibre/features/onboarding/presentation/pages/abstract/i_form_page.dart';
|
import 'package:weblibre/features/onboarding/presentation/pages/abstract/i_form_page.dart';
|
||||||
import 'package:weblibre/features/user/data/models/engine_settings.dart';
|
|
||||||
import 'package:weblibre/features/user/data/models/ublock_filter_list_settings.dart';
|
|
||||||
import 'package:weblibre/features/user/data/providers/ublock_assets.dart';
|
|
||||||
import 'package:weblibre/features/user/domain/repositories/engine_settings.dart';
|
|
||||||
import 'package:weblibre/presentation/widgets/browser_page.dart';
|
import 'package:weblibre/presentation/widgets/browser_page.dart';
|
||||||
|
|
||||||
class UBlockOptInPage extends HookConsumerWidget implements IFormPage {
|
class UBlockOptInPage extends HookConsumerWidget implements IFormPage {
|
||||||
@@ -97,29 +93,7 @@ There are many other lists available to block even more.
|
|||||||
onSaved: (newValue) {
|
onSaved: (newValue) {
|
||||||
if (newValue != true || !installUBlock.value) return;
|
if (newValue != true || !installUBlock.value) return;
|
||||||
|
|
||||||
Future<void> applyOptimizedDefaults() async {
|
unawaited(applyOnboardingOptimizedUBlockDefaults(ref));
|
||||||
try {
|
|
||||||
final registry = await ref.read(
|
|
||||||
ublockAssetsRegistryProvider.future,
|
|
||||||
);
|
|
||||||
final optimized =
|
|
||||||
UBlockFilterListSettings.optimizedDefaults(registry);
|
|
||||||
await ref
|
|
||||||
.read(engineSettingsRepositoryProvider.notifier)
|
|
||||||
.updateSettings(
|
|
||||||
(current) => current.copyWith
|
|
||||||
.ublockFilterListSettings(optimized),
|
|
||||||
);
|
|
||||||
} catch (e, s) {
|
|
||||||
logger.w(
|
|
||||||
'Failed applying optimized uBlock defaults during onboarding',
|
|
||||||
error: e,
|
|
||||||
stackTrace: s,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unawaited(applyOptimizedDefaults());
|
|
||||||
},
|
},
|
||||||
builder: (field) => SwitchListTile(
|
builder: (field) => SwitchListTile(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
|
|||||||
Reference in New Issue
Block a user