everything build but untested & migration not finished
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
abstract interface class ITab {
|
||||
String get id;
|
||||
Uri get url;
|
||||
String? get title;
|
||||
String? get topicId;
|
||||
Favicon? get favicon;
|
||||
Uint8List? get screenshot;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
class ConsistentController {
|
||||
final InAppWebViewController? value;
|
||||
|
||||
const ConsistentController(this.value);
|
||||
|
||||
@override
|
||||
// ignore: avoid_dynamic_calls
|
||||
int get hashCode => value?.platform.id.hashCode ?? -1;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! ConsistentController) return false;
|
||||
return hashCode == other.hashCode;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:lensai/core/uuid.dart';
|
||||
import 'package:lensai/data/models/web_page_info.dart';
|
||||
|
||||
part 'web_view_page.g.dart';
|
||||
|
||||
typedef PageHistory = ({bool canGoBack, bool canGoForward});
|
||||
|
||||
@CopyWith()
|
||||
class WebViewPage extends WebPageInfo with FastEquatable implements ITab {
|
||||
@override
|
||||
@CopyWithField(immutable: true)
|
||||
final String id;
|
||||
|
||||
final InAppWebViewController? controller;
|
||||
|
||||
// ignore: missing_field_in_equatable_props
|
||||
final SslError? sslError;
|
||||
|
||||
@override
|
||||
final String? topicId;
|
||||
|
||||
@override
|
||||
final Uint8List? screenshot;
|
||||
|
||||
final PageHistory pageHistory;
|
||||
|
||||
WebViewPage({
|
||||
required this.id,
|
||||
required this.controller,
|
||||
required super.url,
|
||||
required this.sslError,
|
||||
required super.title,
|
||||
required this.topicId,
|
||||
required super.favicon,
|
||||
required this.screenshot,
|
||||
required this.pageHistory,
|
||||
});
|
||||
|
||||
WebViewPage.create({
|
||||
String? id,
|
||||
this.controller,
|
||||
required super.url,
|
||||
this.sslError,
|
||||
super.title,
|
||||
this.topicId,
|
||||
super.favicon,
|
||||
this.screenshot,
|
||||
this.pageHistory = (canGoBack: false, canGoForward: false),
|
||||
}) : id = id ?? uuid.v7();
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
id,
|
||||
controller,
|
||||
super.url,
|
||||
sslError?.toString(),
|
||||
title,
|
||||
topicId,
|
||||
favicon?.toString(),
|
||||
screenshot,
|
||||
pageHistory,
|
||||
];
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'web_view_page.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$WebViewPageCWProxy {
|
||||
WebViewPage controller(InvalidType controller);
|
||||
|
||||
WebViewPage url(Uri url);
|
||||
|
||||
WebViewPage sslError(InvalidType sslError);
|
||||
|
||||
WebViewPage title(String? title);
|
||||
|
||||
WebViewPage topicId(String? topicId);
|
||||
|
||||
WebViewPage favicon(BrowserIcon? favicon);
|
||||
|
||||
WebViewPage screenshot(Uint8List? screenshot);
|
||||
|
||||
WebViewPage pageHistory(({bool canGoBack, bool canGoForward}) pageHistory);
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `WebViewPage(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// WebViewPage(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
WebViewPage call({
|
||||
InvalidType? controller,
|
||||
Uri? url,
|
||||
InvalidType? sslError,
|
||||
String? title,
|
||||
String? topicId,
|
||||
BrowserIcon? favicon,
|
||||
Uint8List? screenshot,
|
||||
({bool canGoBack, bool canGoForward})? pageHistory,
|
||||
});
|
||||
}
|
||||
|
||||
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfWebViewPage.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfWebViewPage.copyWith.fieldName(...)`
|
||||
class _$WebViewPageCWProxyImpl implements _$WebViewPageCWProxy {
|
||||
const _$WebViewPageCWProxyImpl(this._value);
|
||||
|
||||
final WebViewPage _value;
|
||||
|
||||
@override
|
||||
WebViewPage controller(InvalidType controller) =>
|
||||
this(controller: controller);
|
||||
|
||||
@override
|
||||
WebViewPage url(Uri url) => this(url: url);
|
||||
|
||||
@override
|
||||
WebViewPage sslError(InvalidType sslError) => this(sslError: sslError);
|
||||
|
||||
@override
|
||||
WebViewPage title(String? title) => this(title: title);
|
||||
|
||||
@override
|
||||
WebViewPage topicId(String? topicId) => this(topicId: topicId);
|
||||
|
||||
@override
|
||||
WebViewPage favicon(BrowserIcon? favicon) => this(favicon: favicon);
|
||||
|
||||
@override
|
||||
WebViewPage screenshot(Uint8List? screenshot) => this(screenshot: screenshot);
|
||||
|
||||
@override
|
||||
WebViewPage pageHistory(({bool canGoBack, bool canGoForward}) pageHistory) =>
|
||||
this(pageHistory: pageHistory);
|
||||
|
||||
@override
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `WebViewPage(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// WebViewPage(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
WebViewPage call({
|
||||
Object? controller = const $CopyWithPlaceholder(),
|
||||
Object? url = const $CopyWithPlaceholder(),
|
||||
Object? sslError = const $CopyWithPlaceholder(),
|
||||
Object? title = const $CopyWithPlaceholder(),
|
||||
Object? topicId = const $CopyWithPlaceholder(),
|
||||
Object? favicon = const $CopyWithPlaceholder(),
|
||||
Object? screenshot = const $CopyWithPlaceholder(),
|
||||
Object? pageHistory = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return WebViewPage(
|
||||
id: _value.id,
|
||||
controller:
|
||||
controller == const $CopyWithPlaceholder() || controller == null
|
||||
? _value.controller
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: controller as InvalidType,
|
||||
url: url == const $CopyWithPlaceholder() || url == null
|
||||
? _value.url
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: url as Uri,
|
||||
sslError: sslError == const $CopyWithPlaceholder() || sslError == null
|
||||
? _value.sslError
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: sslError as InvalidType,
|
||||
title: title == const $CopyWithPlaceholder()
|
||||
? _value.title
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: title as String?,
|
||||
topicId: topicId == const $CopyWithPlaceholder()
|
||||
? _value.topicId
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: topicId as String?,
|
||||
favicon: favicon == const $CopyWithPlaceholder()
|
||||
? _value.favicon
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: favicon as BrowserIcon?,
|
||||
screenshot: screenshot == const $CopyWithPlaceholder()
|
||||
? _value.screenshot
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: screenshot as Uint8List?,
|
||||
pageHistory:
|
||||
pageHistory == const $CopyWithPlaceholder() || pageHistory == null
|
||||
? _value.pageHistory
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: pageHistory as ({bool canGoBack, bool canGoForward}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $WebViewPageCopyWith on WebViewPage {
|
||||
/// Returns a callable class that can be used as follows: `instanceOfWebViewPage.copyWith(...)` or like so:`instanceOfWebViewPage.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$WebViewPageCWProxy get copyWith => _$WebViewPageCWProxyImpl(this);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:lensai/features/content_block/domain/repositories/host.dart';
|
||||
import 'package:lensai/features/settings/data/models/settings.dart';
|
||||
import 'package:lensai/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:lensai/features/geckoview/features/topics/domain/providers.dart';
|
||||
import 'package:lensai/features/geckoview/features/topics/domain/repositories/tab_link.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:universal_io/io.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Stream<Set<String>?> blockContentHosts(BlockContentHostsRef ref) {
|
||||
final hostRepository = ref.watch(hostRepositoryProvider.notifier);
|
||||
final enableContentBlocking = ref.watch(
|
||||
settingsRepositoryProvider.select(
|
||||
(value) =>
|
||||
(value.valueOrNull ?? Settings.withDefaults()).enableContentBlocking,
|
||||
),
|
||||
);
|
||||
final enableHostList = ref.watch(
|
||||
settingsRepositoryProvider.select(
|
||||
(value) => (value.valueOrNull ?? Settings.withDefaults()).enableHostList,
|
||||
),
|
||||
);
|
||||
|
||||
if (!enableContentBlocking || enableHostList.isEmpty) {
|
||||
return Stream.value(null);
|
||||
}
|
||||
|
||||
return hostRepository
|
||||
.watchHosts(sources: enableHostList)
|
||||
.map((hosts) => hosts.toSet());
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Future<String> readerabilityScript(ReaderabilityScriptRef ref) {
|
||||
return rootBundle.load('assets/scripts/readability.min.js.gz').then(
|
||||
(value) => compute(
|
||||
(message) => utf8.decode(gzip.decode(message)),
|
||||
value.buffer.asUint8List(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
List<String> activeTabs(ActiveTabsRef ref) {
|
||||
final topic = ref.watch(selectedTopicProvider);
|
||||
return ref.watch(
|
||||
topicTabRepositoryProvider(topic)
|
||||
.select((value) => value.valueOrNull ?? []),
|
||||
);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'providers.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$blockContentHostsHash() => r'41855093d8376152244ae37f98e66eea7c74aa32';
|
||||
|
||||
/// See also [blockContentHosts].
|
||||
@ProviderFor(blockContentHosts)
|
||||
final blockContentHostsProvider = StreamProvider<Set<String>?>.internal(
|
||||
blockContentHosts,
|
||||
name: r'blockContentHostsProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$blockContentHostsHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef BlockContentHostsRef = StreamProviderRef<Set<String>?>;
|
||||
String _$readerabilityScriptHash() =>
|
||||
r'6fdd1aa920bc58c35ef9888158e572e25793870a';
|
||||
|
||||
/// See also [readerabilityScript].
|
||||
@ProviderFor(readerabilityScript)
|
||||
final readerabilityScriptProvider = FutureProvider<String>.internal(
|
||||
readerabilityScript,
|
||||
name: r'readerabilityScriptProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$readerabilityScriptHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef ReaderabilityScriptRef = FutureProviderRef<String>;
|
||||
String _$activeTabsHash() => r'd1ef2ae32d8707f7cc0902dd031e8302a63f50d4';
|
||||
|
||||
/// See also [activeTabs].
|
||||
@ProviderFor(activeTabs)
|
||||
final activeTabsProvider = AutoDisposeProvider<List<String>>.internal(
|
||||
activeTabs,
|
||||
name: r'activeTabsProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$activeTabsHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef ActiveTabsRef = AutoDisposeProviderRef<List<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
|
||||
@@ -1,179 +0,0 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/core/logger.dart';
|
||||
import 'package:lensai/features/geckoview/features/topics/data/providers.dart';
|
||||
import 'package:lensai/features/geckoview/features/topics/domain/providers.dart';
|
||||
import 'package:lensai/features/geckoview/features/topics/domain/repositories/tab_link.dart';
|
||||
import 'package:lensai/features/web_view/domain/entities/consistent_controller.dart';
|
||||
import 'package:lensai/features/web_view/domain/entities/web_view_page.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'web_view.g.dart';
|
||||
|
||||
abstract class _TabStateCopyProxy {
|
||||
Future<void> copyWith({
|
||||
InAppWebViewController? controller,
|
||||
Uri? url,
|
||||
SslError? sslError,
|
||||
String? title,
|
||||
String? topicId,
|
||||
Favicon? favicon,
|
||||
Uint8List? screenshot,
|
||||
({bool canGoBack, bool canGoForward})? pageHistory,
|
||||
});
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
class WebViewTabController extends _$WebViewTabController {
|
||||
String? _requestedTab;
|
||||
|
||||
@override
|
||||
String? build() {
|
||||
final webViewTabs = ref.watch(
|
||||
tabRepositoryProvider.select(
|
||||
(value) => value.value ?? [],
|
||||
),
|
||||
);
|
||||
|
||||
if (_requestedTab != null) {
|
||||
if (webViewTabs.any((tab) => tab.id == _requestedTab)) {
|
||||
return _requestedTab;
|
||||
} else if (webViewTabs.isNotEmpty) {
|
||||
final topic = ref.read(selectedTopicProvider);
|
||||
return webViewTabs.where((tab) => tab.topicId == topic).lastOrNull?.id;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void showTab(String? id) {
|
||||
_requestedTab = id;
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
class TabState extends _$TabState implements _TabStateCopyProxy {
|
||||
KeepAliveLink? _aliveLink;
|
||||
|
||||
@override
|
||||
WebViewPage? build(String tabId) {
|
||||
final tabAsync = ref.watch(tabDataProvider(tabId));
|
||||
|
||||
if (tabAsync.hasValue) {
|
||||
final tab = tabAsync.valueOrNull;
|
||||
|
||||
final current = stateOrNull ??
|
||||
WebViewPage.create(
|
||||
id: tabId,
|
||||
url: tab?.url ?? Uri.https('localhost'),
|
||||
);
|
||||
|
||||
if (tab != null) {
|
||||
_aliveLink ??= ref.keepAlive();
|
||||
|
||||
return current.copyWith(
|
||||
topicId: tab.topicId,
|
||||
url: tab.url,
|
||||
title: tab.title,
|
||||
screenshot: tab.screenshot,
|
||||
);
|
||||
} else {
|
||||
_aliveLink?.close();
|
||||
_aliveLink = null;
|
||||
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> updateScreenshot() async {
|
||||
final screenshot = await state?.controller
|
||||
?.takeScreenshot(
|
||||
screenshotConfiguration: ScreenshotConfiguration(
|
||||
compressFormat: CompressFormat.JPEG,
|
||||
quality: 20,
|
||||
),
|
||||
)
|
||||
.timeout(
|
||||
const Duration(milliseconds: 1500),
|
||||
onTimeout: () {
|
||||
logger.w('Screenshot timed out');
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
await copyWith(screenshot: screenshot);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> copyWith({
|
||||
Object? controller = const $CopyWithPlaceholder(),
|
||||
Object? url = const $CopyWithPlaceholder(),
|
||||
Object? sslError = const $CopyWithPlaceholder(),
|
||||
Object? title = const $CopyWithPlaceholder(),
|
||||
Object? topicId = const $CopyWithPlaceholder(),
|
||||
Object? favicon = const $CopyWithPlaceholder(),
|
||||
Object? screenshot = const $CopyWithPlaceholder(),
|
||||
Object? pageHistory = const $CopyWithPlaceholder(),
|
||||
}) async {
|
||||
if (state != null) {
|
||||
final current = state!;
|
||||
|
||||
state = WebViewPage(
|
||||
id: current.id,
|
||||
controller: controller == const $CopyWithPlaceholder()
|
||||
? current.controller
|
||||
: controller as InAppWebViewController?,
|
||||
url: current.url,
|
||||
sslError: sslError == const $CopyWithPlaceholder()
|
||||
? current.sslError
|
||||
: sslError as SslError?,
|
||||
title: current.title,
|
||||
topicId: current.topicId,
|
||||
favicon: favicon == const $CopyWithPlaceholder()
|
||||
? current.favicon
|
||||
: favicon as Favicon?,
|
||||
screenshot: current.screenshot,
|
||||
pageHistory:
|
||||
pageHistory == const $CopyWithPlaceholder() || pageHistory == null
|
||||
? current.pageHistory
|
||||
: pageHistory as ({bool canGoBack, bool canGoForward}),
|
||||
);
|
||||
|
||||
await ref.read(tabRepositoryProvider.notifier).updateTab(
|
||||
current.id,
|
||||
url: url == const $CopyWithPlaceholder() || url == null
|
||||
? const Value.absent()
|
||||
: Value(url as Uri),
|
||||
title: title == const $CopyWithPlaceholder()
|
||||
? const Value.absent()
|
||||
: Value(title as String?),
|
||||
topicId: topicId == const $CopyWithPlaceholder()
|
||||
? const Value.absent()
|
||||
: Value(topicId as String?),
|
||||
screenshot: screenshot == const $CopyWithPlaceholder()
|
||||
? const Value.absent()
|
||||
: Value(screenshot as Uint8List?),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
InAppWebViewController? webViewController(
|
||||
WebViewControllerRef ref,
|
||||
String tabId,
|
||||
) {
|
||||
return ref
|
||||
.watch(
|
||||
tabStateProvider(tabId)
|
||||
.select((value) => ConsistentController(value?.controller)),
|
||||
)
|
||||
.value;
|
||||
}
|
||||
@@ -1,318 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'web_view.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$webViewControllerHash() => r'f35fb13d46fcb04cee5676089f0cb8d5ca21e89b';
|
||||
|
||||
/// 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 [webViewController].
|
||||
@ProviderFor(webViewController)
|
||||
const webViewControllerProvider = WebViewControllerFamily();
|
||||
|
||||
/// See also [webViewController].
|
||||
class WebViewControllerFamily extends Family<InAppWebViewController?> {
|
||||
/// See also [webViewController].
|
||||
const WebViewControllerFamily();
|
||||
|
||||
/// See also [webViewController].
|
||||
WebViewControllerProvider call(
|
||||
String tabId,
|
||||
) {
|
||||
return WebViewControllerProvider(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
WebViewControllerProvider getProviderOverride(
|
||||
covariant WebViewControllerProvider 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'webViewControllerProvider';
|
||||
}
|
||||
|
||||
/// See also [webViewController].
|
||||
class WebViewControllerProvider
|
||||
extends AutoDisposeProvider<InAppWebViewController?> {
|
||||
/// See also [webViewController].
|
||||
WebViewControllerProvider(
|
||||
String tabId,
|
||||
) : this._internal(
|
||||
(ref) => webViewController(
|
||||
ref as WebViewControllerRef,
|
||||
tabId,
|
||||
),
|
||||
from: webViewControllerProvider,
|
||||
name: r'webViewControllerProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$webViewControllerHash,
|
||||
dependencies: WebViewControllerFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
WebViewControllerFamily._allTransitiveDependencies,
|
||||
tabId: tabId,
|
||||
);
|
||||
|
||||
WebViewControllerProvider._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(
|
||||
InAppWebViewController? Function(WebViewControllerRef provider) create,
|
||||
) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: WebViewControllerProvider._internal(
|
||||
(ref) => create(ref as WebViewControllerRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
tabId: tabId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeProviderElement<InAppWebViewController?> createElement() {
|
||||
return _WebViewControllerProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is WebViewControllerProvider && 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 WebViewControllerRef on AutoDisposeProviderRef<InAppWebViewController?> {
|
||||
/// The parameter `tabId` of this provider.
|
||||
String get tabId;
|
||||
}
|
||||
|
||||
class _WebViewControllerProviderElement
|
||||
extends AutoDisposeProviderElement<InAppWebViewController?>
|
||||
with WebViewControllerRef {
|
||||
_WebViewControllerProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get tabId => (origin as WebViewControllerProvider).tabId;
|
||||
}
|
||||
|
||||
String _$webViewTabControllerHash() =>
|
||||
r'cf1b766aa84472040b56a7b4d9ce1fd1606ed5e1';
|
||||
|
||||
/// See also [WebViewTabController].
|
||||
@ProviderFor(WebViewTabController)
|
||||
final webViewTabControllerProvider =
|
||||
AutoDisposeNotifierProvider<WebViewTabController, String?>.internal(
|
||||
WebViewTabController.new,
|
||||
name: r'webViewTabControllerProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$webViewTabControllerHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$WebViewTabController = AutoDisposeNotifier<String?>;
|
||||
String _$tabStateHash() => r'9ce6b0d99e5032f534c97482d6140dda4b14fb07';
|
||||
|
||||
abstract class _$TabState extends BuildlessAutoDisposeNotifier<WebViewPage?> {
|
||||
late final String tabId;
|
||||
|
||||
WebViewPage? build(
|
||||
String tabId,
|
||||
);
|
||||
}
|
||||
|
||||
/// See also [TabState].
|
||||
@ProviderFor(TabState)
|
||||
const tabStateProvider = TabStateFamily();
|
||||
|
||||
/// See also [TabState].
|
||||
class TabStateFamily extends Family<WebViewPage?> {
|
||||
/// 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 AutoDisposeNotifierProviderImpl<TabState, WebViewPage?> {
|
||||
/// See also [TabState].
|
||||
TabStateProvider(
|
||||
String tabId,
|
||||
) : this._internal(
|
||||
() => TabState()..tabId = 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
|
||||
WebViewPage? runNotifierBuild(
|
||||
covariant TabState notifier,
|
||||
) {
|
||||
return notifier.build(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Override overrideWith(TabState Function() create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: TabStateProvider._internal(
|
||||
() => create()..tabId = tabId,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
tabId: tabId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeNotifierProviderElement<TabState, WebViewPage?> 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 AutoDisposeNotifierProviderRef<WebViewPage?> {
|
||||
/// The parameter `tabId` of this provider.
|
||||
String get tabId;
|
||||
}
|
||||
|
||||
class _TabStateProviderElement
|
||||
extends AutoDisposeNotifierProviderElement<TabState, WebViewPage?>
|
||||
with TabStateRef {
|
||||
_TabStateProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get tabId => (origin as TabStateProvider).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
|
||||
@@ -1,64 +0,0 @@
|
||||
import 'package:lensai/features/geckoview/features/topics/data/providers.dart';
|
||||
import 'package:lensai/features/web_view/domain/repositories/web_view.dart';
|
||||
import 'package:lensai/features/web_view/presentation/services/readerability_script.dart';
|
||||
import 'package:riverpod/riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'readerability.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class ReaderabilityController extends _$ReaderabilityController {
|
||||
late ReaderabilityScriptService _service;
|
||||
late KeepAliveLink _aliveLink;
|
||||
|
||||
@override
|
||||
AsyncValue<({bool readerable, bool applied})> build(
|
||||
String tabId,
|
||||
) {
|
||||
_service = ref.watch(readerabilityScriptServiceProvider(tabId).notifier);
|
||||
_aliveLink = ref.keepAlive();
|
||||
|
||||
ref.listen(
|
||||
isTabExistingProvider(tabId),
|
||||
(previous, next) {
|
||||
if (next.valueOrNull == false) {
|
||||
_aliveLink.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return const AsyncLoading();
|
||||
}
|
||||
|
||||
Future<bool> checkReaderable() async {
|
||||
final applied = state.valueOrNull?.applied ?? false;
|
||||
|
||||
state = const AsyncLoading();
|
||||
final result = await AsyncValue.guard(() async {
|
||||
return (readerable: await _service.isReaderable(), applied: applied);
|
||||
});
|
||||
state = result;
|
||||
|
||||
return result.valueOrNull?.readerable ?? false;
|
||||
}
|
||||
|
||||
Future<void> toggleReaderable() async {
|
||||
final applied = state.valueOrNull?.applied ?? false;
|
||||
final readerable = state.valueOrNull?.readerable ?? false;
|
||||
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
if (applied) {
|
||||
await ref.read(webViewControllerProvider(tabId))?.reload();
|
||||
} else {
|
||||
await _service.applyReaderable();
|
||||
}
|
||||
|
||||
return (readerable: readerable, applied: !applied);
|
||||
});
|
||||
}
|
||||
|
||||
void reset() {
|
||||
state = const AsyncLoading();
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'readerability.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$readerabilityControllerHash() =>
|
||||
r'a1c8da3a9cf48300089e390a4fcae89862a6ec1a';
|
||||
|
||||
/// 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 _$ReaderabilityController extends BuildlessAutoDisposeNotifier<
|
||||
AsyncValue<({bool readerable, bool applied})>> {
|
||||
late final String tabId;
|
||||
|
||||
AsyncValue<({bool readerable, bool applied})> build(
|
||||
String tabId,
|
||||
);
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
@ProviderFor(ReaderabilityController)
|
||||
const readerabilityControllerProvider = ReaderabilityControllerFamily();
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
class ReaderabilityControllerFamily
|
||||
extends Family<AsyncValue<({bool readerable, bool applied})>> {
|
||||
/// See also [ReaderabilityController].
|
||||
const ReaderabilityControllerFamily();
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
ReaderabilityControllerProvider call(
|
||||
String tabId,
|
||||
) {
|
||||
return ReaderabilityControllerProvider(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
ReaderabilityControllerProvider getProviderOverride(
|
||||
covariant ReaderabilityControllerProvider 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'readerabilityControllerProvider';
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
class ReaderabilityControllerProvider extends AutoDisposeNotifierProviderImpl<
|
||||
ReaderabilityController, AsyncValue<({bool readerable, bool applied})>> {
|
||||
/// See also [ReaderabilityController].
|
||||
ReaderabilityControllerProvider(
|
||||
String tabId,
|
||||
) : this._internal(
|
||||
() => ReaderabilityController()..tabId = tabId,
|
||||
from: readerabilityControllerProvider,
|
||||
name: r'readerabilityControllerProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$readerabilityControllerHash,
|
||||
dependencies: ReaderabilityControllerFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
ReaderabilityControllerFamily._allTransitiveDependencies,
|
||||
tabId: tabId,
|
||||
);
|
||||
|
||||
ReaderabilityControllerProvider._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
|
||||
AsyncValue<({bool readerable, bool applied})> runNotifierBuild(
|
||||
covariant ReaderabilityController notifier,
|
||||
) {
|
||||
return notifier.build(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Override overrideWith(ReaderabilityController Function() create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: ReaderabilityControllerProvider._internal(
|
||||
() => create()..tabId = tabId,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
tabId: tabId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeNotifierProviderElement<ReaderabilityController,
|
||||
AsyncValue<({bool readerable, bool applied})>> createElement() {
|
||||
return _ReaderabilityControllerProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ReaderabilityControllerProvider && 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 ReaderabilityControllerRef on AutoDisposeNotifierProviderRef<
|
||||
AsyncValue<({bool readerable, bool applied})>> {
|
||||
/// The parameter `tabId` of this provider.
|
||||
String get tabId;
|
||||
}
|
||||
|
||||
class _ReaderabilityControllerProviderElement
|
||||
extends AutoDisposeNotifierProviderElement<ReaderabilityController,
|
||||
AsyncValue<({bool readerable, bool applied})>>
|
||||
with ReaderabilityControllerRef {
|
||||
_ReaderabilityControllerProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get tabId => (origin as ReaderabilityControllerProvider).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
|
||||
@@ -1,32 +0,0 @@
|
||||
import 'package:lensai/features/geckoview/features/topics/domain/providers.dart';
|
||||
import 'package:lensai/features/geckoview/features/topics/domain/repositories/tab_link.dart';
|
||||
import 'package:lensai/features/web_view/domain/entities/web_view_page.dart';
|
||||
import 'package:lensai/features/web_view/domain/repositories/web_view.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'switch_new_tab.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class SwitchNewTabController extends _$SwitchNewTabController {
|
||||
@override
|
||||
FutureOr<void> build() {}
|
||||
|
||||
Future<void> add(Uri url) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
() async {
|
||||
final topic = ref.read(selectedTopicProvider);
|
||||
final newTab = WebViewPage.create(
|
||||
url: WebUri.uri(url),
|
||||
topicId: topic,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(topicTabRepositoryProvider(topic).notifier)
|
||||
.addTab(newTab);
|
||||
|
||||
ref.read(webViewTabControllerProvider.notifier).showTab(newTab.id);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'switch_new_tab.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$switchNewTabControllerHash() =>
|
||||
r'7ebfea953aeb81c279ea11254ff0ad558e6a949f';
|
||||
|
||||
/// See also [SwitchNewTabController].
|
||||
@ProviderFor(SwitchNewTabController)
|
||||
final switchNewTabControllerProvider =
|
||||
AsyncNotifierProvider<SwitchNewTabController, void>.internal(
|
||||
SwitchNewTabController.new,
|
||||
name: r'switchNewTabControllerProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$switchNewTabControllerHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$SwitchNewTabController = AsyncNotifier<void>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -1,70 +0,0 @@
|
||||
import 'package:lensai/features/settings/data/models/settings.dart';
|
||||
import 'package:lensai/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:lensai/features/web_view/domain/providers.dart';
|
||||
import 'package:lensai/features/web_view/domain/repositories/web_view.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'readerability_script.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class ReaderabilityScriptService extends _$ReaderabilityScriptService {
|
||||
late InAppWebViewController? _controller;
|
||||
late Future<String> _readerabilityScript;
|
||||
late bool _enableReadability;
|
||||
|
||||
@override
|
||||
Future<void> build(String tabId) async {
|
||||
_controller = ref.watch(webViewControllerProvider(tabId));
|
||||
_readerabilityScript = ref.watch(readerabilityScriptProvider.future);
|
||||
_enableReadability = ref.watch(
|
||||
settingsRepositoryProvider.select(
|
||||
(value) =>
|
||||
(value.valueOrNull ?? Settings.withDefaults()).enableReadability,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _injectScript() async {
|
||||
if (_controller != null) {
|
||||
await _readerabilityScript
|
||||
.then((script) => _controller!.evaluateJavascript(source: script));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _ensureScriptInjected() async {
|
||||
if (_controller != null) {
|
||||
final injected = await _controller!.evaluateJavascript(
|
||||
source:
|
||||
"(typeof window !== 'undefined' && typeof window.isReaderable === 'function')",
|
||||
) as bool;
|
||||
|
||||
if (!injected) {
|
||||
await _injectScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> isReaderable() async {
|
||||
if (_enableReadability) {
|
||||
await _ensureScriptInjected();
|
||||
|
||||
if (_controller != null) {
|
||||
return await _controller!.evaluateJavascript(
|
||||
source: 'isReaderable();',
|
||||
) as bool;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> applyReaderable() async {
|
||||
if (_enableReadability) {
|
||||
await _ensureScriptInjected();
|
||||
|
||||
if (_controller != null) {
|
||||
await _controller!.evaluateJavascript(source: 'applyReaderable();');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'readerability_script.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$readerabilityScriptServiceHash() =>
|
||||
r'85f0de50516cadb1f2d1efa8161a8cf45868b9d9';
|
||||
|
||||
/// 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 _$ReaderabilityScriptService
|
||||
extends BuildlessAutoDisposeAsyncNotifier<void> {
|
||||
late final String tabId;
|
||||
|
||||
FutureOr<void> build(
|
||||
String tabId,
|
||||
);
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
@ProviderFor(ReaderabilityScriptService)
|
||||
const readerabilityScriptServiceProvider = ReaderabilityScriptServiceFamily();
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
class ReaderabilityScriptServiceFamily extends Family<AsyncValue<void>> {
|
||||
/// See also [ReaderabilityScriptService].
|
||||
const ReaderabilityScriptServiceFamily();
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
ReaderabilityScriptServiceProvider call(
|
||||
String tabId,
|
||||
) {
|
||||
return ReaderabilityScriptServiceProvider(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
ReaderabilityScriptServiceProvider getProviderOverride(
|
||||
covariant ReaderabilityScriptServiceProvider 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'readerabilityScriptServiceProvider';
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
class ReaderabilityScriptServiceProvider
|
||||
extends AutoDisposeAsyncNotifierProviderImpl<ReaderabilityScriptService,
|
||||
void> {
|
||||
/// See also [ReaderabilityScriptService].
|
||||
ReaderabilityScriptServiceProvider(
|
||||
String tabId,
|
||||
) : this._internal(
|
||||
() => ReaderabilityScriptService()..tabId = tabId,
|
||||
from: readerabilityScriptServiceProvider,
|
||||
name: r'readerabilityScriptServiceProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$readerabilityScriptServiceHash,
|
||||
dependencies: ReaderabilityScriptServiceFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
ReaderabilityScriptServiceFamily._allTransitiveDependencies,
|
||||
tabId: tabId,
|
||||
);
|
||||
|
||||
ReaderabilityScriptServiceProvider._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
|
||||
FutureOr<void> runNotifierBuild(
|
||||
covariant ReaderabilityScriptService notifier,
|
||||
) {
|
||||
return notifier.build(
|
||||
tabId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Override overrideWith(ReaderabilityScriptService Function() create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: ReaderabilityScriptServiceProvider._internal(
|
||||
() => create()..tabId = tabId,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
tabId: tabId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeAsyncNotifierProviderElement<ReaderabilityScriptService, void>
|
||||
createElement() {
|
||||
return _ReaderabilityScriptServiceProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ReaderabilityScriptServiceProvider && 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 ReaderabilityScriptServiceRef
|
||||
on AutoDisposeAsyncNotifierProviderRef<void> {
|
||||
/// The parameter `tabId` of this provider.
|
||||
String get tabId;
|
||||
}
|
||||
|
||||
class _ReaderabilityScriptServiceProviderElement
|
||||
extends AutoDisposeAsyncNotifierProviderElement<ReaderabilityScriptService,
|
||||
void> with ReaderabilityScriptServiceRef {
|
||||
_ReaderabilityScriptServiceProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get tabId => (origin as ReaderabilityScriptServiceProvider).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
|
||||
@@ -1,215 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/data/models/web_page_info.dart';
|
||||
import 'package:lensai/features/bangs/data/models/bang_data.dart';
|
||||
import 'package:lensai/features/bangs/domain/providers.dart';
|
||||
import 'package:lensai/features/bangs/presentation/widgets/site_search.dart';
|
||||
import 'package:lensai/features/kagi/data/entities/modes.dart';
|
||||
import 'package:lensai/features/search_browser/utils/url_builder.dart'
|
||||
as uri_builder;
|
||||
import 'package:lensai/features/settings/data/models/settings.dart';
|
||||
import 'package:lensai/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:lensai/features/share_intent/domain/entities/shared_content.dart';
|
||||
import 'package:lensai/features/web_view/presentation/controllers/switch_new_tab.dart';
|
||||
import 'package:lensai/presentation/widgets/failure_widget.dart';
|
||||
import 'package:lensai/presentation/widgets/website_title_tile.dart';
|
||||
import 'package:lensai/utils/ui_helper.dart' as ui_helper;
|
||||
import 'package:lensai/utils/uri_parser.dart' as uri_parser;
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
class WebPageDialog extends HookConsumerWidget {
|
||||
final Uri url;
|
||||
final WebPageInfo? precachedInfo;
|
||||
|
||||
final void Function()? onDismiss;
|
||||
|
||||
const WebPageDialog({
|
||||
required this.url,
|
||||
this.precachedInfo,
|
||||
this.onDismiss,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final incognitoEnabled = ref.watch(
|
||||
settingsRepositoryProvider.select(
|
||||
(value) => (value.valueOrNull ?? Settings.withDefaults()).incognitoMode,
|
||||
),
|
||||
);
|
||||
|
||||
final availableBangsAsync = ref.watch(
|
||||
bangDataListProvider(
|
||||
filter: (
|
||||
domain: url.host,
|
||||
groups: null,
|
||||
categoryFilter: null,
|
||||
orderMostFrequentFirst: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
final availableBangCount = availableBangsAsync.valueOrNull?.length;
|
||||
|
||||
final formKey = useMemoized(() => GlobalKey<FormState>());
|
||||
final urlTextController = useTextEditingController(text: url.toString());
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
ModalBarrier(
|
||||
color: Theme.of(context).dialogTheme.barrierColor ?? Colors.black54,
|
||||
onDismiss: onDismiss,
|
||||
),
|
||||
SimpleDialog(
|
||||
titlePadding: const EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 0.0),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
insetPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 20.0,
|
||||
vertical: 24.0,
|
||||
),
|
||||
title: WebsiteTitleTile(url, precachedInfo: precachedInfo),
|
||||
children: [
|
||||
SizedBox(
|
||||
//We need this to stretch the dialog, then padding from dialog is applied
|
||||
width: double.maxFinite,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: TextFormField(
|
||||
controller: urlTextController,
|
||||
enableIMEPersonalizedLearning: !incognitoEnabled,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'URL',
|
||||
suffixIcon: (webViewController != null)
|
||||
? IconButton(
|
||||
onPressed: () async {
|
||||
if (formKey.currentState?.validate() ?? false) {
|
||||
await webViewController!.loadUrl(
|
||||
urlRequest: URLRequest(
|
||||
url: WebUri.uri(
|
||||
uri_parser.tryParseUrl(
|
||||
urlTextController.text,
|
||||
eagerParsing: true,
|
||||
)!,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
onDismiss?.call();
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.send),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
validator: (value) {
|
||||
if (uri_parser.tryParseUrl(value, eagerParsing: true) !=
|
||||
null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return 'Invalid URL';
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: availableBangsAsync.when(
|
||||
data: (availableBangs) {
|
||||
if (availableBangs.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return SiteSearch(
|
||||
domain: url.host,
|
||||
availableBangs: availableBangs,
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => FailureWidget(
|
||||
title: 'Could not load bangs',
|
||||
exception: error,
|
||||
),
|
||||
loading: () => SiteSearch(
|
||||
domain: url.host,
|
||||
availableBangs: [
|
||||
BangData(
|
||||
websiteName: 'websiteName',
|
||||
domain: 'domain',
|
||||
trigger: 'trigger',
|
||||
urlTemplate: 'urlTemplate',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (availableBangsAsync.isLoading ||
|
||||
availableBangCount == null ||
|
||||
availableBangCount > 0)
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(MdiIcons.contentCopy),
|
||||
title: const Text('Copy address'),
|
||||
onTap: () async {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: url.toString()),
|
||||
);
|
||||
onDismiss?.call();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
onTap: () async {
|
||||
await ui_helper.launchUrlFeedback(context, url);
|
||||
},
|
||||
leading: const Icon(Icons.open_in_browser),
|
||||
title: const Text('Launch External'),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(MdiIcons.tabPlus),
|
||||
title: const Text('Open in new tab'),
|
||||
onTap: () async {
|
||||
await ref
|
||||
.read(switchNewTabControllerProvider.notifier)
|
||||
.add(url);
|
||||
|
||||
onDismiss?.call();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.share),
|
||||
title: const Text('Share link'),
|
||||
onTap: () async {
|
||||
await Share.shareUri(url);
|
||||
|
||||
onDismiss?.call();
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: Icon(KagiTool.summarizer.icon),
|
||||
title: const Text('Summarize'),
|
||||
onTap: () async {
|
||||
final summarizerUrl = uri_builder.summarizerUri(
|
||||
document: SharedUrl(url),
|
||||
mode: SummarizerMode.keyMoments,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(switchNewTabControllerProvider.notifier)
|
||||
.add(summarizerUrl);
|
||||
|
||||
onDismiss?.call();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,107 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lensai/features/web_view/domain/entities/abstract/tab.dart';
|
||||
import 'package:lensai/features/search_browser/presentation/widgets/favicon.dart';
|
||||
|
||||
class WebViewTab extends StatelessWidget {
|
||||
final ITab tab;
|
||||
final bool isActive;
|
||||
|
||||
final VoidCallback? onTap;
|
||||
final VoidCallback? onLongPress;
|
||||
final VoidCallback? onDelete;
|
||||
|
||||
const WebViewTab({
|
||||
required this.tab,
|
||||
required this.isActive,
|
||||
this.onTap,
|
||||
this.onLongPress,
|
||||
this.onDelete,
|
||||
super.key,
|
||||
});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: isActive ? colorScheme.primary : colorScheme.outline,
|
||||
width: isActive ? 2.0 : 1.0,
|
||||
),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
|
||||
),
|
||||
child: Material(
|
||||
color: colorScheme.surfaceContainerHighest,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
|
||||
child: InkWell(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 6.0),
|
||||
child: Text(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
tab.title ?? 'New Tab',
|
||||
maxLines: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
visualDensity:
|
||||
const VisualDensity(horizontal: -4.0, vertical: -4.0),
|
||||
onPressed: onDelete,
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 6.0,
|
||||
),
|
||||
FaviconImage(
|
||||
url: tab.url,
|
||||
favicon: tab.favicon,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 6.0,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
tab.url.authority,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 6,
|
||||
),
|
||||
if (tab.screenshot != null)
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(16.0),
|
||||
bottomRight: Radius.circular(16.0),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Image.memory(
|
||||
fit: BoxFit.fitWidth,
|
||||
tab.screenshot!,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user