superlistapp / super_native_extensions

Native drag & drop, clipboard access and context menu.
MIT License
451 stars 79 forks source link

[super_drag_and_drop] Can't read files from Microsoft Outlook #158

Closed socramm9 closed 1 year ago

socramm9 commented 1 year ago

I am trying to drag and drop A file from Microsoft Outlook into my Flutter app. But I a receiving a strange error message.

Example Code:

extension on DataReader {
  dynamic getAnyFile(
    AsyncValueChanged<DataReaderFile> onFile, {
    ValueChanged<Object>? onError,
  }) {
    final formats = platformFormats;
    if (formats.isNotEmpty) {
      final format = formats.first;

      return getFile(
        SimpleFileFormat(fallbackFormats: [format]),
        onFile,
        onError: onError,
      );
    } else {
      return null;
    }
  }
}
Widget build(BuildContext context) {
    return DropRegion(
      formats: const [...Formats.standardFormats],
      onDropEnter: (event) {
        //...
      },
      onDropLeave: (event) {
        //...
      },
      onDropOver: (event) {
        return DropOperation.copy;
      },
      onPerformDrop: (event) async {
        final item = event.session.items.first;

        // data reader is available now
        final reader = item.dataReader!;
        if (reader.canProvide(Formats.fileUri)) {
          reader.getValue<Uri>(
            Formats.fileUri,
            (value) async {
              // ...
            },
            onError: (error) {
              debugPrint('Error reading value $error');
            },
          );
          return;
        }

        reader.getAnyFile(
          (value) async {
            if (value is DataReaderVirtualFileAdapter) {
              if (value.file is VirtualFileFromFile) {
                final vFile = value.file as VirtualFileFromFile;

                //...
              } else if (kIsWeb) {
                final data = await value.file.readNext();
                //...
              }
            }
          },
          onError: (error) {
            debugPrint("error $error");
          },
        );
        return;
      },
      child: Container(
          //child: ...,
          ),
    );
  }

Error Message that I get:

ERROR [] Unexpected error Ungültige FORMATETC-Struktur (0x80040064) at src\.\win32\drop.rs:487:22 error PlatformException(super_native_extensions_error, "Windows Error: Eine Schnittstelle, die für einen anderen Thread marshalled war, wurde von der Anwendung aufgerufen. (0x8001010E)", otherError, null)

Translation: ERROR [] Unexpected error Invalid FORMATETC structure (0x80040064) at src\.\win32\drop.rs:487:22

error PlatformException(super_native_extensions_error, "Windows Error: An interface marshaled for a different thread was called by the application. (0x8001010E)", otherError, null)

It works fine if Drag and Dropped from Explorer and on MacOs it works fine also for outlook.

Please let me know if I can Provide further information

knopp commented 1 year ago

Just in case, which super_drag_and_drop version is this with?

socramm9 commented 1 year ago

I Testet it with super_drag_and_drop: ^0.5.0 and the Previous version

knopp commented 1 year ago

Well, this is very disappointing. Turns out that outlook doesn't support IDataObjectAsyncCapability for attachments. I'd expect outlook being a flag ship product having stellar drag & drop implementation but it can't even download attachments in background :-/. Or, for that matter, set proper drag avatars. Quite sad.

Nonetheless, super_drag_and_drop needs to handle this properly.

socramm9 commented 1 year ago

I am still getting the same issue. Do I have to change anything else? I am on Windows 10 If it helps.

I am installing directly from GitHub

super_drag_and_drop:
    git:
      url: https://github.com/superlistapp/super_native_extensions.git
      path: super_drag_and_drop
knopp commented 1 year ago

What revision are you at (check pubspec.lock)?

socramm9 commented 1 year ago

It looks like this after I changed to git version:

image001

knopp commented 1 year ago

I think you need to add dependency_override for super_native_extensions nad also set it to git (current revision). Otherwise it will use the old (currently published) version of super_native_extensions.

knopp commented 1 year ago

I'm hoping to publish and updated version soon though.

socramm9 commented 1 year ago

I updated to 0.6.4 and still get this error:

2023-08-24T15:26:49.813Z ERROR [] Unexpected error Ungültige FORMATETC-Struktur (0x80040064) at src.\win32\drop.rs:488:22

knopp commented 1 year ago

That error is normal for outlook. It is only concerning the drop preview, which is not working for outlook in any application.

This is not related in any way to actually reading the dropped data. It's the other error that you initially got:

error PlatformException(super_native_extensions_error, "Windows Error: An interface marshaled for a different thread was called by the application. (0x8001010E)", otherError, null)

That was relevant to data receiving. Are you unable to read the stream?

socramm9 commented 1 year ago

Thanks for the info. I will check my code and let you know

socramm9 commented 1 year ago

I could fix it now had to change my code for reading Virtual Files :)

Thanks for the great help