imporved app bar; added quick actions;
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||||
|
|
||||||
enum KagiTool {
|
enum KagiTool {
|
||||||
search,
|
search(MdiIcons.searchWeb),
|
||||||
summarizer,
|
summarizer(MdiIcons.text),
|
||||||
//Sort early access features last
|
//Sort early access features last
|
||||||
assistant,
|
assistant(MdiIcons.brain);
|
||||||
|
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
const KagiTool(this.icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AssistantMode {
|
enum AssistantMode {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||||
|
import 'package:fast_equatable/fast_equatable.dart';
|
||||||
|
|
||||||
sealed class Sheet {}
|
// ignore: missing_override_of_must_be_overridden
|
||||||
|
sealed class Sheet with FastEquatable {}
|
||||||
|
|
||||||
class CreateTab extends Sheet {
|
class CreateTab extends Sheet {
|
||||||
final String? content;
|
final String? content;
|
||||||
@@ -9,6 +11,18 @@ class CreateTab extends Sheet {
|
|||||||
bool get hasParameters => content != null || preferredTool != null;
|
bool get hasParameters => content != null || preferredTool != null;
|
||||||
|
|
||||||
CreateTab({this.content, this.preferredTool});
|
CreateTab({this.content, this.preferredTool});
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get cacheHash => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get hashParameters => [content, preferredTool];
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewTabs extends Sheet {}
|
class ViewTabs extends Sheet {
|
||||||
|
@override
|
||||||
|
bool get cacheHash => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get hashParameters => [];
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,11 +33,8 @@ class OverlayDialog extends _$OverlayDialog {
|
|||||||
class BottomSheet extends _$BottomSheet {
|
class BottomSheet extends _$BottomSheet {
|
||||||
@override
|
@override
|
||||||
Sheet? build() {
|
Sheet? build() {
|
||||||
return ref.watch(
|
//Don't use select here because it will only fire on new != previous
|
||||||
createTabStreamProvider.select(
|
return ref.watch(createTabStreamProvider).valueOrNull;
|
||||||
(value) => value.valueOrNull,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void show(Sheet sheet) {
|
void show(Sheet sheet) {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ final overlayDialogProvider =
|
|||||||
);
|
);
|
||||||
|
|
||||||
typedef _$OverlayDialog = AutoDisposeNotifier<Widget?>;
|
typedef _$OverlayDialog = AutoDisposeNotifier<Widget?>;
|
||||||
String _$bottomSheetHash() => r'31108d6d80d5b858024a8a8ae9ebb9c650eabe70';
|
String _$bottomSheetHash() => r'4040ec50a488b4b12123bedceab6d8620e6abe3d';
|
||||||
|
|
||||||
/// See also [BottomSheet].
|
/// See also [BottomSheet].
|
||||||
@ProviderFor(BottomSheet)
|
@ProviderFor(BottomSheet)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:animations/animations.dart';
|
import 'package:animations/animations.dart';
|
||||||
import 'package:bang_navigator/core/routing/routes.dart';
|
import 'package:bang_navigator/core/routing/routes.dart';
|
||||||
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||||
@@ -26,6 +28,7 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
import 'package:speech_to_text_google_dialog/speech_to_text_google_dialog.dart';
|
||||||
|
|
||||||
class KagiScreen extends HookConsumerWidget {
|
class KagiScreen extends HookConsumerWidget {
|
||||||
const KagiScreen({super.key});
|
const KagiScreen({super.key});
|
||||||
@@ -47,6 +50,21 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final quickAction = ref.watch(
|
||||||
|
settingsRepositoryProvider.select(
|
||||||
|
(value) => (value.valueOrNull ?? Settings.withDefaults()).quickAction,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final quickActionVoice = ref.watch(
|
||||||
|
settingsRepositoryProvider.select(
|
||||||
|
(value) => (value.valueOrNull ?? Settings.withDefaults())
|
||||||
|
.quickActionVoiceInput,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final activeWebView = ref.watch(webViewTabControllerProvider);
|
||||||
|
|
||||||
final menuController = useMemoized(() => MenuController());
|
final menuController = useMemoized(() => MenuController());
|
||||||
|
|
||||||
final lastBackButtonPress = useRef<DateTime?>(null);
|
final lastBackButtonPress = useRef<DateTime?>(null);
|
||||||
@@ -54,6 +72,8 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
|
|
||||||
final overlayController = useOverlayPortalController();
|
final overlayController = useOverlayPortalController();
|
||||||
|
|
||||||
|
final activeKagiTool = useValueNotifier<KagiTool?>(null, [displayedSheet]);
|
||||||
|
|
||||||
ref.listen(
|
ref.listen(
|
||||||
overlayDialogProvider,
|
overlayDialogProvider,
|
||||||
(previous, next) {
|
(previous, next) {
|
||||||
@@ -81,23 +101,130 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
child: AppBar(
|
child: AppBar(
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
title: AppBarTitle(
|
titleSpacing: 8.0,
|
||||||
onTap: () {
|
title: (activeWebView != null)
|
||||||
final page = ref.read(webViewTabControllerProvider)?.page.value;
|
? AppBarTitle(
|
||||||
|
activeWebView: activeWebView,
|
||||||
|
onTap: () {
|
||||||
|
final page = activeWebView.page.value;
|
||||||
|
|
||||||
if (page != null) {
|
ref.read(overlayDialogProvider.notifier).show(
|
||||||
ref.read(overlayDialogProvider.notifier).show(
|
WebPageDialog(
|
||||||
WebPageDialog(
|
page: page,
|
||||||
page: page,
|
webViewController: webViewController.value,
|
||||||
webViewController: webViewController.value,
|
onDismiss: ref
|
||||||
onDismiss:
|
.read(overlayDialogProvider.notifier)
|
||||||
ref.read(overlayDialogProvider.notifier).dismiss,
|
.dismiss,
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: HookBuilder(
|
||||||
|
builder: (context) {
|
||||||
|
final activeTool = useListenableSelector(
|
||||||
|
activeKagiTool,
|
||||||
|
() {
|
||||||
|
if (displayedSheet is SharedContentSheet) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return activeKagiTool.value;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
|
||||||
},
|
return Row(
|
||||||
),
|
children: [
|
||||||
|
IconButton(
|
||||||
|
color: (activeTool == KagiTool.search)
|
||||||
|
? Theme.of(context).colorScheme.primary
|
||||||
|
: null,
|
||||||
|
onPressed: () {
|
||||||
|
ref
|
||||||
|
.read(createTabStreamProvider.notifier)
|
||||||
|
.createTab(
|
||||||
|
CreateTab(preferredTool: KagiTool.search),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
icon: Icon(KagiTool.search.icon),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
color: (activeTool == KagiTool.summarizer)
|
||||||
|
? Theme.of(context).colorScheme.primary
|
||||||
|
: null,
|
||||||
|
onPressed: () {
|
||||||
|
ref
|
||||||
|
.read(createTabStreamProvider.notifier)
|
||||||
|
.createTab(
|
||||||
|
CreateTab(preferredTool: KagiTool.summarizer),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
icon: Icon(KagiTool.summarizer.icon),
|
||||||
|
),
|
||||||
|
if (showEarlyAccessFeatures)
|
||||||
|
IconButton(
|
||||||
|
color: (activeTool == KagiTool.assistant)
|
||||||
|
? Theme.of(context).colorScheme.primary
|
||||||
|
: null,
|
||||||
|
onPressed: () {
|
||||||
|
ref
|
||||||
|
.read(createTabStreamProvider.notifier)
|
||||||
|
.createTab(
|
||||||
|
CreateTab(
|
||||||
|
preferredTool: KagiTool.assistant,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
icon: Icon(KagiTool.assistant.icon),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
if (activeWebView != null && quickAction != null)
|
||||||
|
InkWell(
|
||||||
|
onTap: () async {
|
||||||
|
var tab = CreateTab(
|
||||||
|
preferredTool: quickAction,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (quickActionVoice) {
|
||||||
|
final completer = Completer<String>();
|
||||||
|
|
||||||
|
final isServiceAvailable =
|
||||||
|
await SpeechToTextGoogleDialog.getInstance()
|
||||||
|
.showGoogleDialog(
|
||||||
|
onTextReceived: (data) {
|
||||||
|
completer.complete(data.toString());
|
||||||
|
},
|
||||||
|
// locale: "en-US",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isServiceAvailable) {
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showErrorMessage(
|
||||||
|
context,
|
||||||
|
'Service is not available',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tab = CreateTab(
|
||||||
|
preferredTool: quickAction,
|
||||||
|
content: await completer.future,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ref.read(createTabStreamProvider.notifier).createTab(tab);
|
||||||
|
},
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 15.0,
|
||||||
|
horizontal: 8.0,
|
||||||
|
),
|
||||||
|
child: Icon(quickActionVoice ? Icons.mic : quickAction.icon),
|
||||||
|
),
|
||||||
|
),
|
||||||
TabsActionButton(
|
TabsActionButton(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (displayedSheet case ViewTabs()) {
|
if (displayedSheet case ViewTabs()) {
|
||||||
@@ -110,15 +237,22 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
MenuAnchor(
|
MenuAnchor(
|
||||||
controller: menuController,
|
controller: menuController,
|
||||||
builder: (context, controller, child) {
|
builder: (context, controller, child) {
|
||||||
return IconButton(
|
return Padding(
|
||||||
onPressed: () {
|
padding: const EdgeInsets.only(right: 4.0),
|
||||||
if (controller.isOpen) {
|
child: InkWell(
|
||||||
controller.close();
|
onTap: () {
|
||||||
} else {
|
if (controller.isOpen) {
|
||||||
controller.open();
|
controller.close();
|
||||||
}
|
} else {
|
||||||
},
|
controller.open();
|
||||||
icon: const Icon(Icons.more_vert),
|
}
|
||||||
|
},
|
||||||
|
child: const Padding(
|
||||||
|
padding:
|
||||||
|
EdgeInsets.symmetric(vertical: 15.0, horizontal: 8.0),
|
||||||
|
child: Icon(Icons.more_vert),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
menuChildren: [
|
menuChildren: [
|
||||||
@@ -161,7 +295,7 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
CreateTab(preferredTool: KagiTool.assistant),
|
CreateTab(preferredTool: KagiTool.assistant),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
leadingIcon: const Icon(MdiIcons.brain),
|
leadingIcon: Icon(KagiTool.assistant.icon),
|
||||||
child: const Text('Assistant'),
|
child: const Text('Assistant'),
|
||||||
),
|
),
|
||||||
MenuItemButton(
|
MenuItemButton(
|
||||||
@@ -170,7 +304,7 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
CreateTab(preferredTool: KagiTool.summarizer),
|
CreateTab(preferredTool: KagiTool.summarizer),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
leadingIcon: const Icon(MdiIcons.text),
|
leadingIcon: Icon(KagiTool.summarizer.icon),
|
||||||
child: const Text('Summarizer'),
|
child: const Text('Summarizer'),
|
||||||
),
|
),
|
||||||
MenuItemButton(
|
MenuItemButton(
|
||||||
@@ -179,7 +313,7 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
CreateTab(preferredTool: KagiTool.search),
|
CreateTab(preferredTool: KagiTool.search),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
leadingIcon: const Icon(MdiIcons.searchWeb),
|
leadingIcon: Icon(KagiTool.search.icon),
|
||||||
child: const Text('Search'),
|
child: const Text('Search'),
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
@@ -213,10 +347,8 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
child: const Text('Reload'),
|
child: const Text('Reload'),
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
HookConsumer(
|
HookBuilder(
|
||||||
builder: (context, ref, child) {
|
builder: (context) {
|
||||||
final activeWebView =
|
|
||||||
ref.watch(webViewTabControllerProvider);
|
|
||||||
final history = useListenableSelector(
|
final history = useListenableSelector(
|
||||||
activeWebView?.page,
|
activeWebView?.page,
|
||||||
() =>
|
() =>
|
||||||
@@ -272,7 +404,6 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
child: HookConsumer(
|
child: HookConsumer(
|
||||||
builder: (context, ref, child) {
|
builder: (context, ref, child) {
|
||||||
final webViews = ref.watch(webViewRepositoryProvider);
|
final webViews = ref.watch(webViewRepositoryProvider);
|
||||||
final activeWebView = ref.watch(webViewTabControllerProvider);
|
|
||||||
useListenableCallback(activeWebView?.page, () {
|
useListenableCallback(activeWebView?.page, () {
|
||||||
webViewController.value = activeWebView?.page.value.controller;
|
webViewController.value = activeWebView?.page.value.controller;
|
||||||
});
|
});
|
||||||
@@ -391,7 +522,7 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
},
|
},
|
||||||
child: switch (displayedSheet) {
|
child: switch (displayedSheet) {
|
||||||
ViewTabs() => DraggableScrollableSheet(
|
ViewTabs() => DraggableScrollableSheet(
|
||||||
key: ObjectKey(displayedSheet),
|
key: ValueKey(displayedSheet),
|
||||||
expand: false,
|
expand: false,
|
||||||
minChildSize: 0.1,
|
minChildSize: 0.1,
|
||||||
maxChildSize: _realtiveSafeArea(context),
|
maxChildSize: _realtiveSafeArea(context),
|
||||||
@@ -411,7 +542,7 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
final CreateTab parameter => DraggableScrollableSheet(
|
final CreateTab parameter => DraggableScrollableSheet(
|
||||||
key: ObjectKey(displayedSheet),
|
key: ValueKey(displayedSheet),
|
||||||
expand: false,
|
expand: false,
|
||||||
initialChildSize: 0.8,
|
initialChildSize: 0.8,
|
||||||
minChildSize: 0.1,
|
minChildSize: 0.1,
|
||||||
@@ -420,7 +551,7 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
child: SharedContentSheet(
|
child: SharedContentSheet(
|
||||||
key: ObjectKey(parameter),
|
key: ValueKey(parameter),
|
||||||
parameter: parameter,
|
parameter: parameter,
|
||||||
onSubmit: (url) async {
|
onSubmit: (url) async {
|
||||||
await ref
|
await ref
|
||||||
@@ -429,6 +560,9 @@ class KagiScreen extends HookConsumerWidget {
|
|||||||
|
|
||||||
ref.read(bottomSheetProvider.notifier).dismiss();
|
ref.read(bottomSheetProvider.notifier).dismiss();
|
||||||
},
|
},
|
||||||
|
onActiveToolChanged: (tool) {
|
||||||
|
activeKagiTool.value = tool;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import 'package:bang_navigator/features/web_view/domain/entities/web_view_page.dart';
|
import 'package:bang_navigator/features/web_view/domain/entities/web_view_page.dart';
|
||||||
import 'package:bang_navigator/features/web_view/domain/repositories/web_view.dart';
|
|
||||||
import 'package:bang_navigator/features/web_view/presentation/widgets/favicon.dart';
|
import 'package:bang_navigator/features/web_view/presentation/widgets/favicon.dart';
|
||||||
|
import 'package:bang_navigator/features/web_view/presentation/widgets/web_view.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
||||||
import 'package:text_scroll/text_scroll.dart';
|
import 'package:text_scroll/text_scroll.dart';
|
||||||
|
|
||||||
class AppBarTitle extends HookConsumerWidget {
|
class AppBarTitle extends HookWidget {
|
||||||
|
final WebView activeWebView;
|
||||||
|
|
||||||
final void Function()? onTap;
|
final void Function()? onTap;
|
||||||
|
|
||||||
const AppBarTitle({this.onTap, super.key});
|
const AppBarTitle({required this.activeWebView, this.onTap, super.key});
|
||||||
|
|
||||||
Icon _securityStatusIcon(BuildContext context, WebViewPage page) {
|
Icon _securityStatusIcon(BuildContext context, WebViewPage page) {
|
||||||
if (page.url.isScheme('http')) {
|
if (page.url.isScheme('http')) {
|
||||||
@@ -34,12 +35,7 @@ class AppBarTitle extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context) {
|
||||||
final activeWebView = ref.watch(webViewTabControllerProvider);
|
|
||||||
if (activeWebView == null) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
|
|
||||||
final page = useValueListenable(activeWebView.page);
|
final page = useValueListenable(activeWebView.page);
|
||||||
|
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import 'package:bang_navigator/core/routing/routes.dart';
|
import 'package:bang_navigator/core/routing/routes.dart';
|
||||||
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
|
||||||
import 'package:bang_navigator/features/search_browser/domain/entities/sheet.dart';
|
|
||||||
import 'package:bang_navigator/features/search_browser/domain/services/create_tab.dart';
|
|
||||||
import 'package:bang_navigator/features/search_browser/presentation/widgets/error_container.dart';
|
import 'package:bang_navigator/features/search_browser/presentation/widgets/error_container.dart';
|
||||||
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
|
||||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
@@ -21,16 +16,9 @@ class LandingAction extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final showEarlyAccessFeatures = ref.watch(
|
|
||||||
settingsRepositoryProvider.select(
|
|
||||||
(value) => (value.valueOrNull ?? Settings.withDefaults())
|
|
||||||
.showEarlyAccessFeatures,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: sessionTokenAvailable,
|
visible: !sessionTokenAvailable,
|
||||||
replacement: ErrorContainer(
|
child: ErrorContainer(
|
||||||
content: Markdown(
|
content: Markdown(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
onTapLink: (text, href, title) async {
|
onTapLink: (text, href, title) async {
|
||||||
@@ -43,40 +31,6 @@ class LandingAction extends HookConsumerWidget {
|
|||||||
"You must provide a valid session in order to use Kagi's features.",
|
"You must provide a valid session in order to use Kagi's features.",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Wrap(
|
|
||||||
spacing: 8.0,
|
|
||||||
alignment: WrapAlignment.spaceEvenly,
|
|
||||||
children: [
|
|
||||||
OutlinedButton.icon(
|
|
||||||
onPressed: () {
|
|
||||||
ref.read(createTabStreamProvider.notifier).createTab(
|
|
||||||
CreateTab(preferredTool: KagiTool.search),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
icon: const Icon(MdiIcons.searchWeb),
|
|
||||||
label: const Text('Search'),
|
|
||||||
),
|
|
||||||
OutlinedButton.icon(
|
|
||||||
onPressed: () {
|
|
||||||
ref.read(createTabStreamProvider.notifier).createTab(
|
|
||||||
CreateTab(preferredTool: KagiTool.summarizer),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
icon: const Icon(MdiIcons.text),
|
|
||||||
label: const Text('Summarizer'),
|
|
||||||
),
|
|
||||||
if (showEarlyAccessFeatures)
|
|
||||||
OutlinedButton.icon(
|
|
||||||
onPressed: () {
|
|
||||||
ref.read(createTabStreamProvider.notifier).createTab(
|
|
||||||
CreateTab(preferredTool: KagiTool.assistant),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
icon: const Icon(MdiIcons.brain),
|
|
||||||
label: const Text('Assistant'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-11
@@ -10,7 +10,6 @@ import 'package:bang_navigator/presentation/hooks/sync_page_tab.dart';
|
|||||||
import 'package:expandable_page_view/expandable_page_view.dart';
|
import 'package:expandable_page_view/expandable_page_view.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.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:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
typedef OnSubmitUri = void Function(Uri url);
|
typedef OnSubmitUri = void Function(Uri url);
|
||||||
@@ -18,10 +17,12 @@ typedef OnSubmitUri = void Function(Uri url);
|
|||||||
class SharedContentSheet extends HookConsumerWidget {
|
class SharedContentSheet extends HookConsumerWidget {
|
||||||
final CreateTab parameter;
|
final CreateTab parameter;
|
||||||
final OnSubmitUri onSubmit;
|
final OnSubmitUri onSubmit;
|
||||||
|
final void Function(KagiTool tool)? onActiveToolChanged;
|
||||||
|
|
||||||
const SharedContentSheet({
|
const SharedContentSheet({
|
||||||
required this.parameter,
|
required this.parameter,
|
||||||
required this.onSubmit,
|
required this.onSubmit,
|
||||||
|
this.onActiveToolChanged,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
@override
|
@override
|
||||||
@@ -37,11 +38,12 @@ class SharedContentSheet extends HookConsumerWidget {
|
|||||||
() => (parameter.content != null)
|
() => (parameter.content != null)
|
||||||
? SharedContent.parse(parameter.content!)
|
? SharedContent.parse(parameter.content!)
|
||||||
: null,
|
: null,
|
||||||
|
[parameter],
|
||||||
);
|
);
|
||||||
|
|
||||||
final tabController = useTabController(
|
final initialIndex = useMemoized(
|
||||||
initialLength: KagiTool.values.length - (showEarlyAccessFeatures ? 0 : 1),
|
() =>
|
||||||
initialIndex: parameter.preferredTool?.index ??
|
parameter.preferredTool?.index ??
|
||||||
switch (sharedContent) {
|
switch (sharedContent) {
|
||||||
SharedText(text: final text) =>
|
SharedText(text: final text) =>
|
||||||
(showEarlyAccessFeatures && text.length > 25)
|
(showEarlyAccessFeatures && text.length > 25)
|
||||||
@@ -52,10 +54,32 @@ class SharedContentSheet extends HookConsumerWidget {
|
|||||||
? KagiTool.assistant.index
|
? KagiTool.assistant.index
|
||||||
: KagiTool.search.index,
|
: KagiTool.search.index,
|
||||||
},
|
},
|
||||||
|
[sharedContent],
|
||||||
|
);
|
||||||
|
|
||||||
|
final tabController = useTabController(
|
||||||
|
initialLength: KagiTool.values.length - (showEarlyAccessFeatures ? 0 : 1),
|
||||||
|
initialIndex: initialIndex,
|
||||||
);
|
);
|
||||||
final pageController = usePageController(initialPage: tabController.index);
|
final pageController = usePageController(initialPage: tabController.index);
|
||||||
|
|
||||||
useSyncPageWithTab(tabController, pageController);
|
useSyncPageWithTab(
|
||||||
|
tabController,
|
||||||
|
pageController,
|
||||||
|
onIndexChanged: (index) {
|
||||||
|
onActiveToolChanged?.call(KagiTool.values[index]);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
onActiveToolChanged?.call(KagiTool.values[initialIndex]);
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
[initialIndex],
|
||||||
|
);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -63,17 +87,17 @@ class SharedContentSheet extends HookConsumerWidget {
|
|||||||
TabBar(
|
TabBar(
|
||||||
controller: tabController,
|
controller: tabController,
|
||||||
tabs: [
|
tabs: [
|
||||||
const Tab(
|
Tab(
|
||||||
icon: Icon(MdiIcons.searchWeb),
|
icon: Icon(KagiTool.search.icon),
|
||||||
text: 'Search',
|
text: 'Search',
|
||||||
),
|
),
|
||||||
const Tab(
|
Tab(
|
||||||
icon: Icon(MdiIcons.text),
|
icon: Icon(KagiTool.summarizer.icon),
|
||||||
text: 'Summarize',
|
text: 'Summarize',
|
||||||
),
|
),
|
||||||
if (showEarlyAccessFeatures)
|
if (showEarlyAccessFeatures)
|
||||||
const Tab(
|
Tab(
|
||||||
icon: Icon(MdiIcons.brain),
|
icon: Icon(KagiTool.assistant.icon),
|
||||||
text: 'Assistant',
|
text: 'Assistant',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -15,11 +15,9 @@ class TabsActionButton extends HookConsumerWidget {
|
|||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.symmetric(
|
||||||
left: 10.0,
|
horizontal: 8.0,
|
||||||
top: 15.0,
|
vertical: 15.0,
|
||||||
right: 10.0,
|
|
||||||
bottom: 15.0,
|
|
||||||
),
|
),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:bang_navigator/features/content_block/data/models/host.dart';
|
import 'package:bang_navigator/features/content_block/data/models/host.dart';
|
||||||
|
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||||
import 'package:fast_equatable/fast_equatable.dart';
|
import 'package:fast_equatable/fast_equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -16,6 +17,8 @@ class Settings with FastEquatable {
|
|||||||
final bool blockHttpProtocol;
|
final bool blockHttpProtocol;
|
||||||
final Set<HostSource> enableHostList;
|
final Set<HostSource> enableHostList;
|
||||||
final ThemeMode themeMode;
|
final ThemeMode themeMode;
|
||||||
|
final KagiTool? quickAction;
|
||||||
|
final bool quickActionVoiceInput;
|
||||||
|
|
||||||
Settings({
|
Settings({
|
||||||
required this.kagiSession,
|
required this.kagiSession,
|
||||||
@@ -27,6 +30,8 @@ class Settings with FastEquatable {
|
|||||||
required this.blockHttpProtocol,
|
required this.blockHttpProtocol,
|
||||||
required this.enableHostList,
|
required this.enableHostList,
|
||||||
required this.themeMode,
|
required this.themeMode,
|
||||||
|
required this.quickAction,
|
||||||
|
required this.quickActionVoiceInput,
|
||||||
});
|
});
|
||||||
|
|
||||||
Settings.withDefaults({
|
Settings.withDefaults({
|
||||||
@@ -39,6 +44,8 @@ class Settings with FastEquatable {
|
|||||||
bool? blockHttpProtocol,
|
bool? blockHttpProtocol,
|
||||||
Set<HostSource>? enableHostList,
|
Set<HostSource>? enableHostList,
|
||||||
ThemeMode? themeMode,
|
ThemeMode? themeMode,
|
||||||
|
this.quickAction,
|
||||||
|
bool? quickActionVoiceInput,
|
||||||
}) : showEarlyAccessFeatures = showEarlyAccessFeatures ?? true,
|
}) : showEarlyAccessFeatures = showEarlyAccessFeatures ?? true,
|
||||||
incognitoMode = incognitoMode ?? true,
|
incognitoMode = incognitoMode ?? true,
|
||||||
enableJavascript = enableJavascript ?? true,
|
enableJavascript = enableJavascript ?? true,
|
||||||
@@ -46,7 +53,8 @@ class Settings with FastEquatable {
|
|||||||
enableContentBlocking = enableContentBlocking ?? true,
|
enableContentBlocking = enableContentBlocking ?? true,
|
||||||
blockHttpProtocol = blockHttpProtocol ?? false,
|
blockHttpProtocol = blockHttpProtocol ?? false,
|
||||||
enableHostList = enableHostList ?? {HostSource.stevenBlackUnified},
|
enableHostList = enableHostList ?? {HostSource.stevenBlackUnified},
|
||||||
themeMode = themeMode ?? ThemeMode.dark;
|
themeMode = themeMode ?? ThemeMode.dark,
|
||||||
|
quickActionVoiceInput = quickActionVoiceInput ?? false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get cacheHash => true;
|
bool get cacheHash => true;
|
||||||
@@ -62,5 +70,7 @@ class Settings with FastEquatable {
|
|||||||
blockHttpProtocol,
|
blockHttpProtocol,
|
||||||
enableHostList,
|
enableHostList,
|
||||||
themeMode,
|
themeMode,
|
||||||
|
quickAction,
|
||||||
|
quickActionVoiceInput,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ abstract class _$SettingsCWProxy {
|
|||||||
|
|
||||||
Settings themeMode(ThemeMode themeMode);
|
Settings themeMode(ThemeMode themeMode);
|
||||||
|
|
||||||
|
Settings quickAction(KagiTool? quickAction);
|
||||||
|
|
||||||
|
Settings quickActionVoiceInput(bool quickActionVoiceInput);
|
||||||
|
|
||||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||||
///
|
///
|
||||||
/// Usage
|
/// Usage
|
||||||
@@ -41,6 +45,8 @@ abstract class _$SettingsCWProxy {
|
|||||||
bool? blockHttpProtocol,
|
bool? blockHttpProtocol,
|
||||||
Set<HostSource>? enableHostList,
|
Set<HostSource>? enableHostList,
|
||||||
ThemeMode? themeMode,
|
ThemeMode? themeMode,
|
||||||
|
KagiTool? quickAction,
|
||||||
|
bool? quickActionVoiceInput,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +90,13 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
|||||||
@override
|
@override
|
||||||
Settings themeMode(ThemeMode themeMode) => this(themeMode: themeMode);
|
Settings themeMode(ThemeMode themeMode) => this(themeMode: themeMode);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Settings quickAction(KagiTool? quickAction) => this(quickAction: quickAction);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Settings quickActionVoiceInput(bool quickActionVoiceInput) =>
|
||||||
|
this(quickActionVoiceInput: quickActionVoiceInput);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
||||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||||
@@ -102,6 +115,8 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
|||||||
Object? blockHttpProtocol = const $CopyWithPlaceholder(),
|
Object? blockHttpProtocol = const $CopyWithPlaceholder(),
|
||||||
Object? enableHostList = const $CopyWithPlaceholder(),
|
Object? enableHostList = const $CopyWithPlaceholder(),
|
||||||
Object? themeMode = const $CopyWithPlaceholder(),
|
Object? themeMode = const $CopyWithPlaceholder(),
|
||||||
|
Object? quickAction = const $CopyWithPlaceholder(),
|
||||||
|
Object? quickActionVoiceInput = const $CopyWithPlaceholder(),
|
||||||
}) {
|
}) {
|
||||||
return Settings(
|
return Settings(
|
||||||
kagiSession: kagiSession == const $CopyWithPlaceholder()
|
kagiSession: kagiSession == const $CopyWithPlaceholder()
|
||||||
@@ -149,6 +164,16 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
|||||||
? _value.themeMode
|
? _value.themeMode
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: themeMode as ThemeMode,
|
: themeMode as ThemeMode,
|
||||||
|
quickAction: quickAction == const $CopyWithPlaceholder()
|
||||||
|
? _value.quickAction
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: quickAction as KagiTool?,
|
||||||
|
quickActionVoiceInput:
|
||||||
|
quickActionVoiceInput == const $CopyWithPlaceholder() ||
|
||||||
|
quickActionVoiceInput == null
|
||||||
|
? _value.quickActionVoiceInput
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: quickActionVoiceInput as bool,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:bang_navigator/features/content_block/data/models/host.dart';
|
|
||||||
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
||||||
|
import 'package:bang_navigator/features/settings/utils/preference_parser.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@@ -10,34 +9,26 @@ part 'settings_repository.g.dart';
|
|||||||
|
|
||||||
typedef UpdateSettingsFunc = Settings Function(Settings currentSettings);
|
typedef UpdateSettingsFunc = Settings Function(Settings currentSettings);
|
||||||
|
|
||||||
Set<HostSource>? _parseHostSources(List<String>? input) => input
|
enum _StorageKeys {
|
||||||
?.map(
|
kagiSession('kagi_session'),
|
||||||
(list) =>
|
showEarlyAccessFeatures('show_early_access_features'),
|
||||||
HostSource.values.firstWhereOrNull((source) => source.name == list),
|
incognito('enabe_incognito'),
|
||||||
)
|
javascript('enable_js'),
|
||||||
.whereNotNull()
|
launchExternal('enable_launch_external'),
|
||||||
.toSet();
|
contentBlocking('enable_content_blocking'),
|
||||||
|
blockHttpProtocol('block_http'),
|
||||||
|
enableHostList('enable_host_lists'),
|
||||||
|
themeMode('theme_mode'),
|
||||||
|
quickAction('enable_quick_action'),
|
||||||
|
quickActionVoiceInput('enable_quick_action_voice_input');
|
||||||
|
|
||||||
ThemeMode? _parseThemeMode(int? index) {
|
final String key;
|
||||||
if (index != null && index < ThemeMode.values.length) {
|
|
||||||
return ThemeMode.values[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
const _StorageKeys(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Riverpod(keepAlive: true)
|
@Riverpod(keepAlive: true)
|
||||||
class SettingsRepository extends _$SettingsRepository {
|
class SettingsRepository extends _$SettingsRepository {
|
||||||
static const _sessionStorageKey = 'b4ng_kagi_session';
|
|
||||||
static const _showEarlyAccessFeaturesKey = 'b4ng_show_early_access';
|
|
||||||
static const _incognitoStorageKey = 'b4ng_settings_incognito';
|
|
||||||
static const _javascriptStorageKey = 'b4ng_settings_js';
|
|
||||||
static const _launchExternalStorageKey = 'b4ng_settings_launch_external';
|
|
||||||
static const _contentBlockingStorageKey = 'b4ng_settings_content_blocking';
|
|
||||||
static const _blockHttpProtocolStorageKey = 'b4ng_settings_block_http';
|
|
||||||
static const _enableHostListStorageKey = 'b4ng_settings_host_lists';
|
|
||||||
static const _themeModeStorageKey = 'b4ng_settings_theme_mode';
|
|
||||||
|
|
||||||
final FlutterSecureStorage _flutterSecureStorage;
|
final FlutterSecureStorage _flutterSecureStorage;
|
||||||
final Future<SharedPreferences> _sharedPreferences;
|
final Future<SharedPreferences> _sharedPreferences;
|
||||||
|
|
||||||
@@ -53,7 +44,7 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
if (oldSettings != newSettings) {
|
if (oldSettings != newSettings) {
|
||||||
if (oldSettings.kagiSession != newSettings.kagiSession) {
|
if (oldSettings.kagiSession != newSettings.kagiSession) {
|
||||||
await _flutterSecureStorage.write(
|
await _flutterSecureStorage.write(
|
||||||
key: _sessionStorageKey,
|
key: _StorageKeys.kagiSession.key,
|
||||||
value: (newSettings.kagiSession?.isNotEmpty ?? false)
|
value: (newSettings.kagiSession?.isNotEmpty ?? false)
|
||||||
? newSettings.kagiSession
|
? newSettings.kagiSession
|
||||||
: null,
|
: null,
|
||||||
@@ -63,28 +54,28 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
if (newSettings.showEarlyAccessFeatures !=
|
if (newSettings.showEarlyAccessFeatures !=
|
||||||
oldSettings.showEarlyAccessFeatures) {
|
oldSettings.showEarlyAccessFeatures) {
|
||||||
await sharedPreferences.setBool(
|
await sharedPreferences.setBool(
|
||||||
_showEarlyAccessFeaturesKey,
|
_StorageKeys.showEarlyAccessFeatures.key,
|
||||||
newSettings.showEarlyAccessFeatures,
|
newSettings.showEarlyAccessFeatures,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newSettings.incognitoMode != oldSettings.incognitoMode) {
|
if (newSettings.incognitoMode != oldSettings.incognitoMode) {
|
||||||
await sharedPreferences.setBool(
|
await sharedPreferences.setBool(
|
||||||
_incognitoStorageKey,
|
_StorageKeys.incognito.key,
|
||||||
newSettings.incognitoMode,
|
newSettings.incognitoMode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newSettings.enableJavascript != oldSettings.enableJavascript) {
|
if (newSettings.enableJavascript != oldSettings.enableJavascript) {
|
||||||
await sharedPreferences.setBool(
|
await sharedPreferences.setBool(
|
||||||
_javascriptStorageKey,
|
_StorageKeys.javascript.key,
|
||||||
newSettings.enableJavascript,
|
newSettings.enableJavascript,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newSettings.launchUrlExternal != oldSettings.launchUrlExternal) {
|
if (newSettings.launchUrlExternal != oldSettings.launchUrlExternal) {
|
||||||
await sharedPreferences.setBool(
|
await sharedPreferences.setBool(
|
||||||
_launchExternalStorageKey,
|
_StorageKeys.launchExternal.key,
|
||||||
newSettings.launchUrlExternal,
|
newSettings.launchUrlExternal,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -92,14 +83,14 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
if (newSettings.enableContentBlocking !=
|
if (newSettings.enableContentBlocking !=
|
||||||
oldSettings.enableContentBlocking) {
|
oldSettings.enableContentBlocking) {
|
||||||
await sharedPreferences.setBool(
|
await sharedPreferences.setBool(
|
||||||
_contentBlockingStorageKey,
|
_StorageKeys.contentBlocking.key,
|
||||||
newSettings.enableContentBlocking,
|
newSettings.enableContentBlocking,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newSettings.blockHttpProtocol != oldSettings.blockHttpProtocol) {
|
if (newSettings.blockHttpProtocol != oldSettings.blockHttpProtocol) {
|
||||||
await sharedPreferences.setBool(
|
await sharedPreferences.setBool(
|
||||||
_blockHttpProtocolStorageKey,
|
_StorageKeys.blockHttpProtocol.key,
|
||||||
newSettings.blockHttpProtocol,
|
newSettings.blockHttpProtocol,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -109,18 +100,38 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
oldSettings.enableHostList,
|
oldSettings.enableHostList,
|
||||||
)) {
|
)) {
|
||||||
await sharedPreferences.setStringList(
|
await sharedPreferences.setStringList(
|
||||||
_enableHostListStorageKey,
|
_StorageKeys.enableHostList.key,
|
||||||
newSettings.enableHostList.map((list) => list.name).toList(),
|
newSettings.enableHostList.map((list) => list.name).toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newSettings.themeMode != oldSettings.themeMode) {
|
if (newSettings.themeMode != oldSettings.themeMode) {
|
||||||
await sharedPreferences.setInt(
|
await sharedPreferences.setInt(
|
||||||
_themeModeStorageKey,
|
_StorageKeys.themeMode.key,
|
||||||
newSettings.themeMode.index,
|
newSettings.themeMode.index,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newSettings.quickAction != oldSettings.quickAction) {
|
||||||
|
final index = newSettings.quickAction?.index;
|
||||||
|
if (index != null) {
|
||||||
|
await sharedPreferences.setInt(
|
||||||
|
_StorageKeys.quickAction.key,
|
||||||
|
index,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await sharedPreferences.remove(_StorageKeys.quickAction.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newSettings.quickActionVoiceInput !=
|
||||||
|
oldSettings.quickActionVoiceInput) {
|
||||||
|
await sharedPreferences.setBool(
|
||||||
|
_StorageKeys.quickActionVoiceInput.key,
|
||||||
|
newSettings.quickActionVoiceInput,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ref.invalidateSelf();
|
ref.invalidateSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,21 +141,27 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
final sharedPreferences = await _sharedPreferences;
|
final sharedPreferences = await _sharedPreferences;
|
||||||
|
|
||||||
return Settings.withDefaults(
|
return Settings.withDefaults(
|
||||||
kagiSession: await _flutterSecureStorage.read(key: _sessionStorageKey),
|
kagiSession:
|
||||||
|
await _flutterSecureStorage.read(key: _StorageKeys.kagiSession.key),
|
||||||
showEarlyAccessFeatures:
|
showEarlyAccessFeatures:
|
||||||
sharedPreferences.getBool(_showEarlyAccessFeaturesKey),
|
sharedPreferences.getBool(_StorageKeys.showEarlyAccessFeatures.key),
|
||||||
incognitoMode: sharedPreferences.getBool(_incognitoStorageKey),
|
incognitoMode: sharedPreferences.getBool(_StorageKeys.incognito.key),
|
||||||
enableJavascript: sharedPreferences.getBool(_javascriptStorageKey),
|
enableJavascript: sharedPreferences.getBool(_StorageKeys.javascript.key),
|
||||||
launchUrlExternal: sharedPreferences.getBool(_launchExternalStorageKey),
|
launchUrlExternal:
|
||||||
|
sharedPreferences.getBool(_StorageKeys.launchExternal.key),
|
||||||
enableContentBlocking:
|
enableContentBlocking:
|
||||||
sharedPreferences.getBool(_contentBlockingStorageKey),
|
sharedPreferences.getBool(_StorageKeys.contentBlocking.key),
|
||||||
blockHttpProtocol:
|
blockHttpProtocol:
|
||||||
sharedPreferences.getBool(_blockHttpProtocolStorageKey),
|
sharedPreferences.getBool(_StorageKeys.blockHttpProtocol.key),
|
||||||
enableHostList: _parseHostSources(
|
enableHostList: parseHostSources(
|
||||||
sharedPreferences.getStringList(_enableHostListStorageKey),
|
sharedPreferences.getStringList(_StorageKeys.enableHostList.key),
|
||||||
),
|
),
|
||||||
themeMode:
|
themeMode:
|
||||||
_parseThemeMode(sharedPreferences.getInt(_themeModeStorageKey)),
|
parseThemeMode(sharedPreferences.getInt(_StorageKeys.themeMode.key)),
|
||||||
|
quickAction:
|
||||||
|
parseKagiTool(sharedPreferences.getInt(_StorageKeys.quickAction.key)),
|
||||||
|
quickActionVoiceInput:
|
||||||
|
sharedPreferences.getBool(_StorageKeys.quickActionVoiceInput.key),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ part of 'settings_repository.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$settingsRepositoryHash() =>
|
String _$settingsRepositoryHash() =>
|
||||||
r'ac2b1ecddd82e45e901425e9e5fcb9b4b61855fa';
|
r'34d3c771d6ebb17cb9aa41211e035b4d1cbf2183';
|
||||||
|
|
||||||
/// See also [SettingsRepository].
|
/// See also [SettingsRepository].
|
||||||
@ProviderFor(SettingsRepository)
|
@ProviderFor(SettingsRepository)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:bang_navigator/features/bangs/data/models/bang.dart';
|
|||||||
import 'package:bang_navigator/features/bangs/domain/providers.dart';
|
import 'package:bang_navigator/features/bangs/domain/providers.dart';
|
||||||
import 'package:bang_navigator/features/bangs/domain/repositories/data.dart';
|
import 'package:bang_navigator/features/bangs/domain/repositories/data.dart';
|
||||||
import 'package:bang_navigator/features/content_block/data/models/host.dart';
|
import 'package:bang_navigator/features/content_block/data/models/host.dart';
|
||||||
|
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||||
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
||||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||||
import 'package:bang_navigator/features/settings/presentation/controllers/save_settings.dart';
|
import 'package:bang_navigator/features/settings/presentation/controllers/save_settings.dart';
|
||||||
@@ -243,6 +244,76 @@ class SettingsScreen extends HookConsumerWidget {
|
|||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 16,
|
height: 16,
|
||||||
),
|
),
|
||||||
|
_buildSection(theme, 'Appearance'),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const CustomListTile(
|
||||||
|
title: 'Quick Action',
|
||||||
|
subtitle:
|
||||||
|
'Appears in the browser app bar between website title and tab count.',
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
child: Center(
|
||||||
|
child: SegmentedButton<KagiTool>(
|
||||||
|
emptySelectionAllowed: true,
|
||||||
|
segments: [
|
||||||
|
ButtonSegment(
|
||||||
|
value: KagiTool.search,
|
||||||
|
icon: Icon(KagiTool.search.icon),
|
||||||
|
label: const Text('Search'),
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: KagiTool.summarizer,
|
||||||
|
icon: Icon(KagiTool.summarizer.icon),
|
||||||
|
label: const Text('Summarizer'),
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: KagiTool.assistant,
|
||||||
|
icon: Icon(KagiTool.assistant.icon),
|
||||||
|
label: const Text('Assistant'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
selected: {
|
||||||
|
if (settings.quickAction != null) settings.quickAction!,
|
||||||
|
},
|
||||||
|
onSelectionChanged: (value) async {
|
||||||
|
await ref
|
||||||
|
.read(saveSettingsControllerProvider.notifier)
|
||||||
|
.save(
|
||||||
|
(currentSettings) =>
|
||||||
|
currentSettings.copyWith.quickAction(
|
||||||
|
value.isNotEmpty ? value.first : null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SwitchListTile.adaptive(
|
||||||
|
title: const Text('Quick Action - STT'),
|
||||||
|
subtitle: const Text(
|
||||||
|
'Quick option will open with speech-to-text input.',
|
||||||
|
),
|
||||||
|
value: settings.quickActionVoiceInput,
|
||||||
|
onChanged: (settings.quickAction != null)
|
||||||
|
? (value) async {
|
||||||
|
await ref
|
||||||
|
.read(saveSettingsControllerProvider.notifier)
|
||||||
|
.save(
|
||||||
|
(currentSettings) => currentSettings.copyWith
|
||||||
|
.quickActionVoiceInput(value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
),
|
||||||
_buildSection(theme, 'Content Blocking'),
|
_buildSection(theme, 'Content Blocking'),
|
||||||
SwitchListTile.adaptive(
|
SwitchListTile.adaptive(
|
||||||
title: const Text('Enable Content Blocking'),
|
title: const Text('Enable Content Blocking'),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class CustomListTile extends StatelessWidget {
|
|||||||
final Widget? content;
|
final Widget? content;
|
||||||
|
|
||||||
final Widget? prefix;
|
final Widget? prefix;
|
||||||
final Widget suffix;
|
final Widget? suffix;
|
||||||
|
|
||||||
const CustomListTile({
|
const CustomListTile({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -16,13 +16,15 @@ class CustomListTile extends StatelessWidget {
|
|||||||
required this.subtitle,
|
required this.subtitle,
|
||||||
this.content,
|
this.content,
|
||||||
this.prefix,
|
this.prefix,
|
||||||
required this.suffix,
|
this.suffix,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
final subtitleTextTheme = theme.textTheme.bodyMedium!
|
||||||
|
.copyWith(color: theme.colorScheme.onSurfaceVariant);
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
||||||
@@ -44,7 +46,7 @@ class CustomListTile extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
subtitle,
|
subtitle,
|
||||||
style: enabled
|
style: enabled
|
||||||
? theme.textTheme.bodyMedium
|
? subtitleTextTheme
|
||||||
: theme.textTheme.bodyMedium
|
: theme.textTheme.bodyMedium
|
||||||
?.copyWith(color: theme.disabledColor),
|
?.copyWith(color: theme.disabledColor),
|
||||||
),
|
),
|
||||||
@@ -52,7 +54,7 @@ class CustomListTile extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
suffix,
|
if (suffix != null) suffix!,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import 'package:bang_navigator/features/content_block/data/models/host.dart';
|
||||||
|
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
Set<HostSource>? parseHostSources(List<String>? input) => input
|
||||||
|
?.map(
|
||||||
|
(list) =>
|
||||||
|
HostSource.values.firstWhereOrNull((source) => source.name == list),
|
||||||
|
)
|
||||||
|
.whereNotNull()
|
||||||
|
.toSet();
|
||||||
|
|
||||||
|
ThemeMode? parseThemeMode(int? index) {
|
||||||
|
if (index != null && index < ThemeMode.values.length) {
|
||||||
|
return ThemeMode.values[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
KagiTool? parseKagiTool(int? index) {
|
||||||
|
if (index != null && index < ThemeMode.values.length) {
|
||||||
|
return KagiTool.values[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -227,7 +227,7 @@ class WebPageDialog extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(MdiIcons.text),
|
leading: Icon(KagiTool.summarizer.icon),
|
||||||
title: const Text('Summarize'),
|
title: const Text('Summarize'),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final url = uri_builder.summarizerUri(
|
final url = uri_builder.summarizerUri(
|
||||||
|
|||||||
Reference in New Issue
Block a user