From 9def104a84e44cb8843f25e567c1a0ea48c11bae Mon Sep 17 00:00:00 2001 From: Axel Date: Mon, 29 Nov 2021 23:00:23 -0300 Subject: [PATCH] Restore web server files --- Desktop/DesktopApp.js | 10 +-- Desktop/UI/Globals.js | 9 ++- Desktop/UI/WebApp.js | 18 +----- Desktop/UI/WebAppLoader.js | 52 ++++++++------- Desktop/UI/WebAppPreLoader.js | 116 ++++++++++++++++++++++++++++------ Desktop/config/paths.js | 9 ++- Desktop/public/index.html | 2 - 7 files changed, 145 insertions(+), 71 deletions(-) diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index f1afac09f..ceddff1da 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -73,11 +73,13 @@ exports.newDesktopApp = function newDesktopApp() { /* TODO refactor this into something better */ - require('./UI/WebAppPreLoader').loadSuperalgos(); - - /* let react = require('./scripts/start'); - react.start(JSON.parse(DK.desktopApp.p2pNetworkClient.node.config).webPort);*/ + /* + require('./src/UI/WebAppPreLoader').loadSuperalgos(); + */ + /* let react = require('./scripts/start'); + react.start(JSON.parse(DK.desktopApp.p2pNetworkClient.node.config).webPort); +*/ /* thisObject.httpInterface = DK.projects.socialTrading.modules.httpInterface.newDesktopModulesHttpInterface() thisObject.httpInterface.initialize()*/ diff --git a/Desktop/UI/Globals.js b/Desktop/UI/Globals.js index c78ce9079..3d3b69587 100644 --- a/Desktop/UI/Globals.js +++ b/Desktop/UI/Globals.js @@ -1,6 +1,6 @@ /* Root object*/ /* Root objects*/ -exports.UI = { +let UI = { projects: {}, schemas: { projectSchema: undefined }, environment: undefined, @@ -8,7 +8,10 @@ exports.UI = { webApp: undefined } -exports.SA = { projects: {} } - +let SA = { projects: {} } +/* +We will use this to load functions originally intended for Nodejs +*/ +let exports = {} diff --git a/Desktop/UI/WebApp.js b/Desktop/UI/WebApp.js index b4e634eff..cb4b4da43 100644 --- a/Desktop/UI/WebApp.js +++ b/Desktop/UI/WebApp.js @@ -5,7 +5,7 @@ function newWebApp() { Everything is being coded here until some structure emerges. */ let thisObject = { - messageReceived: messageReceived, + messageReceived: messageReceived, initialize: initialize, finalize: finalize } @@ -21,7 +21,6 @@ function newWebApp() { setupRootObject(UI, 'UI') setupRootObject(SA, 'SA') await UI.projects.socialTrading.modules.webSocketsWebAppClient.initialize() - // loadReactDom(); loadWUserProfileTimeline() loadWhoToFollow() setupEventHandlers() @@ -101,15 +100,6 @@ function newWebApp() { } } - async function loadReactDom() { - - reactReqs.ReactDOM.render( - reactReqs.ReactBase, - document.getElementById('root') - ); - - } - async function loadWUserProfileTimeline() { let queryMessage = { queryType: SA.projects.socialTrading.globals.queryTypes.EVENTS, @@ -173,7 +163,8 @@ function newWebApp() { postDiv.appendChild(textNode) contentDiv.appendChild(postDiv) } - } catch (err) { + } + catch (err) { console.log('[ERROR] err.stack = ' + err.stack) } } @@ -294,7 +285,6 @@ function newWebApp() { function updateTextArea() { textArea.value = "" } - break } case 'Follow Profile': { @@ -312,7 +302,6 @@ function newWebApp() { button.setAttribute("class", "profile-to-unfollow-button") button.name = 'Unfollow Profile' } - break } case 'Unfollow Profile': { @@ -330,7 +319,6 @@ function newWebApp() { button.setAttribute("class", "profile-to-follow-button") button.name = 'Follow Profile' } - break } } diff --git a/Desktop/UI/WebAppLoader.js b/Desktop/UI/WebAppLoader.js index 1d684c82a..ce4e46b77 100644 --- a/Desktop/UI/WebAppLoader.js +++ b/Desktop/UI/WebAppLoader.js @@ -1,29 +1,34 @@ -exports.newWebAppLoader = (UI) => { +function newWebAppLoader() { - try { - let modulesArray = [ - 'WebDebugLog.js', - 'WebApp.js' - ] + let thisObject = { + loadModules: loadModules + } - for (let i = 0; i < UI.schemas.projectSchema.length; i++) { - let project = UI.schemas.projectSchema[i] + return thisObject - if (project.UI !== undefined) { - if (project.UI.functionLibraries !== undefined) { - for (let j = 0; j < project.UI.functionLibraries.length; j++) { - let fileName = project.UI.functionLibraries[j].fileName - if (fileName === undefined) { - fileName = project.UI.functionLibraries[j].name.replaceAll(' ', '') + '.js' + async function loadModules() { + try { + let modulesArray = [ + 'WebDebugLog.js', + 'WebApp.js' + ] + + for (let i = 0; i < UI.schemas.projectSchema.length; i++) { + let project = UI.schemas.projectSchema[i] + + if (project.UI !== undefined) { + if (project.UI.functionLibraries !== undefined) { + for (let j = 0; j < project.UI.functionLibraries.length; j++) { + let fileName = project.UI.functionLibraries[j].fileName + if (fileName === undefined) {fileName = project.UI.functionLibraries[j].name.replaceAll(' ', '') + '.js'} + modulesArray.push('Projects' + '/' + project.name + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) } - modulesArray.push('Projects' + '/' + project.name + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) } - } - if (project.UI.utilities !== undefined) { - for (let j = 0; j < project.UI.utilities.length; j++) { - let fileName = project.UI.utilities[j].fileName - if (fileName === undefined) {fileName = project.UI.utilities[j].name.replaceAll(' ', '') + '.js'} + if (project.UI.utilities !== undefined) { + for (let j = 0; j < project.UI.utilities.length; j++) { + let fileName = project.UI.utilities[j].fileName + if (fileName === undefined) {fileName = project.UI.utilities[j].name.replaceAll(' ', '') + '.js'} modulesArray.push('Projects' + '/' + project.name + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName) } } @@ -104,9 +109,10 @@ exports.newWebAppLoader = (UI) => { } } } - } catch (err) { - console.log('[ERROR] loadModules -> err = ' + err.stack) - } + } catch (err) { + console.log('[ERROR] loadModules -> err = ' + err.stack) + } + } } diff --git a/Desktop/UI/WebAppPreLoader.js b/Desktop/UI/WebAppPreLoader.js index 95e218eec..548e3da05 100644 --- a/Desktop/UI/WebAppPreLoader.js +++ b/Desktop/UI/WebAppPreLoader.js @@ -1,33 +1,111 @@ -exports.loadSuperalgos = () => { + +function loadSuperalgos() { + + let browser = checkBrowserVersion() + if ((browser.name !== "Chrome" && browser.name !== "Safari") || (browser.name === "Chrome" && parseInt(browser.version) < 85) || (browser.name === "Safari" && parseInt(browser.version) < 13)) { + alert("Superalgos is officially supported on Google Chrome 85 or Safari 13.1 and above. Your browser version has been detected as potentially beneath this. If you continue you may experience some functionaility issues.\n\nDetected Browser: " + browser.name + "\nVersion: " + browser.version) + } loadGlobals() function loadGlobals() { - let {UI} = require('./Globals'); - setupEnvironment(UI); + let path = "Globals.js" + REQUIREJS([path], onRequired) + + function onRequired(pModule) { + setupEnvironment() + } } - function setupEnvironment(UI) { - let ENVIRONMENT = require('../../Environment'); - UI.environment = ENVIRONMENT.newEnvironment(); - setupClientNode(UI); + function setupEnvironment() { + httpRequest(undefined, 'Environment', onResponse) + + function onResponse(err, file) { + UI.environment = JSON.parse(file) + setupClientNode() + } } - function setupClientNode(UI) { - UI.clientNode = DK.desktopApp.p2pNetworkClient.node; - setupProjectsSchema(UI); + function setupClientNode() { + httpRequest(undefined, 'ClientNode', onResponse) + + function onResponse(err, file) { + UI.clientNode = JSON.parse(file) + setupProjectsSchema() + } } - function setupProjectsSchema(UI) { - UI.schemas.projectSchema = require('../../Projects/ProjectsSchema.json'); - loadModules(UI) + function setupProjectsSchema() { + httpRequest(undefined, 'ProjectsSchema', onResponse) + + function onResponse(err, file) { + UI.schemas.projectSchema = JSON.parse(file) + loadModules() + } } - function loadModules(UI) { - let react = require('../scripts/start'); - react.start(JSON.parse(DK.desktopApp.p2pNetworkClient.node.config).webPort); + function loadModules() { + let path = "WebAppLoader.js" + REQUIREJS([path], onRequired) - /* let APP_LOADER_MODULE = require('./WebAppLoader'); - APP_LOADER_MODULE.newWebAppLoader(UI);*/ + function onRequired(pModule) { + let APP_LOADER_MODULE = newWebAppLoader() + APP_LOADER_MODULE.loadModules() + } } -} \ No newline at end of file +} + +function httpRequest(pContentToSend, pPath, callBackFunction) { + let xmlHttpRequest = new XMLHttpRequest() + xmlHttpRequest.onreadystatechange = function () { + if (this.readyState === 4 && this.status === 200) { + try { + callBackFunction(undefined, xmlHttpRequest.responseText) + } catch (err) { + console.log('[ERROR] httpRequest -> httpRequest -> err.stack = ' + err.stack) + console.log('[ERROR] httpRequest -> httpRequest -> pContentToSend = ' + pContentToSend) + console.log('[ERROR] httpRequest -> httpRequest -> pPath = ' + pPath) + console.log('[ERROR] httpRequest -> httpRequest -> xmlHttpRequest.responseText = ' + xmlHttpRequest.responseText) + console.log('[ERROR] httpRequest -> httpRequest -> callBackFunction = ' + callBackFunction) + + } + return + } else if (this.readyState === 4 && this.status === 404) { + callBackFunction({ result: "Fail", message: xmlHttpRequest.responseText.trim(), code: xmlHttpRequest.responseText.trim() }) + return + } + } + + if (pContentToSend === undefined) { + xmlHttpRequest.open("GET", pPath, true) + xmlHttpRequest.send() + } else { + try { + let blob = new Blob([pContentToSend], { type: 'text/plain' }) + xmlHttpRequest.open("POST", pPath, true) + xmlHttpRequest.send(blob) + } catch (err) { + if (ERROR_LOG === true) { console.log("[ERROR] callServer -> err.message = " + err.message) } + callBackFunction({ result: "Fail", message: err.message }) + } + } +} + +function checkBrowserVersion() { + + let ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [] + if (/trident/i.test(M[1])) { + tem = /\brv[ :]+(\d+)/g.exec(ua) || [] + return { name: 'IE', version: (tem[1] || '') } + } + if (M[1] === 'Chrome') { + tem = ua.match(/\bOPR|Edge\/(\d+)/) + if (tem != null) { return { name: 'Opera', version: tem[1] } } + } + M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'] + if ((tem = ua.match(/version\/(\d+)/i)) != null) { M.splice(1, 1, tem[1]) } + return { + name: M[0], + version: M[1] + } +} diff --git a/Desktop/config/paths.js b/Desktop/config/paths.js index 8df8e760e..beb561b99 100644 --- a/Desktop/config/paths.js +++ b/Desktop/config/paths.js @@ -62,12 +62,11 @@ module.exports = { appPackageJson: resolveApp('package.json'), appSrc: resolveApp('Desktop/src'), appNodeModules: resolveApp('node_modules'), - globals: resolveApp('Desktop/UI/Globals'), - projects: resolveApp('Projects'), - environment: resolveApp('Environments'), - schema: resolveApp('Projects/ProjectsSchema'), publicUrlOrPath, }; - +/* globals: resolveApp('Desktop/UI/Globals'), + projects: resolveApp('Projects'), + environment: resolveApp('Environments'), + schema: resolveApp('Projects/ProjectsSchema'),*/ module.exports.moduleFileExtensions = moduleFileExtensions; diff --git a/Desktop/public/index.html b/Desktop/public/index.html index 81a214993..81b324ffe 100644 --- a/Desktop/public/index.html +++ b/Desktop/public/index.html @@ -6,10 +6,8 @@ - -