implemented selection api
This commit is contained in:
@@ -2,11 +2,77 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:lensai/core/logger.dart';
|
||||
import 'package:lensai/features/bangs/domain/providers.dart';
|
||||
import 'package:lensai/features/geckoview/domain/providers/tab_session.dart';
|
||||
import 'package:lensai/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
GeckoSelectionActionService selectionActionService(
|
||||
SelectionActionServiceRef ref,
|
||||
) {
|
||||
final service = GeckoSelectionActionService.setUp();
|
||||
|
||||
unawaited(
|
||||
service.setActions([
|
||||
SearchAction((text) async {
|
||||
final defaultSearchBang =
|
||||
await ref.read(kagiSearchBangDataProvider.future);
|
||||
|
||||
if (defaultSearchBang != null) {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(url: defaultSearchBang.getUrl(text));
|
||||
} else {
|
||||
logger.e('No default search bang found');
|
||||
}
|
||||
}),
|
||||
PrivateSearchAction((text) async {
|
||||
final defaultSearchBang =
|
||||
await ref.read(kagiSearchBangDataProvider.future);
|
||||
|
||||
if (defaultSearchBang != null) {
|
||||
await ref.read(tabRepositoryProvider.notifier).addTab(
|
||||
url: defaultSearchBang.getUrl(text),
|
||||
private: true,
|
||||
);
|
||||
} else {
|
||||
logger.e('No default search bang found');
|
||||
}
|
||||
}),
|
||||
ShareAction((text) async {
|
||||
await Share.share(text);
|
||||
}),
|
||||
CallAction((text) async {
|
||||
final uri = Uri.tryParse('tel:${text.replaceAll(' ', '')}');
|
||||
|
||||
if (uri != null) {
|
||||
final canLaunch = await canLaunchUrl(uri);
|
||||
if (canLaunch) {
|
||||
await launchUrl(uri);
|
||||
}
|
||||
}
|
||||
}),
|
||||
EmailAction((text) async {
|
||||
final uri = Uri.tryParse('mailto:$text');
|
||||
|
||||
if (uri != null) {
|
||||
final canLaunch = await canLaunchUrl(uri);
|
||||
if (canLaunch) {
|
||||
await launchUrl(uri);
|
||||
}
|
||||
}
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
GeckoEventService eventService(EventServiceRef ref) {
|
||||
final service = GeckoEventService.setUp();
|
||||
@@ -54,6 +120,6 @@ class EngineReadyState extends _$EngineReadyState {
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
TabSession selectedTabSessionNotifier(SelectedTabSessionNotifierRef ref) {
|
||||
Raw<TabSession> selectedTabSessionNotifier(SelectedTabSessionNotifierRef ref) {
|
||||
return ref.watch(tabSessionProvider(null).notifier);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,23 @@ part of 'providers.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$selectionActionServiceHash() =>
|
||||
r'c150f6003dcea80b18fc063dd998ab45ce27d1a1';
|
||||
|
||||
/// See also [selectionActionService].
|
||||
@ProviderFor(selectionActionService)
|
||||
final selectionActionServiceProvider =
|
||||
Provider<GeckoSelectionActionService>.internal(
|
||||
selectionActionService,
|
||||
name: r'selectionActionServiceProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$selectionActionServiceHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef SelectionActionServiceRef = ProviderRef<GeckoSelectionActionService>;
|
||||
String _$eventServiceHash() => r'5aa357fdf0d217677a9a66ecb50417ac18929cad';
|
||||
|
||||
/// See also [eventService].
|
||||
@@ -21,12 +38,12 @@ final eventServiceProvider = Provider<GeckoEventService>.internal(
|
||||
|
||||
typedef EventServiceRef = ProviderRef<GeckoEventService>;
|
||||
String _$selectedTabSessionNotifierHash() =>
|
||||
r'1b0fe1afa87c0b09fc8407ceb91946fffaef5214';
|
||||
r'ea9959e871dd0c3a8b80152eafe726c925094106';
|
||||
|
||||
/// See also [selectedTabSessionNotifier].
|
||||
@ProviderFor(selectedTabSessionNotifier)
|
||||
final selectedTabSessionNotifierProvider =
|
||||
AutoDisposeProvider<TabSession>.internal(
|
||||
AutoDisposeProvider<Raw<TabSession>>.internal(
|
||||
selectedTabSessionNotifier,
|
||||
name: r'selectedTabSessionNotifierProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
@@ -36,7 +53,7 @@ final selectedTabSessionNotifierProvider =
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef SelectedTabSessionNotifierRef = AutoDisposeProviderRef<TabSession>;
|
||||
typedef SelectedTabSessionNotifierRef = AutoDisposeProviderRef<Raw<TabSession>>;
|
||||
String _$engineReadyStateHash() => r'c682333e2e07cf0635aa7ae793a2088ca648c950';
|
||||
|
||||
/// See also [EngineReadyState].
|
||||
|
||||
@@ -607,19 +607,26 @@ class BrowserScreen extends HookConsumerWidget {
|
||||
SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
GeckoView(
|
||||
preInitializationStep: () async {
|
||||
await ref
|
||||
.read(eventServiceProvider)
|
||||
.viewReadyStateEvents
|
||||
.firstWhere((state) => state == true)
|
||||
.timeout(
|
||||
const Duration(seconds: 3),
|
||||
onTimeout: () {
|
||||
logger.e(
|
||||
'Browser fragement not reported ready, trying to intitialize anyways',
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
//Initialize dependencies
|
||||
ref.watch(selectionActionServiceProvider);
|
||||
|
||||
return GeckoView(
|
||||
preInitializationStep: () async {
|
||||
await ref
|
||||
.read(eventServiceProvider)
|
||||
.viewReadyStateEvents
|
||||
.firstWhere((state) => state == true)
|
||||
.timeout(
|
||||
const Duration(seconds: 3),
|
||||
onTimeout: () {
|
||||
logger.e(
|
||||
'Browser fragement not reported ready, trying to intitialize anyways',
|
||||
);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user