intermediate
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:lensai/domain/entities/equatable_image.dart';
|
||||
import 'package:lensai/extensions/image.dart';
|
||||
import 'package:lensai/features/geckoview/utils/image_helper.dart';
|
||||
|
||||
class BrowserIcon with FastEquatable {
|
||||
final EquatableImage image;
|
||||
|
||||
final Color? dominantColor;
|
||||
final IconSource source;
|
||||
|
||||
static Future<BrowserIcon> fromBytes(
|
||||
Uint8List bytes, {
|
||||
required Color? dominantColor,
|
||||
required IconSource source,
|
||||
}) async {
|
||||
final image =
|
||||
await tryDecodeImage(bytes).then((image) => image!.toEquatable());
|
||||
|
||||
return BrowserIcon._(
|
||||
image: image,
|
||||
dominantColor: dominantColor,
|
||||
source: source,
|
||||
);
|
||||
}
|
||||
|
||||
BrowserIcon._({
|
||||
required this.image,
|
||||
required this.dominantColor,
|
||||
required this.source,
|
||||
});
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
image,
|
||||
dominantColor,
|
||||
source,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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,23 @@
|
||||
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,25 @@
|
||||
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,84 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:lensai/domain/entities/equatable_image.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/history_state.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/readerable_state.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/security_state.dart';
|
||||
|
||||
part 'tab_state.g.dart';
|
||||
|
||||
@CopyWith()
|
||||
class TabState with FastEquatable {
|
||||
@CopyWithField(immutable: true)
|
||||
final String id;
|
||||
|
||||
final String? contextId;
|
||||
|
||||
final Uri url;
|
||||
final String title;
|
||||
|
||||
final EquatableImage? icon;
|
||||
final EquatableImage? thumbnail;
|
||||
|
||||
final int progress;
|
||||
|
||||
final bool isPrivate;
|
||||
final bool isFullScreen;
|
||||
final bool isLoading;
|
||||
|
||||
final SecurityState securityInfoState;
|
||||
final HistoryState historyState;
|
||||
final ReaderableState readerableState;
|
||||
|
||||
TabState({
|
||||
required this.id,
|
||||
required this.contextId,
|
||||
required this.url,
|
||||
required this.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,
|
||||
});
|
||||
|
||||
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(),
|
||||
);
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
id,
|
||||
contextId,
|
||||
url,
|
||||
title,
|
||||
icon,
|
||||
thumbnail,
|
||||
progress,
|
||||
isPrivate,
|
||||
isFullScreen,
|
||||
isLoading,
|
||||
securityInfoState,
|
||||
historyState,
|
||||
readerableState,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tab_state.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);
|
||||
|
||||
/// 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,
|
||||
});
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
||||
/// 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(),
|
||||
}) {
|
||||
return TabState(
|
||||
id: _value.id,
|
||||
contextId: contextId == const $CopyWithPlaceholder()
|
||||
? _value.contextId
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: contextId as String?,
|
||||
url: url == const $CopyWithPlaceholder() || url == null
|
||||
? _value.url
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: url as Uri,
|
||||
title: title == const $CopyWithPlaceholder() || title == null
|
||||
? _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() || progress == null
|
||||
? _value.progress
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: progress as int,
|
||||
isPrivate: isPrivate == const $CopyWithPlaceholder() || isPrivate == null
|
||||
? _value.isPrivate
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: isPrivate as bool,
|
||||
isFullScreen:
|
||||
isFullScreen == const $CopyWithPlaceholder() || isFullScreen == null
|
||||
? _value.isFullScreen
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: isFullScreen as bool,
|
||||
isLoading: isLoading == const $CopyWithPlaceholder() || isLoading == null
|
||||
? _value.isLoading
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: isLoading as bool,
|
||||
securityInfoState: securityInfoState == const $CopyWithPlaceholder() ||
|
||||
securityInfoState == null
|
||||
? _value.securityInfoState
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: securityInfoState as SecurityState,
|
||||
historyState:
|
||||
historyState == const $CopyWithPlaceholder() || historyState == null
|
||||
? _value.historyState
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: historyState as HistoryState,
|
||||
readerableState: readerableState == const $CopyWithPlaceholder() ||
|
||||
readerableState == null
|
||||
? _value.readerableState
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: readerableState as ReaderableState,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,41 @@
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/tab_state.dart';
|
||||
import 'package:lensai/features/geckoview/domain/repositories/selected_tab.dart';
|
||||
import 'package:lensai/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:lensai/features/geckoview/domain/repositories/tab_session.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
GeckoEventService eventService(EventServiceRef ref) {
|
||||
final service = GeckoEventService.setUp();
|
||||
|
||||
ref.onDispose(() {
|
||||
service.dispose();
|
||||
});
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
TabState? tabState(TabStateRef ref, String? tabId) {
|
||||
if (tabId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ref.watch(
|
||||
tabRepositoryProvider.select((tabs) => tabs[tabId]),
|
||||
);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
TabState? selectedTabState(SelectedTabStateRef ref) {
|
||||
final tabId = ref.watch(selectedTabControllerProvider);
|
||||
return ref.watch(tabStateProvider(tabId));
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
TabSession selectedTabSessionNotifier(SelectedTabSessionNotifierRef ref) {
|
||||
return ref.watch(tabSessionProvider(null).notifier);
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'providers.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$eventServiceHash() => r'5aa357fdf0d217677a9a66ecb50417ac18929cad';
|
||||
|
||||
/// See also [eventService].
|
||||
@ProviderFor(eventService)
|
||||
final eventServiceProvider = Provider<GeckoEventService>.internal(
|
||||
eventService,
|
||||
name: r'eventServiceProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$eventServiceHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef EventServiceRef = ProviderRef<GeckoEventService>;
|
||||
String _$tabStateHash() => r'6985f5472625a9cf44c8bbc61e61b7577eb60e71';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
/// See also [tabState].
|
||||
@ProviderFor(tabState)
|
||||
const tabStateProvider = TabStateFamily();
|
||||
|
||||
/// See also [tabState].
|
||||
class TabStateFamily extends Family<TabState?> {
|
||||
/// See also [tabState].
|
||||
const TabStateFamily();
|
||||
|
||||
/// See also [tabState].
|
||||
TabStateProvider call(
|
||||
String? tabId,
|
||||
) {
|
||||
return TabStateProvider(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TabStateProvider getProviderOverride(
|
||||
covariant TabStateProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.tabId,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'tabStateProvider';
|
||||
}
|
||||
|
||||
/// See also [tabState].
|
||||
class TabStateProvider extends AutoDisposeProvider<TabState?> {
|
||||
/// See also [tabState].
|
||||
TabStateProvider(
|
||||
String? tabId,
|
||||
) : this._internal(
|
||||
(ref) => tabState(
|
||||
ref as TabStateRef,
|
||||
tabId,
|
||||
),
|
||||
from: tabStateProvider,
|
||||
name: r'tabStateProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$tabStateHash,
|
||||
dependencies: TabStateFamily._dependencies,
|
||||
allTransitiveDependencies: TabStateFamily._allTransitiveDependencies,
|
||||
tabId: tabId,
|
||||
);
|
||||
|
||||
TabStateProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.tabId,
|
||||
}) : super.internal();
|
||||
|
||||
final String? tabId;
|
||||
|
||||
@override
|
||||
Override overrideWith(
|
||||
TabState? Function(TabStateRef provider) create,
|
||||
) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: TabStateProvider._internal(
|
||||
(ref) => create(ref as TabStateRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
tabId: tabId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeProviderElement<TabState?> createElement() {
|
||||
return _TabStateProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is TabStateProvider && other.tabId == tabId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, tabId.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
mixin TabStateRef on AutoDisposeProviderRef<TabState?> {
|
||||
/// The parameter `tabId` of this provider.
|
||||
String? get tabId;
|
||||
}
|
||||
|
||||
class _TabStateProviderElement extends AutoDisposeProviderElement<TabState?>
|
||||
with TabStateRef {
|
||||
_TabStateProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String? get tabId => (origin as TabStateProvider).tabId;
|
||||
}
|
||||
|
||||
String _$selectedTabStateHash() => r'd5240ade9010f5c9f00d7a4f419e1b776f75fac1';
|
||||
|
||||
/// See also [selectedTabState].
|
||||
@ProviderFor(selectedTabState)
|
||||
final selectedTabStateProvider = AutoDisposeProvider<TabState?>.internal(
|
||||
selectedTabState,
|
||||
name: r'selectedTabStateProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$selectedTabStateHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef SelectedTabStateRef = AutoDisposeProviderRef<TabState?>;
|
||||
String _$selectedTabSessionNotifierHash() =>
|
||||
r'1b0fe1afa87c0b09fc8407ceb91946fffaef5214';
|
||||
|
||||
/// See also [selectedTabSessionNotifier].
|
||||
@ProviderFor(selectedTabSessionNotifier)
|
||||
final selectedTabSessionNotifierProvider =
|
||||
AutoDisposeProvider<TabSession>.internal(
|
||||
selectedTabSessionNotifier,
|
||||
name: r'selectedTabSessionNotifierProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$selectedTabSessionNotifierHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef SelectedTabSessionNotifierRef = AutoDisposeProviderRef<TabSession>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:lensai/features/geckoview/domain/providers.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'selected_tab.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class SelectedTabController extends _$SelectedTabController {
|
||||
final _tabsService = GeckoTabService();
|
||||
|
||||
Future<void> selectTab(String tabId) {
|
||||
return _tabsService.selectTab(tabId: tabId);
|
||||
}
|
||||
|
||||
@override
|
||||
String? build() {
|
||||
final eventSerivce = ref.watch(eventServiceProvider);
|
||||
|
||||
final selectedTabSub = eventSerivce.selectedTabEvents.listen(
|
||||
(tabId) {
|
||||
state = tabId;
|
||||
},
|
||||
);
|
||||
|
||||
ref.onDispose(() {
|
||||
unawaited(selectedTabSub.cancel());
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'selected_tab.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$selectedTabControllerHash() =>
|
||||
r'b5d79d4d5c2dc08d504e601fa29c8b83d51c9716';
|
||||
|
||||
/// See also [SelectedTabController].
|
||||
@ProviderFor(SelectedTabController)
|
||||
final selectedTabControllerProvider =
|
||||
NotifierProvider<SelectedTabController, String?>.internal(
|
||||
SelectedTabController.new,
|
||||
name: r'selectedTabControllerProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$selectedTabControllerHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$SelectedTabController = Notifier<String?>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -0,0 +1,165 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:lensai/extensions/image.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/history_state.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/readerable_state.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/security_state.dart';
|
||||
import 'package:lensai/features/geckoview/domain/entities/tab_state.dart';
|
||||
import 'package:lensai/features/geckoview/domain/providers.dart';
|
||||
import 'package:lensai/features/geckoview/utils/image_helper.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'tab.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class TabRepository extends _$TabRepository {
|
||||
final _tabsService = GeckoTabService();
|
||||
|
||||
void _onTabListChange(List<String> tabs) {
|
||||
state = {
|
||||
for (final tabId in tabs) tabId: state[tabId] ?? TabState.$default(tabId),
|
||||
};
|
||||
}
|
||||
|
||||
void _onTabContentStateChange(TabContentState contentState) {
|
||||
final current =
|
||||
state[contentState.id] ?? TabState.$default(contentState.id);
|
||||
|
||||
state = {...state}..[contentState.id] = current.copyWith(
|
||||
contextId: contentState.contextId,
|
||||
url: Uri.parse(contentState.url),
|
||||
title: contentState.title,
|
||||
progress: contentState.progress,
|
||||
isPrivate: contentState.isPrivate,
|
||||
isFullScreen: contentState.isFullScreen,
|
||||
isLoading: contentState.isLoading,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onIconChange(IconEvent event) async {
|
||||
final IconEvent(:tabId, :bytes) = event;
|
||||
|
||||
final current = state[tabId] ?? TabState.$default(tabId);
|
||||
|
||||
final image = (bytes != null)
|
||||
? (await tryDecodeImage(bytes)
|
||||
.then((image) async => image?.toEquatable()))
|
||||
: null;
|
||||
|
||||
state = {...state}..[tabId] = current.copyWith.icon(image);
|
||||
}
|
||||
|
||||
Future<void> _onThumbnailChange(ThumbnailEvent event) async {
|
||||
final ThumbnailEvent(:tabId, :bytes) = event;
|
||||
|
||||
final current = state[tabId] ?? TabState.$default(tabId);
|
||||
|
||||
final image = (bytes != null)
|
||||
? (await tryDecodeImage(bytes)
|
||||
.then((image) async => image?.toEquatable()))
|
||||
: null;
|
||||
|
||||
state = {...state}..[tabId] = current.copyWith.thumbnail(image);
|
||||
}
|
||||
|
||||
void _onSecurityInfoStateChange(SecurityInfoEvent event) {
|
||||
final SecurityInfoEvent(:tabId, :securityInfo) = event;
|
||||
|
||||
final current = state[tabId] ?? TabState.$default(tabId);
|
||||
|
||||
state = {...state}..[tabId] = current.copyWith.securityInfoState(
|
||||
SecurityState(
|
||||
secure: securityInfo.secure,
|
||||
host: securityInfo.host,
|
||||
issuer: securityInfo.issuer,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onHistoryStateChange(HistoryEvent event) {
|
||||
final HistoryEvent(:tabId, :history) = event;
|
||||
|
||||
final current = state[tabId] ?? TabState.$default(tabId);
|
||||
|
||||
state = {...state}..[tabId] = current.copyWith.historyState(
|
||||
HistoryState(
|
||||
items: history.items.nonNulls
|
||||
.map(
|
||||
(item) =>
|
||||
HistoryItem(url: Uri.parse(item.url), title: item.title),
|
||||
)
|
||||
.toList(),
|
||||
currentIndex: history.currentIndex,
|
||||
canGoBack: history.canGoBack,
|
||||
canGoForward: history.canGoForward,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onReaderableStateChange(ReaderableEvent event) {
|
||||
final ReaderableEvent(:tabId, :readerable) = event;
|
||||
|
||||
final current = state[tabId] ?? TabState.$default(tabId);
|
||||
|
||||
state = {...state}..[tabId] = current.copyWith.readerableState(
|
||||
ReaderableState(
|
||||
readerable: readerable.readerable,
|
||||
active: readerable.active,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> addTab({
|
||||
Uri? url,
|
||||
bool selectTab = true,
|
||||
bool startLoading = true,
|
||||
String? parentId,
|
||||
LoadUrlFlags flags = LoadUrlFlags.NONE,
|
||||
String? contextId,
|
||||
Source source = Internal.newTab,
|
||||
bool private = false,
|
||||
HistoryMetadataKey? historyMetadata,
|
||||
Map<String, String>? additionalHeaders,
|
||||
}) {
|
||||
return _tabsService.addTab(
|
||||
url: url,
|
||||
selectTab: selectTab,
|
||||
startLoading: startLoading,
|
||||
parentId: parentId,
|
||||
flags: flags,
|
||||
contextId: contextId,
|
||||
source: source,
|
||||
private: private,
|
||||
historyMetadata: historyMetadata,
|
||||
additionalHeaders: additionalHeaders,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> closeTabs(List<String> tabIds) {
|
||||
return _tabsService.removeTabs(ids: tabIds);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, TabState> build() {
|
||||
final eventService = ref.watch(eventServiceProvider);
|
||||
|
||||
final subscriptions = [
|
||||
eventService.tabListEvents.listen(_onTabListChange),
|
||||
eventService.tabContentEvents.listen(_onTabContentStateChange),
|
||||
eventService.iconEvents.listen(_onIconChange),
|
||||
eventService.thumbnailEvents.listen(_onThumbnailChange),
|
||||
eventService.securityInfoEvents.listen(_onSecurityInfoStateChange),
|
||||
eventService.historyEvents.listen(_onHistoryStateChange),
|
||||
eventService.readerableEvents.listen(_onReaderableStateChange),
|
||||
];
|
||||
|
||||
ref.onDispose(() {
|
||||
for (final sub in subscriptions) {
|
||||
unawaited(sub.cancel());
|
||||
}
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tab.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$tabRepositoryHash() => r'64724c0215624753c5c6ff8d6827b890ad9a6f2c';
|
||||
|
||||
/// See also [TabRepository].
|
||||
@ProviderFor(TabRepository)
|
||||
final tabRepositoryProvider =
|
||||
NotifierProvider<TabRepository, Map<String, TabState>>.internal(
|
||||
TabRepository.new,
|
||||
name: r'tabRepositoryProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$tabRepositoryHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$TabRepository = Notifier<Map<String, TabState>>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'tab_session.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class TabSession extends _$TabSession {
|
||||
late GeckoSessionService _sessionService;
|
||||
|
||||
Future<void> loadUrl({
|
||||
required Uri url,
|
||||
LoadUrlFlags flags = LoadUrlFlags.NONE,
|
||||
Map<String, String>? additionalHeaders,
|
||||
}) {
|
||||
return _sessionService.loadUrl(
|
||||
url: url,
|
||||
flags: flags,
|
||||
additionalHeaders: additionalHeaders,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void build(String? tabId) {
|
||||
_sessionService = (tabId != null)
|
||||
? GeckoSessionService(tabId: tabId)
|
||||
: GeckoSessionService.forActiveTab();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tab_session.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$tabSessionHash() => r'4aab49dcb544cfc9e7a61b498d2ccf2c28ef729b';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _$TabSession extends BuildlessAutoDisposeNotifier<void> {
|
||||
late final String? tabId;
|
||||
|
||||
void build(
|
||||
String? tabId,
|
||||
);
|
||||
}
|
||||
|
||||
/// See also [TabSession].
|
||||
@ProviderFor(TabSession)
|
||||
const tabSessionProvider = TabSessionFamily();
|
||||
|
||||
/// See also [TabSession].
|
||||
class TabSessionFamily extends Family<void> {
|
||||
/// See also [TabSession].
|
||||
const TabSessionFamily();
|
||||
|
||||
/// See also [TabSession].
|
||||
TabSessionProvider call(
|
||||
String? tabId,
|
||||
) {
|
||||
return TabSessionProvider(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TabSessionProvider getProviderOverride(
|
||||
covariant TabSessionProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.tabId,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'tabSessionProvider';
|
||||
}
|
||||
|
||||
/// See also [TabSession].
|
||||
class TabSessionProvider
|
||||
extends AutoDisposeNotifierProviderImpl<TabSession, void> {
|
||||
/// See also [TabSession].
|
||||
TabSessionProvider(
|
||||
String? tabId,
|
||||
) : this._internal(
|
||||
() => TabSession()..tabId = tabId,
|
||||
from: tabSessionProvider,
|
||||
name: r'tabSessionProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$tabSessionHash,
|
||||
dependencies: TabSessionFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
TabSessionFamily._allTransitiveDependencies,
|
||||
tabId: tabId,
|
||||
);
|
||||
|
||||
TabSessionProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.tabId,
|
||||
}) : super.internal();
|
||||
|
||||
final String? tabId;
|
||||
|
||||
@override
|
||||
void runNotifierBuild(
|
||||
covariant TabSession notifier,
|
||||
) {
|
||||
return notifier.build(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Override overrideWith(TabSession Function() create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: TabSessionProvider._internal(
|
||||
() => create()..tabId = tabId,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
tabId: tabId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeNotifierProviderElement<TabSession, void> createElement() {
|
||||
return _TabSessionProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is TabSessionProvider && other.tabId == tabId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, tabId.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
mixin TabSessionRef on AutoDisposeNotifierProviderRef<void> {
|
||||
/// The parameter `tabId` of this provider.
|
||||
String? get tabId;
|
||||
}
|
||||
|
||||
class _TabSessionProviderElement
|
||||
extends AutoDisposeNotifierProviderElement<TabSession, void>
|
||||
with TabSessionRef {
|
||||
_TabSessionProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String? get tabId => (origin as TabSessionProvider).tabId;
|
||||
}
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
Reference in New Issue
Block a user