mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Handle ImageProcessorUploadSuccessEvent
This commit is contained in:
parent
88af19ac67
commit
54e8c127b9
6 changed files with 74 additions and 5 deletions
|
@ -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!;
|
||||
|
|
|
@ -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<Message>().listen((event) {
|
||||
_subscriptions.add(MessageRelay.stream.whereType<Message>().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<ImageProcessorUploadSuccessEvent>()
|
||||
.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 = <StreamSubscription>[];
|
||||
}
|
||||
|
|
12
np_platform_image_processor/build.yaml
Normal file
12
np_platform_image_processor/build.yaml
Normal file
|
@ -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
|
|
@ -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";
|
||||
}
|
||||
|
|
15
np_platform_image_processor/lib/src/event.g.dart
Normal file
15
np_platform_image_processor/lib/src/event.g.dart
Normal file
|
@ -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 {}";
|
||||
}
|
||||
}
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue