electron-in-action/firesale

not cross-platform?

Opened this issue · 3 comments

dragging and dropping a markdown file is not working on win 10, but doing the same with text files work.

I found some issues too, maybe could be related @shin-ra :

  • One was with the macOS methods setDocumentEdited and isDocumentEdited undefined in Win using Electron 7 so I had to implement them. (not your case since .txt works for you)
  • Second issue was with the function fileTypeIsSupported, the property type of the dragged files shows an empty string, so I check the extension with a simple regexp in those cases.

check out this commit

@Ventrosky the fileTypeIsSupported implementation in your commit works on MacOS for the drop event but not the dragover event where both file.type and file.name fields are both empty.

oh my it has been so long :) here it's the bit of code referenced by @robertpatrick

const getDraggedFile = (event) => event.dataTransfer.items[0];
const getDroppedFile = (event) => event.dataTransfer.files[0];

// used in the handlers to add drag-over/ drag-error classes
const fileTypeIsSupported = (file) => {
    return file.type ?  
        ['text/plain', 'text/markdown'].includes(file.type)  : 
        /\.(md|markdown|txt)$/i.test(file.name);
};

It's interesting dho, because from the docs the DataTransferItem should contain the MIME type, didn't have problems with dragover on linux or win 10 when I tested it with files with the extension .md or .txt but didn't have the chance to try it on a mac.
While the regexp test on file.name makes sense only for the file elements returned by getDroppedFile used for handling the drop event.
Looking back I have some objections on how I wrote this function and I think those two checks should be separated. Something like this would have been much clearer of what I think where my intentions:

const supportedDragoverItem =  (item) => ['text/plain', 'text/markdown'].includes(item.type);
const supportedDropFile =  (file) => /\.(md|markdown|txt)$/i.test(file.name);

While this doesn't solve the dragover problem on a Mac maybe can still help with the investigation