implemented chat archive
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:universal_io/io.dart';
|
||||
import 'package:watcher/watcher.dart';
|
||||
|
||||
part 'chat_archive_file.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class ChatArchiveFileRepository extends _$ChatArchiveFileRepository {
|
||||
final Future<Directory> _archiveDirectoryFuture;
|
||||
|
||||
ChatArchiveFileRepository()
|
||||
: _archiveDirectoryFuture =
|
||||
path_provider.getApplicationDocumentsDirectory().then(
|
||||
(documentDirectory) => Directory(
|
||||
path.join(documentDirectory.path, 'archive', 'chat'),
|
||||
).create(recursive: true),
|
||||
);
|
||||
|
||||
Future<List<FileSystemEntity>> list() {
|
||||
return _archiveDirectoryFuture.then((value) => value.list().toList());
|
||||
}
|
||||
|
||||
Future<void> write(String fileName, String contents) async {
|
||||
final directory = await _archiveDirectoryFuture;
|
||||
final file = File(path.join(directory.path, fileName));
|
||||
|
||||
await file.writeAsString(contents, flush: true);
|
||||
}
|
||||
|
||||
Future<String?> read(String fileName) async {
|
||||
final directory = await _archiveDirectoryFuture;
|
||||
final file = File(path.join(directory.path, fileName));
|
||||
|
||||
if (!await file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return file.readAsString();
|
||||
}
|
||||
|
||||
Future<void> delete(String fileName) async {
|
||||
final directory = await _archiveDirectoryFuture;
|
||||
final file = File(path.join(directory.path, fileName));
|
||||
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Raw<Stream<WatchEvent>> build() async* {
|
||||
final watcher = DirectoryWatcher(
|
||||
await _archiveDirectoryFuture
|
||||
.then((archiveDirectory) => archiveDirectory.absolute.path),
|
||||
);
|
||||
|
||||
yield* watcher.events;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'chat_archive_file.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$chatArchiveFileRepositoryHash() =>
|
||||
r'50268506cf0c23ba1724ece6c9f44cb87be6299f';
|
||||
|
||||
/// See also [ChatArchiveFileRepository].
|
||||
@ProviderFor(ChatArchiveFileRepository)
|
||||
final chatArchiveFileRepositoryProvider = AutoDisposeNotifierProvider<
|
||||
ChatArchiveFileRepository, Raw<Stream<WatchEvent>>>.internal(
|
||||
ChatArchiveFileRepository.new,
|
||||
name: r'chatArchiveFileRepositoryProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$chatArchiveFileRepositoryHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$ChatArchiveFileRepository
|
||||
= AutoDisposeNotifier<Raw<Stream<WatchEvent>>>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -0,0 +1,23 @@
|
||||
class ChatEntity {
|
||||
static final _namePattern = RegExp(r"^(.*?) - (.*?)\.md$");
|
||||
|
||||
final String fileName;
|
||||
|
||||
final String? name;
|
||||
final DateTime? dateTime;
|
||||
|
||||
ChatEntity._(this.fileName, {this.name, this.dateTime});
|
||||
|
||||
factory ChatEntity.fromFileName(String fileName) {
|
||||
final match = _namePattern.firstMatch(fileName);
|
||||
|
||||
return ChatEntity._(
|
||||
fileName,
|
||||
name: match?.group(1),
|
||||
dateTime: (match != null) ? DateTime.tryParse(match.group(2)!) : null,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => name ?? fileName;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:bang_navigator/features/chat_archive/data/repositories/chat_archive_file.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/domain/entities/chat_entity.dart';
|
||||
import 'package:bang_navigator/features/kagi/data/services/chat.dart';
|
||||
import 'package:exceptions/exceptions.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
part 'chat_archive.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class ChatArchiveRepository extends _$ChatArchiveRepository {
|
||||
Future<List<ChatEntity>> _listArchivedChats() async {
|
||||
final files =
|
||||
await ref.read(chatArchiveFileRepositoryProvider.notifier).list();
|
||||
|
||||
return files
|
||||
.where((file) => path.extension(file.path) == '.md')
|
||||
.map((file) => ChatEntity.fromFileName(path.basename(file.path)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<Result<void>> archiveChat(String fileName, Uri url) async {
|
||||
final contentsResult =
|
||||
await ref.read(kagiChatServiceProvider.notifier).downloadChat(url);
|
||||
|
||||
return contentsResult.flatMapAsync(
|
||||
(contents) => ref
|
||||
.read(chatArchiveFileRepositoryProvider.notifier)
|
||||
.write(fileName, contents),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Result<String>> readChat(String fileName) async {
|
||||
final contentsResult = await Result.fromAsync(
|
||||
() => ref.read(chatArchiveFileRepositoryProvider.notifier).read(fileName),
|
||||
);
|
||||
|
||||
return contentsResult.fold(
|
||||
(value) => (value == null)
|
||||
? Result.failure(
|
||||
ErrorMessage(
|
||||
source: 'Chat Archive',
|
||||
message: 'Chat $fileName not found',
|
||||
),
|
||||
)
|
||||
: Result.success(value),
|
||||
onFailure: Result.failure,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<ChatEntity>> build() async* {
|
||||
final fileRepository = ref.watch(chatArchiveFileRepositoryProvider);
|
||||
|
||||
yield* ConcatStream([
|
||||
_listArchivedChats().asStream(),
|
||||
fileRepository.asyncMap(
|
||||
(_) => _listArchivedChats(),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Future<String> readArchivedChat(
|
||||
ReadArchivedChatRef ref, String fileName) async {
|
||||
final result =
|
||||
await ref.read(chatArchiveRepositoryProvider.notifier).readChat(fileName);
|
||||
|
||||
return result.value;
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'chat_archive.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$readArchivedChatHash() => r'e7d646a0ea22fe24d96e97f86c1d46fe83818508';
|
||||
|
||||
/// 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 [readArchivedChat].
|
||||
@ProviderFor(readArchivedChat)
|
||||
const readArchivedChatProvider = ReadArchivedChatFamily();
|
||||
|
||||
/// See also [readArchivedChat].
|
||||
class ReadArchivedChatFamily extends Family<AsyncValue<String>> {
|
||||
/// See also [readArchivedChat].
|
||||
const ReadArchivedChatFamily();
|
||||
|
||||
/// See also [readArchivedChat].
|
||||
ReadArchivedChatProvider call(
|
||||
String fileName,
|
||||
) {
|
||||
return ReadArchivedChatProvider(
|
||||
fileName,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
ReadArchivedChatProvider getProviderOverride(
|
||||
covariant ReadArchivedChatProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.fileName,
|
||||
);
|
||||
}
|
||||
|
||||
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'readArchivedChatProvider';
|
||||
}
|
||||
|
||||
/// See also [readArchivedChat].
|
||||
class ReadArchivedChatProvider extends AutoDisposeFutureProvider<String> {
|
||||
/// See also [readArchivedChat].
|
||||
ReadArchivedChatProvider(
|
||||
String fileName,
|
||||
) : this._internal(
|
||||
(ref) => readArchivedChat(
|
||||
ref as ReadArchivedChatRef,
|
||||
fileName,
|
||||
),
|
||||
from: readArchivedChatProvider,
|
||||
name: r'readArchivedChatProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$readArchivedChatHash,
|
||||
dependencies: ReadArchivedChatFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
ReadArchivedChatFamily._allTransitiveDependencies,
|
||||
fileName: fileName,
|
||||
);
|
||||
|
||||
ReadArchivedChatProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.fileName,
|
||||
}) : super.internal();
|
||||
|
||||
final String fileName;
|
||||
|
||||
@override
|
||||
Override overrideWith(
|
||||
FutureOr<String> Function(ReadArchivedChatRef provider) create,
|
||||
) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: ReadArchivedChatProvider._internal(
|
||||
(ref) => create(ref as ReadArchivedChatRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
fileName: fileName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeFutureProviderElement<String> createElement() {
|
||||
return _ReadArchivedChatProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ReadArchivedChatProvider && other.fileName == fileName;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, fileName.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
mixin ReadArchivedChatRef on AutoDisposeFutureProviderRef<String> {
|
||||
/// The parameter `fileName` of this provider.
|
||||
String get fileName;
|
||||
}
|
||||
|
||||
class _ReadArchivedChatProviderElement
|
||||
extends AutoDisposeFutureProviderElement<String> with ReadArchivedChatRef {
|
||||
_ReadArchivedChatProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get fileName => (origin as ReadArchivedChatProvider).fileName;
|
||||
}
|
||||
|
||||
String _$chatArchiveRepositoryHash() =>
|
||||
r'c53b0d2704953a205c12357642237e15e8ffd3b1';
|
||||
|
||||
/// See also [ChatArchiveRepository].
|
||||
@ProviderFor(ChatArchiveRepository)
|
||||
final chatArchiveRepositoryProvider = AutoDisposeStreamNotifierProvider<
|
||||
ChatArchiveRepository, List<ChatEntity>>.internal(
|
||||
ChatArchiveRepository.new,
|
||||
name: r'chatArchiveRepositoryProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$chatArchiveRepositoryHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$ChatArchiveRepository = AutoDisposeStreamNotifier<List<ChatEntity>>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -0,0 +1,138 @@
|
||||
import 'package:bang_navigator/core/routing/routes.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/data/repositories/chat_archive_file.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/domain/entities/chat_entity.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/domain/repositories/chat_archive.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/utils/markdown_to_text.dart';
|
||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/controllers/switch_new_tab.dart';
|
||||
import 'package:bang_navigator/presentation/widgets/failure_widget.dart';
|
||||
import 'package:bang_navigator/utils/ui_helper.dart' as ui_helper;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.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:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
class ChatArchiveDetailScreen extends HookConsumerWidget {
|
||||
final String fileName;
|
||||
|
||||
const ChatArchiveDetailScreen(this.fileName, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final chatAsync = ref.watch(readArchivedChatProvider(fileName));
|
||||
|
||||
final entity = useMemoized(() => ChatEntity.fromFileName(fileName));
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(entity.toString()),
|
||||
actions: [
|
||||
MenuAnchor(
|
||||
builder: (context, controller, child) {
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.more_vert),
|
||||
);
|
||||
},
|
||||
menuChildren: [
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
if (chatAsync.valueOrNull != null) {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(
|
||||
text: await Future.microtask(
|
||||
() => markdownToText(chatAsync.valueOrNull!),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
leadingIcon: const Icon(MdiIcons.textLong),
|
||||
child: const Text('Copy as plain text'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
if (chatAsync.valueOrNull != null) {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(
|
||||
text: chatAsync.valueOrNull!,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
// ignore: deprecated_member_use
|
||||
leadingIcon: const Icon(MdiIcons.languageMarkdown),
|
||||
child: const Text('Copy as markdown'),
|
||||
),
|
||||
const Divider(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(chatArchiveFileRepositoryProvider.notifier)
|
||||
.delete(fileName);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
},
|
||||
leadingIcon: const Icon(Icons.delete),
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Skeletonizer(
|
||||
enabled: chatAsync.isLoading,
|
||||
child: chatAsync.when(
|
||||
data: (data) => Markdown(
|
||||
data: data,
|
||||
selectable: true,
|
||||
onTapLink: (text, href, title) async {
|
||||
if (href != null) {
|
||||
if (Uri.parse(href) case final Uri url) {
|
||||
final launchExternal = ref
|
||||
.read(settingsRepositoryProvider)
|
||||
.valueOrNull
|
||||
?.launchUrlExternal ??
|
||||
false;
|
||||
|
||||
if (launchExternal) {
|
||||
await ui_helper.launchUrlFeedback(context, Uri.parse(href));
|
||||
} else {
|
||||
await ref
|
||||
.read(switchNewTabControllerProvider.notifier)
|
||||
.add(url);
|
||||
|
||||
if (context.mounted) {
|
||||
context.go(KagiRoute().location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
error: (error, stackTrace) {
|
||||
return FailureWidget(
|
||||
title: error.toString(),
|
||||
onRetry: () => ref.refresh(readArchivedChatProvider(fileName)),
|
||||
);
|
||||
},
|
||||
loading: () => const Bone.multiText(
|
||||
lines: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:bang_navigator/core/routing/routes.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/domain/repositories/chat_archive.dart';
|
||||
import 'package:bang_navigator/presentation/widgets/failure_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
class ChatArchiveListScreen extends HookConsumerWidget {
|
||||
const ChatArchiveListScreen({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final chatsAsync = ref.watch(chatArchiveRepositoryProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Chat Archive')),
|
||||
body: SafeArea(
|
||||
child: Skeletonizer(
|
||||
enabled: chatsAsync.isLoading,
|
||||
child: chatsAsync.when(
|
||||
data: (chats) {
|
||||
return ListView.builder(
|
||||
itemCount: chats.length,
|
||||
itemBuilder: (context, index) {
|
||||
final chat = chats[index];
|
||||
|
||||
return ListTile(
|
||||
title: Text(chat.toString()),
|
||||
subtitle: (chat.dateTime != null)
|
||||
? Text(chat.dateTime.toString())
|
||||
: null,
|
||||
onTap: () async {
|
||||
await context.push(
|
||||
ChatArchiveDetailRoute(fileName: chat.fileName)
|
||||
.location,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) {
|
||||
return FailureWidget(
|
||||
title: error.toString(),
|
||||
onRetry: () => ref.refresh(chatArchiveRepositoryProvider),
|
||||
);
|
||||
},
|
||||
loading: () => ListView.builder(
|
||||
itemCount: 3,
|
||||
itemBuilder: (context, index) => const ListTile(
|
||||
title: Bone.text(),
|
||||
subtitle: Bone.text(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:html/parser.dart' as html_parser;
|
||||
import 'package:markdown/markdown.dart' as md;
|
||||
|
||||
String markdownToText(String markdown) {
|
||||
final html = md.markdownToHtml(markdown);
|
||||
final document = html_parser.parse(html);
|
||||
|
||||
return document.body?.text ?? '';
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:bang_navigator/core/http_error_handler.dart';
|
||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:exceptions/exceptions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'chat.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class KagiChatService extends _$KagiChatService {
|
||||
late http.Client _client;
|
||||
|
||||
@override
|
||||
void build() {
|
||||
_client = http.Client();
|
||||
}
|
||||
|
||||
Future<Result<String>> downloadChat(Uri url) {
|
||||
final kagiSession =
|
||||
ref.read(settingsRepositoryProvider).valueOrNull?.kagiSession;
|
||||
|
||||
return Result.fromAsync(
|
||||
() async {
|
||||
final response = await _client
|
||||
.get(url.replace(queryParameters: {'token': kagiSession}));
|
||||
|
||||
return response.body;
|
||||
},
|
||||
exceptionHandler: handleHttpError,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'chat.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$kagiChatServiceHash() => r'80ead208a1d7ca0da98bd20f11c99efd0d682c8f';
|
||||
|
||||
/// See also [KagiChatService].
|
||||
@ProviderFor(KagiChatService)
|
||||
final kagiChatServiceProvider =
|
||||
NotifierProvider<KagiChatService, void>.internal(
|
||||
KagiChatService.new,
|
||||
name: r'kagiChatServiceProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$kagiChatServiceHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$KagiChatService = Notifier<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
|
||||
@@ -25,7 +25,6 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class KagiScreen extends HookConsumerWidget {
|
||||
const KagiScreen({super.key});
|
||||
@@ -208,6 +207,14 @@ class KagiScreen extends HookConsumerWidget {
|
||||
child: const Text('Summarizer'),
|
||||
),
|
||||
const Divider(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await context.push(ChatArchiveListRoute().location);
|
||||
},
|
||||
leadingIcon: const Icon(MdiIcons.archive),
|
||||
child: const Text('Chat Archive'),
|
||||
),
|
||||
const Divider(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await context.push(AboutRoute().location);
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'settings_repository.dart';
|
||||
// **************************************************************************
|
||||
|
||||
String _$settingsRepositoryHash() =>
|
||||
r'1e1dc6c76bdcaf742335bf8e11a584093ec13f33';
|
||||
r'2b715f29915e541cec5c7c0993c8099944989f48';
|
||||
|
||||
/// See also [SettingsRepository].
|
||||
@ProviderFor(SettingsRepository)
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'save_settings.g.dart';
|
||||
|
||||
@riverpod
|
||||
@Riverpod()
|
||||
class SaveSettingsController extends _$SaveSettingsController {
|
||||
@override
|
||||
FutureOr<void> build() {}
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'save_settings.dart';
|
||||
// **************************************************************************
|
||||
|
||||
String _$saveSettingsControllerHash() =>
|
||||
r'861664dc6e526737adff645597b141c2ba9d97c1';
|
||||
r'f03cbb1a3a04f974560f5b6f0312fcc54ec25c54';
|
||||
|
||||
/// See also [SaveSettingsController].
|
||||
@ProviderFor(SaveSettingsController)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bang_navigator/core/logger.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/domain/entities/chat_entity.dart';
|
||||
import 'package:bang_navigator/features/chat_archive/domain/repositories/chat_archive.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/providers.dart';
|
||||
@@ -10,6 +12,7 @@ import 'package:bang_navigator/features/settings/data/repositories/settings_repo
|
||||
import 'package:bang_navigator/features/web_view/domain/entities/web_view_page.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/controllers/switch_new_tab.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/widgets/web_page_dialog.dart';
|
||||
import 'package:bang_navigator/features/web_view/utils/download_helper.dart';
|
||||
import 'package:bang_navigator/features/web_view/utils/favicon_helper.dart';
|
||||
import 'package:bang_navigator/utils/platform_util.dart' as platform_util;
|
||||
import 'package:bang_navigator/utils/ui_helper.dart' as ui_helper;
|
||||
@@ -328,18 +331,40 @@ class _WebViewState extends ConsumerState<WebView> {
|
||||
onTitleChanged: (controller, title) {
|
||||
widget.updatePage((page) => page.copyWith.title(title));
|
||||
},
|
||||
onDownloadStartRequest: (controller, downloadStartRequest) async {
|
||||
final fileName = getDispositionFileName(
|
||||
downloadStartRequest.contentDisposition!,
|
||||
);
|
||||
|
||||
// onDownloadStartRequest: (controller, downloadStartRequest) {
|
||||
// final regex = RegExp(
|
||||
// r"filename\*=UTF-8''([\w%\-\.]+)(?:; ?|$)",
|
||||
// caseSensitive: false,
|
||||
// );
|
||||
if (fileName != null) {
|
||||
final entity = ChatEntity.fromFileName(fileName);
|
||||
if (entity.name != null) {
|
||||
final fileWrite = await ref
|
||||
.read(chatArchiveRepositoryProvider.notifier)
|
||||
.archiveChat(fileName, downloadStartRequest.url);
|
||||
|
||||
// final math =
|
||||
// regex.firstMatch(downloadStartRequest.contentDisposition!);
|
||||
|
||||
// print(math);
|
||||
// },
|
||||
fileWrite.map(
|
||||
onSuccess: (_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: Colors.green,
|
||||
content: Text(
|
||||
'Conversation "$entity" saved successfully!',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
onFailure: (errorMessage) {
|
||||
ui_helper.showErrorMessage(
|
||||
context,
|
||||
errorMessage.toString(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
HookBuilder(
|
||||
builder: (context) {
|
||||
|
||||
Reference in New Issue
Block a user