From 54e8c127b9ecac08130d15260ec1726ab745ac8a Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Wed, 31 Jan 2024 01:35:12 +0800 Subject: [PATCH] Handle ImageProcessorUploadSuccessEvent --- app/lib/controller/account_controller.dart | 5 +++- app/lib/event/native_event_relay.dart | 29 ++++++++++++++++--- np_platform_image_processor/build.yaml | 12 ++++++++ .../lib/src/event.dart | 8 +++++ .../lib/src/event.g.dart | 15 ++++++++++ np_platform_image_processor/pubspec.yaml | 10 +++++++ 6 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 np_platform_image_processor/build.yaml create mode 100644 np_platform_image_processor/lib/src/event.g.dart diff --git a/app/lib/controller/account_controller.dart b/app/lib/controller/account_controller.dart index 20e1e2d1..cdd66061 100644 --- a/app/lib/controller/account_controller.dart +++ b/app/lib/controller/account_controller.dart @@ -44,7 +44,10 @@ class AccountController { _metadataController?.dispose(); _metadataController = null; _nativeEventRelay?.dispose(); - _nativeEventRelay = NativeEventRelay(filesController: filesController); + _nativeEventRelay = NativeEventRelay( + filesController: filesController, + metadataController: metadataController, + ); } Account get account => _account!; diff --git a/app/lib/event/native_event_relay.dart b/app/lib/event/native_event_relay.dart index f05bcd46..1271058d 100644 --- a/app/lib/event/native_event_relay.dart +++ b/app/lib/event/native_event_relay.dart @@ -2,19 +2,24 @@ import 'dart:async'; import 'package:logging/logging.dart'; import 'package:nc_photos/controller/files_controller.dart'; +import 'package:nc_photos/controller/metadata_controller.dart'; import 'package:nc_photos/event/native_event.dart'; +import 'package:nc_photos/platform/features.dart' as features; import 'package:nc_photos/stream_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_platform_image_processor/np_platform_image_processor.dart'; import 'package:np_platform_message_relay/np_platform_message_relay.dart'; part 'native_event_relay.g.dart'; +/// Convert native events into actions on the corresponding controllers @npLog class NativeEventRelay { NativeEventRelay({ required this.filesController, + required this.metadataController, }) { - _subscription = MessageRelay.stream.whereType().listen((event) { + _subscriptions.add(MessageRelay.stream.whereType().listen((event) { switch (event.event) { case FileExifUpdatedEvent.id: _onFileExifUpdatedEvent(FileExifUpdatedEvent.fromEvent(event)); @@ -24,11 +29,19 @@ class NativeEventRelay { _log.severe('Unknown event: ${event.event}'); break; } - }); + })); + + if (features.isSupportEnhancement) { + _subscriptions.add(ImageProcessor.stream + .whereType() + .listen(_onImageProcessorUploadSuccessEvent)); + } } void dispose() { - _subscription?.cancel(); + for (final s in _subscriptions) { + s.cancel(); + } } void _onFileExifUpdatedEvent(FileExifUpdatedEvent ev) { @@ -36,6 +49,14 @@ class NativeEventRelay { filesController.applySyncResult(fileExifs: ev.fileIds); } + void _onImageProcessorUploadSuccessEvent( + ImageProcessorUploadSuccessEvent ev) { + _log.info(ev); + filesController.syncRemote(); + metadataController.scheduleNext(); + } + final FilesController filesController; - StreamSubscription? _subscription; + final MetadataController metadataController; + final _subscriptions = []; } diff --git a/np_platform_image_processor/build.yaml b/np_platform_image_processor/build.yaml new file mode 100644 index 00000000..3f712dba --- /dev/null +++ b/np_platform_image_processor/build.yaml @@ -0,0 +1,12 @@ +targets: + $default: + builders: + to_string_build: + options: + formatStringNameMapping: + double: "${$?.toStringAsFixed(3)}" + List: "[length: ${$?.length}]" + Set: "{length: ${$?.length}}" + File: "${$?.path}" + FileDescriptor: "${$?.fdPath}" + useEnumName: true diff --git a/np_platform_image_processor/lib/src/event.dart b/np_platform_image_processor/lib/src/event.dart index 3c85173b..f7a4ddf8 100644 --- a/np_platform_image_processor/lib/src/event.dart +++ b/np_platform_image_processor/lib/src/event.dart @@ -1,3 +1,7 @@ +import 'package:to_string/to_string.dart'; + +part 'event.g.dart'; + abstract class ImageProcessorEvent { static ImageProcessorEvent fromNativeEvent(dynamic ev) { final id = ev["event"]; @@ -10,6 +14,7 @@ abstract class ImageProcessorEvent { } } +@toString class ImageProcessorUploadSuccessEvent implements ImageProcessorEvent { const ImageProcessorUploadSuccessEvent._(); @@ -18,5 +23,8 @@ class ImageProcessorUploadSuccessEvent implements ImageProcessorEvent { return const ImageProcessorUploadSuccessEvent._(); } + @override + String toString() => _$toString(); + static const _id = "ImageProcessorUploadSuccessEvent"; } diff --git a/np_platform_image_processor/lib/src/event.g.dart b/np_platform_image_processor/lib/src/event.g.dart new file mode 100644 index 00000000..fb2854ef --- /dev/null +++ b/np_platform_image_processor/lib/src/event.g.dart @@ -0,0 +1,15 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'event.dart'; + +// ************************************************************************** +// ToStringGenerator +// ************************************************************************** + +extension _$ImageProcessorUploadSuccessEventToString + on ImageProcessorUploadSuccessEvent { + String _$toString() { + // ignore: unnecessary_string_interpolations + return "ImageProcessorUploadSuccessEvent {}"; + } +} diff --git a/np_platform_image_processor/pubspec.yaml b/np_platform_image_processor/pubspec.yaml index 1d98bfc1..8f6e5b1f 100644 --- a/np_platform_image_processor/pubspec.yaml +++ b/np_platform_image_processor/pubspec.yaml @@ -17,6 +17,11 @@ dependencies: path: ../codegen np_platform_raw_image: path: ../np_platform_raw_image + to_string: + git: + url: https://gitlab.com/nkming2/dart-to-string + ref: to_string-1.0.0 + path: to_string dev_dependencies: build_runner: ^2.2.1 @@ -24,6 +29,11 @@ dev_dependencies: path: ../codegen_build np_lints: path: ../np_lints + to_string_build: + git: + url: https://gitlab.com/nkming2/dart-to-string + ref: to_string_build-1.0.0 + path: to_string_build flutter: plugin: