added support for custom addon collections

This commit is contained in:
Fabian Freund
2025-09-30 13:02:17 +02:00
parent 7c4662a7be
commit 751e22ac5e
20 changed files with 423 additions and 41 deletions
@@ -0,0 +1,143 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:universal_io/io.dart';
import 'package:weblibre/features/user/data/models/engine_settings.dart';
import 'package:weblibre/features/user/domain/repositories/engine_settings.dart';
import 'package:weblibre/utils/form_validators.dart';
const _defaultServerUrl = 'https://services.addons.mozilla.org';
class AddonCollectionScreen extends HookConsumerWidget {
const AddonCollectionScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final formKey = useMemoized(() => GlobalKey<FormState>());
final addonCollectionSetting = ref.watch(
engineSettingsWithDefaultsProvider.select(
(value) => value.addonCollection,
),
);
final serverURLController = useTextEditingController(
text: addonCollectionSetting?.serverURL ?? _defaultServerUrl,
keys: [addonCollectionSetting],
);
final collectionUserController = useTextEditingController(
text: addonCollectionSetting?.collectionUser,
keys: [addonCollectionSetting],
);
final collectionNameController = useTextEditingController(
text: addonCollectionSetting?.collectionName,
keys: [addonCollectionSetting],
);
return Scaffold(
appBar: AppBar(
title: const Text('Custom Extension Collection'),
actions: [
if (addonCollectionSetting != null)
IconButton(
onPressed: () async {
await ref
.read(engineSettingsRepositoryProvider.notifier)
.updateSettings(
(currentSettings) =>
currentSettings.copyWith.addonCollection(null),
);
unawaited(
Future.delayed(const Duration(seconds: 1)).whenComplete(() {
exit(0);
}),
);
},
icon: const Icon(Icons.delete),
),
],
),
body: Form(
key: formKey,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: ListView(
children: [
TextFormField(
controller: serverURLController,
decoration: const InputDecoration(
label: Text('Server URL'),
hintText: _defaultServerUrl,
floatingLabelBehavior: FloatingLabelBehavior.always,
),
keyboardType: TextInputType.url,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
eagerParsing: false,
);
},
),
const SizedBox(height: 8),
TextFormField(
controller: collectionUserController,
decoration: const InputDecoration(
label: Text('Collection User'),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
validator: validateRequired,
),
const SizedBox(height: 8),
TextFormField(
controller: collectionNameController,
decoration: const InputDecoration(
label: Text('Collection Name'),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
validator: validateRequired,
),
const SizedBox(height: 32),
FilledButton(
onPressed: () async {
if (formKey.currentState?.validate() == true) {
await ref
.read(engineSettingsRepositoryProvider.notifier)
.updateSettings(
(
currentSettings,
) => currentSettings.copyWith.addonCollection(
AddonCollection(
serverURL: serverURLController.text,
collectionUser: collectionUserController.text,
collectionName: collectionNameController.text,
),
),
);
unawaited(
Future.delayed(const Duration(seconds: 1)).whenComplete(
() {
exit(0);
},
),
);
}
},
child: const Text('Save & Restart Browser'),
),
],
),
),
),
),
);
}
}
@@ -29,6 +29,7 @@ import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:universal_io/io.dart';
import 'package:weblibre/core/logger.dart';
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/features/settings/presentation/controllers/save_settings.dart';
import 'package:weblibre/features/settings/presentation/widgets/custom_list_tile.dart';
import 'package:weblibre/features/user/data/models/engine_settings.dart';
@@ -198,6 +199,17 @@ class DeveloperSettingsScreen extends HookConsumerWidget {
label: const Text('Copy'),
),
),
ListTile(
leading: const Icon(MdiIcons.puzzle),
title: const Text('Custom Extension Collection'),
subtitle: const Text(
'Custom Add-on Collections are curated lists of extensions that users can create and share.',
),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
await AddonCollectionRoute().push(context);
},
),
],
);
},