Skip to content

Commit

Permalink
feat(pyodideworker): wip approaches to registering service worker wit…
Browse files Browse the repository at this point in the history
…h recent changes pulled in from main
  • Loading branch information
sra405 committed May 31, 2024
1 parent 800d114 commit 3c484c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,46 @@ import VisualOutputPane from "./VisualOutputPane";
import OutputViewToggle from "../OutputViewToggle";
import { SettingsContext } from "../../../../../utils/settings";
import RunnerControls from "../../../../RunButton/RunnerControls";
// import PyodideWorker from "worker-loader!./PyodideWorker.js";
// import PyodideWorker from "worker-plugin/loader!?esModule./PyodideWorkerObj.js";
// import PyodideWorker from "worker-plugin/loader!./PyodideWorker.js"; // outputs a string like 0.web-component.worker.js
// import serviceWorker from "worker-loader!../../../../utils/PyodideServiceWorker.js";
// import serviceWorker from "../../../../utils/PyodideServiceWorker.js";

// import fileContent from "./PyodideWorkerObj.js";
// import fileContent from "./PyodideWorker.js";

// const blob = new Blob([fileContent], { type: "application/javascript" }); // Create a blob from the imported file
// const url = URL.createObjectURL(blob); // Create a blob URL

const getWorkerURL = (url) => {
const content = `importScripts("${url}");`;
const blob = new Blob([content], { type: "application/javascript" });
return URL.createObjectURL(blob);
};

const workerUrl = getWorkerURL(`${process.env.PUBLIC_URL}/PyodideWorker.js`);
// const serviceWorkerUrl = getWorkerURL(
// `${process.env.PUBLIC_URL}/PyodideServiceWorker.js`,
// );

const PyodideRunner = ({ active }) => {
const pyodideWorker = useMemo(
() => new Worker("./PyodideWorker.js", { type: "module" }),
[],
);
// const pyodideWorker = useMemo(
// () =>
// // new Worker(`${process.env.PUBLIC_URL}/PyodideWorker.js`, {
// // new Worker(new URL("./PyodideWorker.js", import.meta.url), {
// new Worker(`./PyodideWorker.js`, {
// type: "module",
// // credentials: "omit", // or "same-origin" if your server requires cookies or HTTP authentication
// }),
// [],
// );
// const pyodideWorker = useMemo(() => new PyodideWorker(), []);
// const pyodideWorker = useMemo(() => new Worker(PyodideWorker), []);
// const pyodideWorker = useMemo(() => PyodideWorker, []);
// const pyodideWorker = useMemo(() => new Worker(url, { type: "module" }), []);
const pyodideWorker = useMemo(() => new Worker(workerUrl), []);
// const pyodideWorker = useMemo(() => new Worker(PyodideWorker()), []);
const interruptBuffer = useRef();
const stdinBuffer = useRef();
const stdinClosed = useRef();
Expand Down
5 changes: 3 additions & 2 deletions src/components/Editor/Runners/RunnerFactory.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import PythonRunner from "./PythonRunner/PythonRunner";
import PyodideRunner from "./PythonRunner/PyodideRunner/PyodideRunner";
// import PythonRunner from "./PythonRunner/SkulptRunner/SkulptRunner";
import HtmlRunner from "./HtmlRunner/HtmlRunner";

const RunnerFactory = ({ projectType }) => {
const Runner = () => {
if (projectType === "html") {
return HtmlRunner;
} else {
return PythonRunner;
return PyodideRunner;
}
};

Expand Down

0 comments on commit 3c484c3

Please sign in to comment.