refactoring

This commit is contained in:
Fabian Freund
2025-02-20 12:27:34 +01:00
parent b81fc1cc42
commit 490e13000b
138 changed files with 1392 additions and 3251 deletions
@@ -0,0 +1,29 @@
import 'package:fast_equatable/fast_equatable.dart';
class FindResultState with FastEquatable {
final int activeMatchOrdinal;
final int numberOfMatches;
final bool isDoneCounting;
FindResultState({
required this.activeMatchOrdinal,
required this.numberOfMatches,
required this.isDoneCounting,
});
factory FindResultState.$default() => FindResultState(
activeMatchOrdinal: -1,
numberOfMatches: 0,
isDoneCounting: false,
);
@override
List<Object?> get hashParameters => [
activeMatchOrdinal,
numberOfMatches,
isDoneCounting,
];
@override
bool get cacheHash => true;
}
@@ -0,0 +1,47 @@
import 'package:fast_equatable/fast_equatable.dart';
class HistoryItem with FastEquatable {
final Uri url;
final String title;
HistoryItem({required this.url, required this.title});
@override
bool get cacheHash => true;
@override
List<Object?> get hashParameters => [url, title];
}
class HistoryState with FastEquatable {
final List<HistoryItem> items;
final int currentIndex;
final bool canGoBack;
final bool canGoForward;
HistoryState({
required this.items,
required this.currentIndex,
required this.canGoBack,
required this.canGoForward,
});
factory HistoryState.$default() => HistoryState(
items: const [],
currentIndex: 0,
canGoBack: false,
canGoForward: false,
);
@override
bool get cacheHash => true;
@override
List<Object?> get hashParameters => [
items,
currentIndex,
canGoBack,
canGoForward,
];
}
@@ -0,0 +1,18 @@
import 'package:fast_equatable/fast_equatable.dart';
class ReaderableState with FastEquatable {
final bool readerable;
final bool active;
ReaderableState({required this.readerable, required this.active});
factory ReaderableState.$default() =>
ReaderableState(readerable: false, active: false);
@override
bool get cacheHash => true;
@override
List<Object?> get hashParameters => [readerable, active];
}
@@ -0,0 +1,22 @@
import 'package:fast_equatable/fast_equatable.dart';
class SecurityState with FastEquatable {
final bool secure;
final String host;
final String issuer;
SecurityState({
required this.secure,
required this.host,
required this.issuer,
});
factory SecurityState.$default() =>
SecurityState(secure: false, host: "", issuer: "");
@override
bool get cacheHash => true;
@override
List<Object?> get hashParameters => [secure, host, issuer];
}
@@ -0,0 +1,103 @@
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:lensai/data/models/web_page_info.dart';
import 'package:lensai/domain/entities/equatable_image.dart';
import 'package:lensai/extensions/nullable.dart';
import 'package:lensai/features/geckoview/domain/entities/browser_icon.dart';
import 'package:lensai/features/geckoview/domain/entities/states/find_result.dart';
import 'package:lensai/features/geckoview/domain/entities/states/history.dart';
import 'package:lensai/features/geckoview/domain/entities/states/readerable.dart';
import 'package:lensai/features/geckoview/domain/entities/states/security.dart';
part 'tab.g.dart';
@CopyWith()
class TabState extends WebPageInfo with FastEquatable {
@CopyWithField(immutable: true)
final String id;
final String? contextId;
@override
String get title => super.title!;
final EquatableImage? icon;
@override
BrowserIcon? get favicon => icon.mapNotNull(
(icon) => BrowserIcon(
image: icon,
dominantColor: null,
source: IconSource.memory,
),
);
final EquatableImage? thumbnail;
final int progress;
final bool isPrivate;
final bool isFullScreen;
final bool isLoading;
final SecurityState securityInfoState;
final HistoryState historyState;
final ReaderableState readerableState;
final FindResultState findResultState;
TabState({
required this.id,
required this.contextId,
required super.url,
required String title,
required this.icon,
required this.thumbnail,
required this.progress,
required this.isPrivate,
required this.isFullScreen,
required this.isLoading,
required this.securityInfoState,
required this.historyState,
required this.readerableState,
required this.findResultState,
}) : super(title: title);
factory TabState.$default(String tabId) => TabState(
id: tabId,
contextId: null,
url: Uri.parse('about:blank'),
title: "",
icon: null,
thumbnail: null,
progress: 0,
isPrivate: false,
isFullScreen: false,
isLoading: false,
securityInfoState: SecurityState.$default(),
historyState: HistoryState.$default(),
readerableState: ReaderableState.$default(),
findResultState: FindResultState.$default(),
);
@override
bool get cacheHash => true;
@override
List<Object?> get hashParameters => [
id,
contextId,
url,
title,
icon,
thumbnail,
progress,
isPrivate,
isFullScreen,
isLoading,
securityInfoState,
historyState,
readerableState,
findResultState,
];
}
@@ -0,0 +1,193 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'tab.dart';
// **************************************************************************
// CopyWithGenerator
// **************************************************************************
abstract class _$TabStateCWProxy {
TabState contextId(String? contextId);
TabState url(Uri url);
TabState title(String title);
TabState icon(EquatableImage? icon);
TabState thumbnail(EquatableImage? thumbnail);
TabState progress(int progress);
TabState isPrivate(bool isPrivate);
TabState isFullScreen(bool isFullScreen);
TabState isLoading(bool isLoading);
TabState securityInfoState(SecurityState securityInfoState);
TabState historyState(HistoryState historyState);
TabState readerableState(ReaderableState readerableState);
TabState findResultState(FindResultState findResultState);
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TabState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// TabState(...).copyWith(id: 12, name: "My name")
/// ````
TabState call({
String? contextId,
Uri url,
String title,
EquatableImage? icon,
EquatableImage? thumbnail,
int progress,
bool isPrivate,
bool isFullScreen,
bool isLoading,
SecurityState securityInfoState,
HistoryState historyState,
ReaderableState readerableState,
FindResultState findResultState,
});
}
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTabState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTabState.copyWith.fieldName(...)`
class _$TabStateCWProxyImpl implements _$TabStateCWProxy {
const _$TabStateCWProxyImpl(this._value);
final TabState _value;
@override
TabState contextId(String? contextId) => this(contextId: contextId);
@override
TabState url(Uri url) => this(url: url);
@override
TabState title(String title) => this(title: title);
@override
TabState icon(EquatableImage? icon) => this(icon: icon);
@override
TabState thumbnail(EquatableImage? thumbnail) => this(thumbnail: thumbnail);
@override
TabState progress(int progress) => this(progress: progress);
@override
TabState isPrivate(bool isPrivate) => this(isPrivate: isPrivate);
@override
TabState isFullScreen(bool isFullScreen) => this(isFullScreen: isFullScreen);
@override
TabState isLoading(bool isLoading) => this(isLoading: isLoading);
@override
TabState securityInfoState(SecurityState securityInfoState) =>
this(securityInfoState: securityInfoState);
@override
TabState historyState(HistoryState historyState) =>
this(historyState: historyState);
@override
TabState readerableState(ReaderableState readerableState) =>
this(readerableState: readerableState);
@override
TabState findResultState(FindResultState findResultState) =>
this(findResultState: findResultState);
@override
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TabState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// TabState(...).copyWith(id: 12, name: "My name")
/// ````
TabState call({
Object? contextId = const $CopyWithPlaceholder(),
Object? url = const $CopyWithPlaceholder(),
Object? title = const $CopyWithPlaceholder(),
Object? icon = const $CopyWithPlaceholder(),
Object? thumbnail = const $CopyWithPlaceholder(),
Object? progress = const $CopyWithPlaceholder(),
Object? isPrivate = const $CopyWithPlaceholder(),
Object? isFullScreen = const $CopyWithPlaceholder(),
Object? isLoading = const $CopyWithPlaceholder(),
Object? securityInfoState = const $CopyWithPlaceholder(),
Object? historyState = const $CopyWithPlaceholder(),
Object? readerableState = const $CopyWithPlaceholder(),
Object? findResultState = const $CopyWithPlaceholder(),
}) {
return TabState(
id: _value.id,
contextId: contextId == const $CopyWithPlaceholder()
? _value.contextId
// ignore: cast_nullable_to_non_nullable
: contextId as String?,
url: url == const $CopyWithPlaceholder()
? _value.url
// ignore: cast_nullable_to_non_nullable
: url as Uri,
title: title == const $CopyWithPlaceholder()
? _value.title
// ignore: cast_nullable_to_non_nullable
: title as String,
icon: icon == const $CopyWithPlaceholder()
? _value.icon
// ignore: cast_nullable_to_non_nullable
: icon as EquatableImage?,
thumbnail: thumbnail == const $CopyWithPlaceholder()
? _value.thumbnail
// ignore: cast_nullable_to_non_nullable
: thumbnail as EquatableImage?,
progress: progress == const $CopyWithPlaceholder()
? _value.progress
// ignore: cast_nullable_to_non_nullable
: progress as int,
isPrivate: isPrivate == const $CopyWithPlaceholder()
? _value.isPrivate
// ignore: cast_nullable_to_non_nullable
: isPrivate as bool,
isFullScreen: isFullScreen == const $CopyWithPlaceholder()
? _value.isFullScreen
// ignore: cast_nullable_to_non_nullable
: isFullScreen as bool,
isLoading: isLoading == const $CopyWithPlaceholder()
? _value.isLoading
// ignore: cast_nullable_to_non_nullable
: isLoading as bool,
securityInfoState: securityInfoState == const $CopyWithPlaceholder()
? _value.securityInfoState
// ignore: cast_nullable_to_non_nullable
: securityInfoState as SecurityState,
historyState: historyState == const $CopyWithPlaceholder()
? _value.historyState
// ignore: cast_nullable_to_non_nullable
: historyState as HistoryState,
readerableState: readerableState == const $CopyWithPlaceholder()
? _value.readerableState
// ignore: cast_nullable_to_non_nullable
: readerableState as ReaderableState,
findResultState: findResultState == const $CopyWithPlaceholder()
? _value.findResultState
// ignore: cast_nullable_to_non_nullable
: findResultState as FindResultState,
);
}
}
extension $TabStateCopyWith on TabState {
/// Returns a callable class that can be used as follows: `instanceOfTabState.copyWith(...)` or like so:`instanceOfTabState.copyWith.fieldName(...)`.
// ignore: library_private_types_in_public_api
_$TabStateCWProxy get copyWith => _$TabStateCWProxyImpl(this);
}
@@ -0,0 +1,44 @@
import 'dart:ui';
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:lensai/domain/entities/equatable_image.dart';
part 'web_extension.g.dart';
@CopyWith()
class WebExtensionState with FastEquatable {
String extensionId;
String? title;
bool enabled;
String? badgeText;
Color? badgeTextColor;
Color? badgeBackgroundColor;
final EquatableImage? icon;
WebExtensionState({
required this.extensionId,
required this.enabled,
this.title,
this.badgeText,
this.badgeTextColor,
this.badgeBackgroundColor,
this.icon,
});
@override
bool get cacheHash => true;
@override
List<Object?> get hashParameters => [
extensionId,
title,
enabled,
badgeText,
badgeTextColor,
badgeBackgroundColor,
icon,
];
}
@@ -0,0 +1,126 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'web_extension.dart';
// **************************************************************************
// CopyWithGenerator
// **************************************************************************
abstract class _$WebExtensionStateCWProxy {
WebExtensionState extensionId(String extensionId);
WebExtensionState enabled(bool enabled);
WebExtensionState title(String? title);
WebExtensionState badgeText(String? badgeText);
WebExtensionState badgeTextColor(Color? badgeTextColor);
WebExtensionState badgeBackgroundColor(Color? badgeBackgroundColor);
WebExtensionState icon(EquatableImage? icon);
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `WebExtensionState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// WebExtensionState(...).copyWith(id: 12, name: "My name")
/// ````
WebExtensionState call({
String extensionId,
bool enabled,
String? title,
String? badgeText,
Color? badgeTextColor,
Color? badgeBackgroundColor,
EquatableImage? icon,
});
}
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfWebExtensionState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfWebExtensionState.copyWith.fieldName(...)`
class _$WebExtensionStateCWProxyImpl implements _$WebExtensionStateCWProxy {
const _$WebExtensionStateCWProxyImpl(this._value);
final WebExtensionState _value;
@override
WebExtensionState extensionId(String extensionId) =>
this(extensionId: extensionId);
@override
WebExtensionState enabled(bool enabled) => this(enabled: enabled);
@override
WebExtensionState title(String? title) => this(title: title);
@override
WebExtensionState badgeText(String? badgeText) => this(badgeText: badgeText);
@override
WebExtensionState badgeTextColor(Color? badgeTextColor) =>
this(badgeTextColor: badgeTextColor);
@override
WebExtensionState badgeBackgroundColor(Color? badgeBackgroundColor) =>
this(badgeBackgroundColor: badgeBackgroundColor);
@override
WebExtensionState icon(EquatableImage? icon) => this(icon: icon);
@override
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `WebExtensionState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// WebExtensionState(...).copyWith(id: 12, name: "My name")
/// ````
WebExtensionState call({
Object? extensionId = const $CopyWithPlaceholder(),
Object? enabled = const $CopyWithPlaceholder(),
Object? title = const $CopyWithPlaceholder(),
Object? badgeText = const $CopyWithPlaceholder(),
Object? badgeTextColor = const $CopyWithPlaceholder(),
Object? badgeBackgroundColor = const $CopyWithPlaceholder(),
Object? icon = const $CopyWithPlaceholder(),
}) {
return WebExtensionState(
extensionId: extensionId == const $CopyWithPlaceholder()
? _value.extensionId
// ignore: cast_nullable_to_non_nullable
: extensionId as String,
enabled: enabled == const $CopyWithPlaceholder()
? _value.enabled
// ignore: cast_nullable_to_non_nullable
: enabled as bool,
title: title == const $CopyWithPlaceholder()
? _value.title
// ignore: cast_nullable_to_non_nullable
: title as String?,
badgeText: badgeText == const $CopyWithPlaceholder()
? _value.badgeText
// ignore: cast_nullable_to_non_nullable
: badgeText as String?,
badgeTextColor: badgeTextColor == const $CopyWithPlaceholder()
? _value.badgeTextColor
// ignore: cast_nullable_to_non_nullable
: badgeTextColor as Color?,
badgeBackgroundColor: badgeBackgroundColor == const $CopyWithPlaceholder()
? _value.badgeBackgroundColor
// ignore: cast_nullable_to_non_nullable
: badgeBackgroundColor as Color?,
icon: icon == const $CopyWithPlaceholder()
? _value.icon
// ignore: cast_nullable_to_non_nullable
: icon as EquatableImage?,
);
}
}
extension $WebExtensionStateCopyWith on WebExtensionState {
/// Returns a callable class that can be used as follows: `instanceOfWebExtensionState.copyWith(...)` or like so:`instanceOfWebExtensionState.copyWith.fieldName(...)`.
// ignore: library_private_types_in_public_api
_$WebExtensionStateCWProxy get copyWith =>
_$WebExtensionStateCWProxyImpl(this);
}