TurboWarp / packager

Converts Scratch projects into HTML files, zip archives, or executable programs for Windows, macOS, and Linux.
https://packager.turbowarp.org/
Mozilla Public License 2.0
242 stars 154 forks source link

No pen #854

Closed kingsuper195 closed 5 months ago

kingsuper195 commented 6 months ago

I am using the scaffolding api for my project and I get this warning when I try to use it with a project that has the pen extension in it: vm warn Central dispatch replacing existing service provider for extension_0_pen I am not sure whether it is a problem with scaffolding or my use of scaffolding.

GarboMuffin commented 6 months ago

Unless pen is actually not working you should be able to ignore that

GarboMuffin commented 6 months ago

If pen is indeed not working then send me a URL/file/etc. so I can check what's wrong

kingsuper195 commented 6 months ago

It is acctually not working, this is the repo, you can ignore the non scaffolding stuff. The file is FS/embed.html.

GarboMuffin commented 6 months ago

I modified your HTML to be just the scaffolding part and pen works fine;

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <script src="https://cdn.jsdelivr.net/npm/@turbowarp/packager@2.0.0/dist/scaffolding/scaffolding-full.js"></script>
    <style>
        html, body, #project {
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div id="project"></div>
    <script>
        // const COMMAND = 'load-os-file:';
        // var messagerecived = false;
        // async function dataUrlToBytes(dataUrl) {
        //   const res = await fetch('http://localhost:3333/fs/read?encoding=base64&path='+dataUrl);
        //   const json = await res.json(); 
        //   const res2 = await fetch('data:application/octet-stream;base64,'+json.contents);
        //   return await res2.arrayBuffer();
        // }        
        // var notime = window.setTimeout(function(){
        //     if(!messagerecived){
        //         window.parent.postMessage("OS.ALEART.noapp.send");
        //     }
        // },3000)

        // https://docs.turbowarp.org/unshared-projects#developers
        const getProjectMetadata = async (projectId) => {
            const response = await fetch(`https://trampoline.turbowarp.org/api/projects/${projectId}`);
            if (response.status === 404) {
                throw new Error('The project is unshared or does not exist');
            }
            if (!response.ok) {
                throw new Error(`HTTP error ${response.status} fetching project metadata`);
            }
            const json = await response.json();
            return json;
        };
        const getProjectData = async (projectId) => {
            const metadata = await getProjectMetadata(projectId);
            const token = metadata.project_token;
            const response = await fetch(`https://projects.scratch.mit.edu/${projectId}?token=${token}`);
            if (!response.ok) {
                throw new Error(`HTTP error ${response.status} fetching project data`);
            }
            const data = await response.arrayBuffer();
            return data;
        };

        const scaffolding = new Scaffolding.Scaffolding();
        scaffolding.width = 480; /* Custom stage width */
        scaffolding.height = 360; /* Custom stage height */
        scaffolding.resizeMode = 'dynamic-resize'; /* or '' or 'stretch' */
        scaffolding.editableLists = false; /* Affects list monitors */

        async function run() {
            const projectData = await getProjectData('15832807');
            scaffolding.setup();
            scaffolding.appendTo(document.getElementById('project'));
            scaffolding.setUsername("User1");
            scaffolding.loadProject(projectData)
                .then(() => {
                    scaffolding.start();
                })
                .catch((error) => {
                    console.error("loadProject: "+error)
                    var message = "OS.TRIGGER.exitapp.run";
                    window.parent.postMessage(message, "*");
                });            
        }

        run();

        // window.addEventListener('message', async function(event) {

        //     if(!event.data.startsWith(COMMAND)) return;
        //     /* debugger; */
        //     clearTimeout(notime);

        // });
        // document.addEventListener('keydown', exitApp);

        // window.parent.postMessage("OS.TRIGGER.enterapp.run","*")
        // function exitApp(e) {
        //   if(e.key=="Home"){
        //     var message = "OS.TRIGGER.exitapp.run";
        //     window.parent.postMessage(message, "*");
        //   }
        // }
    </script>
</body>
</html>

image

the ? is from not having web sources set up, but that's not needed if you're loading projects from files as it seems you are

kingsuper195 commented 5 months ago

It looks like I may have broken the sb3 file I was testing with and broke it. I started again with it and now pen is working fine. Thanks for your support!