prepare for multiple apps
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:drift/drift.dart' show Expression, Insertable, Value;
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/extensions/uri.dart';
|
||||
import 'package:weblibre/features/bangs/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/bangs/data/models/bang_group.dart';
|
||||
|
||||
part 'bang.g.dart';
|
||||
|
||||
enum BangFormat {
|
||||
///When the bang is invoked with no query, opens the base path of the URL (/)
|
||||
///instead of any path given in the template (g., /search)
|
||||
@JsonValue('open_base_path')
|
||||
openBasePath,
|
||||
|
||||
///URL encode the search terms. Some sites do not work with this, so it can
|
||||
///be disabled by omitting this.
|
||||
@JsonValue('url_encode_placeholder')
|
||||
urlEncodePlaceholder,
|
||||
|
||||
///URL encodes spaces as +, instead of %20. Some sites only work correctly
|
||||
///with one or the other.
|
||||
@JsonValue('url_encode_space_to_plus')
|
||||
urlEncodeSpaceToPlus,
|
||||
|
||||
///When the bang is invoked with no query, open the snap domain (ad) instead of any path given in the template
|
||||
@JsonValue('open_snap_domain')
|
||||
openSnapDomain,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@CopyWith()
|
||||
class Bang with FastEquatable implements Insertable<Bang> {
|
||||
static const _templateQueryPlaceholder = '{{{s}}}';
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
final BangGroup? group;
|
||||
|
||||
///The name of the website associated with the bang.
|
||||
@JsonKey(name: 's')
|
||||
final String websiteName;
|
||||
|
||||
///The domain name of the websit
|
||||
@JsonKey(name: 'd')
|
||||
final String domain;
|
||||
|
||||
///The specific trigger word or phrase used to invoke the bang.
|
||||
@JsonKey(name: 't')
|
||||
final String trigger;
|
||||
|
||||
///The URL template to use when the bang is invoked, where `{{{s}}}` is replaced by the user's query.
|
||||
@JsonKey(name: 'u')
|
||||
final String urlTemplate;
|
||||
|
||||
///The category of the website, if applicable
|
||||
@JsonKey(name: 'c')
|
||||
final String? category;
|
||||
|
||||
///The subcategory of the website, if applicable
|
||||
@JsonKey(name: 'sc')
|
||||
final String? subCategory;
|
||||
|
||||
///The format flags indicating how the query should be processed.
|
||||
@JsonKey(name: 'fmt')
|
||||
final Set<BangFormat>? format;
|
||||
|
||||
///Additional triggers that invoke this bang
|
||||
@JsonKey(name: 'ts')
|
||||
final Set<String>? additionalTriggers;
|
||||
|
||||
///Additional triggers that invoke this bang
|
||||
@JsonKey(name: 'ad')
|
||||
final String? snapDomain;
|
||||
|
||||
@JsonKey(defaultValue: false)
|
||||
final bool searxngApi;
|
||||
|
||||
String formatQuery(String input) {
|
||||
return (format == null ||
|
||||
format!.contains(BangFormat.urlEncodePlaceholder) == true)
|
||||
? (format == null ||
|
||||
format?.contains(BangFormat.urlEncodeSpaceToPlus) == true)
|
||||
? Uri.encodeQueryComponent(input)
|
||||
: Uri.encodeComponent(input)
|
||||
: input;
|
||||
}
|
||||
|
||||
Uri getDefaultUrl() {
|
||||
return getTemplateUrl('');
|
||||
}
|
||||
|
||||
Uri getTemplateUrl(String? query) {
|
||||
final queryEmpty = query.isEmpty;
|
||||
|
||||
if (queryEmpty && format?.contains(BangFormat.openSnapDomain) == true) {
|
||||
if (snapDomain.isNotEmpty) {
|
||||
return Uri.parse(snapDomain!);
|
||||
}
|
||||
}
|
||||
|
||||
final url = (!queryEmpty)
|
||||
? urlTemplate.replaceAll(_templateQueryPlaceholder, formatQuery(query!))
|
||||
: urlTemplate;
|
||||
|
||||
var template = Uri.parse(url);
|
||||
if (!template.hasScheme || template.origin.isEmpty) {
|
||||
template = Uri.https(
|
||||
domain,
|
||||
).replace(path: template.path, query: template.query);
|
||||
}
|
||||
|
||||
if (queryEmpty && format?.contains(BangFormat.openBasePath) == true) {
|
||||
template = template.base;
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
static Set<BangFormat> decodeFormat(Iterable input) {
|
||||
return input.map((e) => $enumDecode(_$BangFormatEnumMap, e)).toSet();
|
||||
}
|
||||
|
||||
static List<String> encodeFormat(Iterable<BangFormat> format) {
|
||||
return format.map((e) => _$BangFormatEnumMap[e]!).toList();
|
||||
}
|
||||
|
||||
Bang({
|
||||
required this.websiteName,
|
||||
required this.domain,
|
||||
required this.trigger,
|
||||
required this.urlTemplate,
|
||||
required this.searxngApi,
|
||||
this.group,
|
||||
this.category,
|
||||
this.subCategory,
|
||||
this.format,
|
||||
this.additionalTriggers,
|
||||
this.snapDomain,
|
||||
});
|
||||
|
||||
factory Bang.fromJson(Map<String, dynamic> json) => _$BangFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$BangToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
group,
|
||||
websiteName,
|
||||
domain,
|
||||
trigger,
|
||||
urlTemplate,
|
||||
category,
|
||||
subCategory,
|
||||
format,
|
||||
additionalTriggers,
|
||||
snapDomain,
|
||||
searxngApi,
|
||||
];
|
||||
|
||||
@override
|
||||
Map<String, Expression<Object>> toColumns(bool nullToAbsent) {
|
||||
return BangCompanion(
|
||||
trigger: Value(trigger),
|
||||
websiteName: Value(websiteName),
|
||||
domain: Value(domain),
|
||||
urlTemplate: Value(urlTemplate),
|
||||
group: Value.absentIfNull(group),
|
||||
category: Value.absentIfNull(category),
|
||||
subCategory: Value.absentIfNull(subCategory),
|
||||
format: Value.absentIfNull(format),
|
||||
additionalTriggers: Value.absentIfNull(additionalTriggers),
|
||||
snapDomain: Value.absentIfNull(snapDomain),
|
||||
).toColumns(nullToAbsent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bang.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$BangCWProxy {
|
||||
Bang websiteName(String websiteName);
|
||||
|
||||
Bang domain(String domain);
|
||||
|
||||
Bang trigger(String trigger);
|
||||
|
||||
Bang urlTemplate(String urlTemplate);
|
||||
|
||||
Bang searxngApi(bool searxngApi);
|
||||
|
||||
Bang group(BangGroup? group);
|
||||
|
||||
Bang category(String? category);
|
||||
|
||||
Bang subCategory(String? subCategory);
|
||||
|
||||
Bang format(Set<BangFormat>? format);
|
||||
|
||||
Bang additionalTriggers(Set<String>? additionalTriggers);
|
||||
|
||||
Bang snapDomain(String? snapDomain);
|
||||
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Bang(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// Bang(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
Bang call({
|
||||
String websiteName,
|
||||
String domain,
|
||||
String trigger,
|
||||
String urlTemplate,
|
||||
bool searxngApi,
|
||||
BangGroup? group,
|
||||
String? category,
|
||||
String? subCategory,
|
||||
Set<BangFormat>? format,
|
||||
Set<String>? additionalTriggers,
|
||||
String? snapDomain,
|
||||
});
|
||||
}
|
||||
|
||||
/// Callable proxy for `copyWith` functionality.
|
||||
/// Use as `instanceOfBang.copyWith(...)` or call `instanceOfBang.copyWith.fieldName(value)` for a single field.
|
||||
class _$BangCWProxyImpl implements _$BangCWProxy {
|
||||
const _$BangCWProxyImpl(this._value);
|
||||
|
||||
final Bang _value;
|
||||
|
||||
@override
|
||||
Bang websiteName(String websiteName) => call(websiteName: websiteName);
|
||||
|
||||
@override
|
||||
Bang domain(String domain) => call(domain: domain);
|
||||
|
||||
@override
|
||||
Bang trigger(String trigger) => call(trigger: trigger);
|
||||
|
||||
@override
|
||||
Bang urlTemplate(String urlTemplate) => call(urlTemplate: urlTemplate);
|
||||
|
||||
@override
|
||||
Bang searxngApi(bool searxngApi) => call(searxngApi: searxngApi);
|
||||
|
||||
@override
|
||||
Bang group(BangGroup? group) => call(group: group);
|
||||
|
||||
@override
|
||||
Bang category(String? category) => call(category: category);
|
||||
|
||||
@override
|
||||
Bang subCategory(String? subCategory) => call(subCategory: subCategory);
|
||||
|
||||
@override
|
||||
Bang format(Set<BangFormat>? format) => call(format: format);
|
||||
|
||||
@override
|
||||
Bang additionalTriggers(Set<String>? additionalTriggers) =>
|
||||
call(additionalTriggers: additionalTriggers);
|
||||
|
||||
@override
|
||||
Bang snapDomain(String? snapDomain) => call(snapDomain: snapDomain);
|
||||
|
||||
@override
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Bang(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// Bang(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
Bang call({
|
||||
Object? websiteName = const $CopyWithPlaceholder(),
|
||||
Object? domain = const $CopyWithPlaceholder(),
|
||||
Object? trigger = const $CopyWithPlaceholder(),
|
||||
Object? urlTemplate = const $CopyWithPlaceholder(),
|
||||
Object? searxngApi = const $CopyWithPlaceholder(),
|
||||
Object? group = const $CopyWithPlaceholder(),
|
||||
Object? category = const $CopyWithPlaceholder(),
|
||||
Object? subCategory = const $CopyWithPlaceholder(),
|
||||
Object? format = const $CopyWithPlaceholder(),
|
||||
Object? additionalTriggers = const $CopyWithPlaceholder(),
|
||||
Object? snapDomain = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return Bang(
|
||||
websiteName:
|
||||
websiteName == const $CopyWithPlaceholder() || websiteName == null
|
||||
? _value.websiteName
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: websiteName as String,
|
||||
domain: domain == const $CopyWithPlaceholder() || domain == null
|
||||
? _value.domain
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: domain as String,
|
||||
trigger: trigger == const $CopyWithPlaceholder() || trigger == null
|
||||
? _value.trigger
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: trigger as String,
|
||||
urlTemplate:
|
||||
urlTemplate == const $CopyWithPlaceholder() || urlTemplate == null
|
||||
? _value.urlTemplate
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: urlTemplate as String,
|
||||
searxngApi:
|
||||
searxngApi == const $CopyWithPlaceholder() || searxngApi == null
|
||||
? _value.searxngApi
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: searxngApi as bool,
|
||||
group: group == const $CopyWithPlaceholder()
|
||||
? _value.group
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: group as BangGroup?,
|
||||
category: category == const $CopyWithPlaceholder()
|
||||
? _value.category
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: category as String?,
|
||||
subCategory: subCategory == const $CopyWithPlaceholder()
|
||||
? _value.subCategory
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: subCategory as String?,
|
||||
format: format == const $CopyWithPlaceholder()
|
||||
? _value.format
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: format as Set<BangFormat>?,
|
||||
additionalTriggers: additionalTriggers == const $CopyWithPlaceholder()
|
||||
? _value.additionalTriggers
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: additionalTriggers as Set<String>?,
|
||||
snapDomain: snapDomain == const $CopyWithPlaceholder()
|
||||
? _value.snapDomain
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: snapDomain as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $BangCopyWith on Bang {
|
||||
/// Returns a callable class used to build a new instance with modified fields.
|
||||
/// Example: `instanceOfBang.copyWith(...)` or `instanceOfBang.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$BangCWProxy get copyWith => _$BangCWProxyImpl(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Bang _$BangFromJson(Map<String, dynamic> json) => Bang(
|
||||
websiteName: json['s'] as String,
|
||||
domain: json['d'] as String,
|
||||
trigger: json['t'] as String,
|
||||
urlTemplate: json['u'] as String,
|
||||
searxngApi: json['searxngApi'] as bool? ?? false,
|
||||
category: json['c'] as String?,
|
||||
subCategory: json['sc'] as String?,
|
||||
format: (json['fmt'] as List<dynamic>?)
|
||||
?.map((e) => $enumDecode(_$BangFormatEnumMap, e))
|
||||
.toSet(),
|
||||
additionalTriggers: (json['ts'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toSet(),
|
||||
snapDomain: json['ad'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$BangToJson(Bang instance) => <String, dynamic>{
|
||||
's': instance.websiteName,
|
||||
'd': instance.domain,
|
||||
't': instance.trigger,
|
||||
'u': instance.urlTemplate,
|
||||
'c': instance.category,
|
||||
'sc': instance.subCategory,
|
||||
'fmt': instance.format?.map((e) => _$BangFormatEnumMap[e]!).toList(),
|
||||
'ts': instance.additionalTriggers?.toList(),
|
||||
'ad': instance.snapDomain,
|
||||
'searxngApi': instance.searxngApi,
|
||||
};
|
||||
|
||||
const _$BangFormatEnumMap = {
|
||||
BangFormat.openBasePath: 'open_base_path',
|
||||
BangFormat.urlEncodePlaceholder: 'url_encode_placeholder',
|
||||
BangFormat.urlEncodeSpaceToPlus: 'url_encode_space_to_plus',
|
||||
BangFormat.openSnapDomain: 'open_snap_domain',
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:weblibre/features/bangs/data/models/bang.dart';
|
||||
import 'package:weblibre/features/bangs/data/models/bang_group.dart';
|
||||
import 'package:weblibre/features/bangs/data/models/bang_key.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/entities/browser_icon.dart';
|
||||
|
||||
part 'bang_data.g.dart';
|
||||
|
||||
@CopyWith(constructor: '_copyWith')
|
||||
class BangData extends Bang {
|
||||
final int frequency;
|
||||
final DateTime? lastUsed;
|
||||
|
||||
final BrowserIcon? icon;
|
||||
|
||||
@override
|
||||
BangGroup get group => super.group!;
|
||||
|
||||
BangData({
|
||||
required super.websiteName,
|
||||
required super.domain,
|
||||
required super.trigger,
|
||||
required super.urlTemplate,
|
||||
required super.group,
|
||||
required super.searxngApi,
|
||||
super.category,
|
||||
super.subCategory,
|
||||
super.format,
|
||||
super.additionalTriggers,
|
||||
super.snapDomain,
|
||||
int? frequency,
|
||||
this.lastUsed,
|
||||
this.icon,
|
||||
}) : frequency = frequency ?? 0;
|
||||
|
||||
//For some reasons including super.group breaks generation of copywith, so we have this one for now
|
||||
BangData._copyWith({
|
||||
required super.websiteName,
|
||||
required super.domain,
|
||||
required super.trigger,
|
||||
required super.urlTemplate,
|
||||
required super.searxngApi,
|
||||
super.category,
|
||||
super.subCategory,
|
||||
super.format,
|
||||
super.additionalTriggers,
|
||||
super.snapDomain,
|
||||
int? frequency,
|
||||
this.lastUsed,
|
||||
this.icon,
|
||||
}) : frequency = frequency ?? 0;
|
||||
|
||||
BangKey toKey() => BangKey(group: group, trigger: trigger);
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
...super.hashParameters,
|
||||
frequency,
|
||||
lastUsed,
|
||||
icon,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bang_data.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$BangDataCWProxy {
|
||||
BangData websiteName(String websiteName);
|
||||
|
||||
BangData domain(String domain);
|
||||
|
||||
BangData trigger(String trigger);
|
||||
|
||||
BangData urlTemplate(String urlTemplate);
|
||||
|
||||
BangData searxngApi(bool searxngApi);
|
||||
|
||||
BangData category(String? category);
|
||||
|
||||
BangData subCategory(String? subCategory);
|
||||
|
||||
BangData format(Set<BangFormat>? format);
|
||||
|
||||
BangData additionalTriggers(Set<String>? additionalTriggers);
|
||||
|
||||
BangData snapDomain(String? snapDomain);
|
||||
|
||||
BangData frequency(int? frequency);
|
||||
|
||||
BangData lastUsed(DateTime? lastUsed);
|
||||
|
||||
BangData icon(BrowserIcon? icon);
|
||||
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `BangData(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// BangData(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
BangData call({
|
||||
String websiteName,
|
||||
String domain,
|
||||
String trigger,
|
||||
String urlTemplate,
|
||||
bool searxngApi,
|
||||
String? category,
|
||||
String? subCategory,
|
||||
Set<BangFormat>? format,
|
||||
Set<String>? additionalTriggers,
|
||||
String? snapDomain,
|
||||
int? frequency,
|
||||
DateTime? lastUsed,
|
||||
BrowserIcon? icon,
|
||||
});
|
||||
}
|
||||
|
||||
/// Callable proxy for `copyWith` functionality.
|
||||
/// Use as `instanceOfBangData.copyWith(...)` or call `instanceOfBangData.copyWith.fieldName(value)` for a single field.
|
||||
class _$BangDataCWProxyImpl implements _$BangDataCWProxy {
|
||||
const _$BangDataCWProxyImpl(this._value);
|
||||
|
||||
final BangData _value;
|
||||
|
||||
@override
|
||||
BangData websiteName(String websiteName) => call(websiteName: websiteName);
|
||||
|
||||
@override
|
||||
BangData domain(String domain) => call(domain: domain);
|
||||
|
||||
@override
|
||||
BangData trigger(String trigger) => call(trigger: trigger);
|
||||
|
||||
@override
|
||||
BangData urlTemplate(String urlTemplate) => call(urlTemplate: urlTemplate);
|
||||
|
||||
@override
|
||||
BangData searxngApi(bool searxngApi) => call(searxngApi: searxngApi);
|
||||
|
||||
@override
|
||||
BangData category(String? category) => call(category: category);
|
||||
|
||||
@override
|
||||
BangData subCategory(String? subCategory) => call(subCategory: subCategory);
|
||||
|
||||
@override
|
||||
BangData format(Set<BangFormat>? format) => call(format: format);
|
||||
|
||||
@override
|
||||
BangData additionalTriggers(Set<String>? additionalTriggers) =>
|
||||
call(additionalTriggers: additionalTriggers);
|
||||
|
||||
@override
|
||||
BangData snapDomain(String? snapDomain) => call(snapDomain: snapDomain);
|
||||
|
||||
@override
|
||||
BangData frequency(int? frequency) => call(frequency: frequency);
|
||||
|
||||
@override
|
||||
BangData lastUsed(DateTime? lastUsed) => call(lastUsed: lastUsed);
|
||||
|
||||
@override
|
||||
BangData icon(BrowserIcon? icon) => call(icon: icon);
|
||||
|
||||
@override
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `BangData(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// BangData(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
BangData call({
|
||||
Object? websiteName = const $CopyWithPlaceholder(),
|
||||
Object? domain = const $CopyWithPlaceholder(),
|
||||
Object? trigger = const $CopyWithPlaceholder(),
|
||||
Object? urlTemplate = const $CopyWithPlaceholder(),
|
||||
Object? searxngApi = const $CopyWithPlaceholder(),
|
||||
Object? category = const $CopyWithPlaceholder(),
|
||||
Object? subCategory = const $CopyWithPlaceholder(),
|
||||
Object? format = const $CopyWithPlaceholder(),
|
||||
Object? additionalTriggers = const $CopyWithPlaceholder(),
|
||||
Object? snapDomain = const $CopyWithPlaceholder(),
|
||||
Object? frequency = const $CopyWithPlaceholder(),
|
||||
Object? lastUsed = const $CopyWithPlaceholder(),
|
||||
Object? icon = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return BangData._copyWith(
|
||||
websiteName:
|
||||
websiteName == const $CopyWithPlaceholder() || websiteName == null
|
||||
? _value.websiteName
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: websiteName as String,
|
||||
domain: domain == const $CopyWithPlaceholder() || domain == null
|
||||
? _value.domain
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: domain as String,
|
||||
trigger: trigger == const $CopyWithPlaceholder() || trigger == null
|
||||
? _value.trigger
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: trigger as String,
|
||||
urlTemplate:
|
||||
urlTemplate == const $CopyWithPlaceholder() || urlTemplate == null
|
||||
? _value.urlTemplate
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: urlTemplate as String,
|
||||
searxngApi:
|
||||
searxngApi == const $CopyWithPlaceholder() || searxngApi == null
|
||||
? _value.searxngApi
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: searxngApi as bool,
|
||||
category: category == const $CopyWithPlaceholder()
|
||||
? _value.category
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: category as String?,
|
||||
subCategory: subCategory == const $CopyWithPlaceholder()
|
||||
? _value.subCategory
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: subCategory as String?,
|
||||
format: format == const $CopyWithPlaceholder()
|
||||
? _value.format
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: format as Set<BangFormat>?,
|
||||
additionalTriggers: additionalTriggers == const $CopyWithPlaceholder()
|
||||
? _value.additionalTriggers
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: additionalTriggers as Set<String>?,
|
||||
snapDomain: snapDomain == const $CopyWithPlaceholder()
|
||||
? _value.snapDomain
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: snapDomain as String?,
|
||||
frequency: frequency == const $CopyWithPlaceholder()
|
||||
? _value.frequency
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: frequency as int?,
|
||||
lastUsed: lastUsed == const $CopyWithPlaceholder()
|
||||
? _value.lastUsed
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: lastUsed as DateTime?,
|
||||
icon: icon == const $CopyWithPlaceholder()
|
||||
? _value.icon
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: icon as BrowserIcon?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $BangDataCopyWith on BangData {
|
||||
/// Returns a callable class used to build a new instance with modified fields.
|
||||
/// Example: `instanceOfBangData.copyWith(...)` or `instanceOfBangData.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$BangDataCWProxy get copyWith => _$BangDataCWProxyImpl(this);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
enum BangGroup {
|
||||
general(
|
||||
remote:
|
||||
'https://raw.githubusercontent.com/FaFre/bangs/main/data/bangs.json',
|
||||
bundled: 'assets/bangs/bangs.json',
|
||||
),
|
||||
kagi(
|
||||
remote:
|
||||
'https://raw.githubusercontent.com/FaFre/bangs/main/data/kagi_bangs.json',
|
||||
bundled: 'assets/bangs/kagi_bangs.json',
|
||||
),
|
||||
user(remote: null, bundled: null);
|
||||
|
||||
final String? bundled;
|
||||
final String? remote;
|
||||
|
||||
const BangGroup({required this.bundled, required this.remote});
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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:json_annotation/json_annotation.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
import 'package:weblibre/features/bangs/data/models/bang_group.dart';
|
||||
|
||||
class BangKey {
|
||||
final String trigger;
|
||||
final BangGroup group;
|
||||
|
||||
const BangKey({required this.group, required this.trigger});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '${group.name}::$trigger';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BangKey &&
|
||||
runtimeType == other.runtimeType &&
|
||||
trigger == other.trigger &&
|
||||
group == other.group;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(trigger, group);
|
||||
|
||||
static BangKey? tryFromString(String key) {
|
||||
try {
|
||||
var [group, trigger] = key.split('::');
|
||||
|
||||
//Migrate to schema v5
|
||||
if (group == 'assistant') {
|
||||
group = BangGroup.kagi.name;
|
||||
}
|
||||
|
||||
return BangKey(
|
||||
group: BangGroup.values.firstWhere((g) => g.name == group),
|
||||
trigger: trigger,
|
||||
);
|
||||
} catch (e, s) {
|
||||
logger.w(
|
||||
'Failed to parse BangKey from string: "$key"',
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BangKeyConverter implements JsonConverter<BangKey?, String?> {
|
||||
const BangKeyConverter();
|
||||
|
||||
@override
|
||||
BangKey? fromJson(String? json) {
|
||||
return json.mapNotNull((json) => BangKey.tryFromString(json));
|
||||
}
|
||||
|
||||
@override
|
||||
String? toJson(BangKey? object) {
|
||||
return object?.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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:fast_equatable/fast_equatable.dart';
|
||||
|
||||
class SearchHistoryEntry with FastEquatable {
|
||||
final String searchQuery;
|
||||
final String trigger;
|
||||
final DateTime searchDate;
|
||||
|
||||
SearchHistoryEntry({
|
||||
required this.searchQuery,
|
||||
required this.trigger,
|
||||
required this.searchDate,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [searchQuery, trigger, searchDate];
|
||||
}
|
||||
Reference in New Issue
Block a user