Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Buggem opened this issue Dec 20, 2023 · 16 comments
Open

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

Buggem opened this issue Dec 20, 2023 · 16 comments

Comments

@Buggem
Copy link

Buggem commented Dec 20, 2023

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
Copy link
Author

Buggem commented Dec 20, 2023

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

@Buggem
Copy link
Author

Buggem commented Dec 20, 2023

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

@Buggem
Copy link
Author

Buggem commented Dec 20, 2023

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

@Buggem
Copy link
Author

Buggem commented Dec 20, 2023

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 Buggem changed the title cannot export to pc Cannot export to PC (button does not work) nor import Dec 20, 2023
@Buggem
Copy link
Author

Buggem commented Dec 20, 2023

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
Copy link
Author

Buggem commented Dec 20, 2023

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
Copy link
Author

Buggem commented Dec 20, 2023

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
Copy link
Author

Buggem commented Dec 20, 2023

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

@Buggem
Copy link
Author

Buggem commented Dec 22, 2023

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
Copy link
Author

Buggem commented Dec 22, 2023

umm no you didnt sorry

it was just micropython code instead of blockly code ;0

@Buggem
Copy link
Author

Buggem commented Dec 22, 2023

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

incase of future updates, here it is

@Buggem
Copy link
Author

Buggem commented Dec 31, 2023

hurry up and fix

@Buggem
Copy link
Author

Buggem commented Apr 6, 2024

this is just useless irl

@Buggem
Copy link
Author

Buggem commented Apr 6, 2024

been 4 months bro

@ace-dent
Copy link
Contributor

ace-dent commented Apr 6, 2024

Please can you raise a PR for review?

@Buggem
Copy link
Author

Buggem commented Apr 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants