TinyCircuits-Thumby-Code-Editor icon indicating copy to clipboard operation
TinyCircuits-Thumby-Code-Editor copied to clipboard

Cannot export to PC (button does not work) nor import

Open Buggem opened this issue 1 year ago • 16 comments

export to pc Button doesn't work (Firefox 121.0). I am a javascript dev and I have done similar things (making scripts to download files) before and would be happy to help if you need it. Os is macOS Sonama 14.1.2 (m2)

Buggem avatar Dec 20 '23 01:12 Buggem

Added: used js debug skills: error is window.showSaveFilePicker is not a function

Buggem avatar Dec 20 '23 02:12 Buggem

that is an experimental technology ye silly guys you gotta state that

Buggem avatar Dec 20 '23 02:12 Buggem

nice open source editor, im trying to emulate the file picker right now

Buggem avatar Dec 20 '23 02:12 Buggem

here is some code that patches the issue, at least on firefox also the open button aint gonna work either. it uses the same API as the showSaveFilePicker() function (the File System API)

window.showSaveFilePicker=function(fileoptions) {
    window.savefileopt = fileoptions;
    return new Promise((resolve) => {
    resolve({
            
            kind: "file",
            createWritable: function() {
                
                return new Promise((resolve) => {
                    resolve({
                        write: function(blob){
                            var saveData = function (blob, fileName) {
                                    var a = document.createElement("a");
                                    document.body.appendChild(a);
                                    a.style = "display: none";
                                    
                                            var url = window.URL.createObjectURL(blob);
                                            a.href = url;
                                            a.download = prompt("Choose a name for the download", fileName);
                                            a.click();
                                            window.URL.revokeObjectURL(url);
                                    
                            };
                            saveData(blob, savefileopt.suggestedName)
                            resolve();
                        },
                        close:function(){}
                    })
                    //fake the fake file handles fake writable
                });
            }
        }) //fake the file handle
  });
}; 

I put a lot of time and effort into this ( 10 minutes) so I hope to see it implemented in your code. (im not very good) also you must do similar for the file picker (include an invisible <input> instead of an invisible <a> as that will increase compatibility by 105%.) so yeh, be sure to at least include something like this as a fallback if the function cannot be found. Thanks, buggem (Max Parry)

Buggem avatar Dec 20 '23 02:12 Buggem

And even weirder I can see a catch statement for the showOpenFilePicker() call, but not the showSaveFilePicker() call. Weird, feels like someone forgot to catch for errors there. It's lucky for me though, because it led me right to the spot.

Buggem avatar Dec 20 '23 02:12 Buggem

for some reason i can't get the openFilePicker call to work.

window.showOpenFilePicker = function(fileoptions) {
	try {
    return new Promise((resolve) => {
        resolve({
            fileoptions: fileoptions,
            getFile: function() {
                let fileoptions = this.fileoptions;
                return new Promise((resolve) => {
                    let input = document.createElement('input');
                    input.type = 'file';
                    input.style = "display: none";
                    input.accept = this.fileoption.types.map(a=>a.accept).join(',')
                    input.onchange = e => {
                        resolve(e.target.files[0]);
                    }
                    input.click();
                    window.myFileInput = input; // for debugging
                }); // our part is done, we can let the file class do the rest... woo-hoo
            }
        })
    });
	} catch(e) { console.log(e.message); }
}

my code so far

Buggem avatar Dec 20 '23 03:12 Buggem

finished and working:

window.showOpenFilePicker = function(fileoptions) {
    console.log("here")
    window.openfileopt = fileoptions;
    return new Promise((resolve) => {
        
        alert("inside promise openfilepicker")
        resolve([{
            
            getFile: function() {
                alert("got to getfile")
                
                return new Promise((resolve) => {
                    let input = document.createElement('input');
                    input.type = 'file';
                    input.style = "display: none";
                    input.onchange = e => {
                        resolve(e.target.files[0]);
                    }
                    input.click();
                    window.myFileInput = input; // for debugging
                }); // our part is done, we can let the file class do the rest... woo-hoo
            }
        }])
    });
    
}

Buggem avatar Dec 20 '23 04:12 Buggem

could you implement my code? will open a pull request if you want me to

Buggem avatar Dec 20 '23 04:12 Buggem

congratulations, you changed your script and broke my code :) working on a fix, if you do this again ill have to create a repo for this ;) lol

Buggem avatar Dec 22 '23 01:12 Buggem

umm no you didnt sorry

it was just micropython code instead of blockly code ;0

Buggem avatar Dec 22 '23 01:12 Buggem

https://github.com/Buggem/sysstorapi-hack/tree/main

incase of future updates, here it is

Buggem avatar Dec 22 '23 01:12 Buggem

hurry up and fix

Buggem avatar Dec 31 '23 02:12 Buggem

this is just useless irl

Buggem avatar Apr 06 '24 07:04 Buggem

been 4 months bro

Buggem avatar Apr 06 '24 07:04 Buggem

Please can you raise a PR for review?

ace-dent avatar Apr 06 '24 11:04 ace-dent

@ace-dent yes i can, and i will try

Buggem avatar Apr 06 '24 21:04 Buggem