diff --git a/user_config/usr/share/newton/context_path/index.html b/user_config/usr/share/newton/context_path/index.html index 581effa..3b42269 100644 --- a/user_config/usr/share/newton/context_path/index.html +++ b/user_config/usr/share/newton/context_path/index.html @@ -73,17 +73,18 @@ + + + + + - - - - + + - - \ No newline at end of file diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js b/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js index 65653ef..0bbf39b 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js @@ -78,35 +78,8 @@ const importScriptFromNetwork = async (url) => { } -const importScriptFromScriptStr = async (scriptStr) => { - // Create a Blob with the text content and MIME type "text/javascript". - const blob = createScriptBlob(scriptStr); - - // Create an object URL from the Blob. - return createBlobURL(blob); -} - -const importScriptFromBackendResponse = async (scriptName, dataStr) => { - backendResponse = atob(dataStr); - scriptBlobURLs[scriptName] = await importScriptFromScriptStr(backendResponse); -} -const importJavaScriptFileFromBlobURL = async (objectURL) => { - // Create a new script element and set its src attribute to the object URL. - const scriptElement = document.createElement("script"); - scriptElement.src = objectURL; - - // Add a listener to revoke the object URL when the script has loaded. - // scriptElement.addEventListener("load", () => { - // URL.revokeObjectURL(objectURL); - // }); - - // Append the script element to the document to execute the JavaScript code. - document.body.appendChild(scriptElement); -} - - const importJavaScriptFile = async (url) => { - const objectURL = importScriptFromNetwork(url); + const objectURL = await importScriptFromNetwork(url); // Create a new script element and set its src attribute to the object URL. const scriptElement = document.createElement("script"); @@ -119,4 +92,32 @@ const importJavaScriptFile = async (url) => { // Append the script element to the document to execute the JavaScript code. document.body.appendChild(scriptElement); +} + +const importJavaScriptFileFromBlobURL = async (objectURL) => { + // Create a new script element and set its src attribute to the object URL. + const scriptElement = document.createElement("script"); + scriptElement.src = objectURL; + + // Add a listener to revoke the object URL when the script has loaded. + scriptElement.addEventListener("load", () => { + console.log("Loaded script..."); + // URL.revokeObjectURL(objectURL); + }); + + // Append the script element to the document to execute the JavaScript code. + document.body.appendChild(scriptElement); +} + +const importScriptFromScriptStr = async (scriptStr) => { + // Create a Blob with the text content and MIME type "text/javascript". + const blob = createScriptBlob(scriptStr); + + // Create an object URL from the Blob. + return createBlobURL(blob); +} + +const importScriptFromBackendResponse = async (scriptName, dataStr) => { + backendResponse = atob(dataStr); + scriptBlobURLs[scriptName] = await importScriptFromScriptStr(backendResponse); } \ No newline at end of file diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/events.js b/user_config/usr/share/newton/context_path/resources/js/newton/events.js index e2de7bc..9c8b057 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/events.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/events.js @@ -16,6 +16,7 @@ const loadLSPClientJSFiles = () => { const baseLink = `${window.location.href}resources/js/libs/ace_editor/lsp`; sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/ace-linters.js`, content = ""); + sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/base-service.js`, content = ""); sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/service-manager.js`, content = ""); sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/language-client.js`, content = ""); diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js index 5d0393e..814e508 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js @@ -67,28 +67,28 @@ const setSession = async (ftype, fhash, session) => { if (ftype === "python") { // const baseLink = "http://0.0.0.0:4880"; - //importJavaScriptFile(baseLink + "/ace-linters.js").then( - // importScripts("${await importScriptFromNetwork(baseLink + "/service-manager.js")}"); - // importScripts("${await importScriptFromNetwork(baseLink + "/python-service.js")}"); - // importScripts("${await importScriptFromNetwork(baseLink + "/language-client.js")}"); + // importJavaScriptFile(baseLink + "/ace-linters.js").then( importJavaScriptFileFromBlobURL( scriptBlobURLs["ace-linters.js"] ).then( async () => { + /* Works but isn't websocket */ + // manager.registerService("python", { + // module: () => { + // importScripts( "${ scriptBlobURLs["python-service.js"] }" ); + // return {PythonService}; + // }, + // className: "PythonService", + // modes: "python|python3", + // }); + + // importScripts("${await importScriptFromNetwork(baseLink + "/service-manager.js")}"); + // importScripts("${await importScriptFromNetwork(baseLink + "/python-service.js")}"); + // importScripts("${await importScriptFromNetwork(baseLink + "/language-client.js")}"); let workerString = ` !function () { importScripts( "${ scriptBlobURLs["service-manager.js"] }" ); let manager = new ServiceManager(self); - /* Works but isn't websocket */ - // manager.registerService("python", { - // module: () => { - // importScripts( "${ scriptBlobURLs["python-service.js"] }" ); - // return {PythonService}; - // }, - // className: "PythonService", - // modes: "python|python3", - // }); - /* Works and is websocket */ manager.registerServer("python", { module: () => { @@ -109,12 +109,19 @@ const setSession = async (ftype, fhash, session) => { }() `; - let worker = new Worker(createBlobURL(createScriptBlob(workerString))); + let worker = new Worker( + createBlobURL( + createScriptBlob(workerString) + ) + ); + let provider = LanguageProvider.create(worker); provider.registerEditor(editor); } - ); + ).catch((e) => { + console.log(e); + }); } }