electron-in-action / firesale

Mozilla Public License 2.0
76 stars 41 forks source link

not cross-platform? #2

Open shin-ra opened 5 years ago

shin-ra commented 5 years ago

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

Ventrosky commented 5 years ago

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

check out this commit

robertpatrick commented 3 years ago

@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.

Ventrosky commented 3 years ago

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 .txtbut 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