diff --git a/Desktop/UI/Globals.js b/Desktop/UI/Globals.js index 1890f2da3..90f9af4e0 100644 --- a/Desktop/UI/Globals.js +++ b/Desktop/UI/Globals.js @@ -1,10 +1,8 @@ -/* Global Constatns */ -let webApp -let PROJECTS_SCHEMA -let ENVIRONMENT - -/* New Root object*/ +/* Root object*/ let UI = { - projects: {} + projects: {}, + schemas: { projectSchema: undefined }, + environment: undefined, + running: {} } diff --git a/Desktop/UI/WebApp.js b/Desktop/UI/WebApp.js index 80e92cca4..eb18b803a 100644 --- a/Desktop/UI/WebApp.js +++ b/Desktop/UI/WebApp.js @@ -26,8 +26,8 @@ function newWebApp() { Here we will setup the UI object, with all the projects and spaces. */ - for (let i = 0; i < PROJECTS_SCHEMA.length; i++) { - let projectDefinition = PROJECTS_SCHEMA[i] + for (let i = 0; i < UI.schemas.projectSchema.length; i++) { + let projectDefinition = UI.schemas.projectSchema[i] UI.projects[projectDefinition.propertyName] = {} let projectInstance = UI.projects[projectDefinition.propertyName] diff --git a/Desktop/UI/WebAppLoader.js b/Desktop/UI/WebAppLoader.js index b86797e6d..cfdce582f 100644 --- a/Desktop/UI/WebAppLoader.js +++ b/Desktop/UI/WebAppLoader.js @@ -5,15 +5,12 @@ function newWebAppLoader() { loadModules: loadModules } - let postLoader return thisObject async function loadModules() { try { let modulesArray = [ 'WebDebugLog.js', - 'WebAppPostLoader.js', - 'Globals.js', 'WebApp.js' ] @@ -115,8 +112,8 @@ function newWebAppLoader() { if (downloadedCounter === modulesArray.length) { setTimeout(() => { - postLoader = newWebAppPostLoader() - postLoader.start() + UI.running.webApp = newWebApp() + UI.running.webApp.initialize() }, 500) } diff --git a/Desktop/UI/WebAppPostLoader.js b/Desktop/UI/WebAppPostLoader.js deleted file mode 100644 index a5f110bf6..000000000 --- a/Desktop/UI/WebAppPostLoader.js +++ /dev/null @@ -1,37 +0,0 @@ - - -function newWebAppPostLoader() { - - let thisObject = { - start: start - } - return thisObject - - function start() { - try { - - setupEnvironment() - - function setupEnvironment() { - httpRequest(undefined, 'Environment', onResponse) - - function onResponse(err, file) { - ENVIRONMENT = JSON.parse(file) - setupProjectsSchema() - } - } - - function setupProjectsSchema() { - httpRequest(undefined, 'ProjectsSchema', onResponse) - - function onResponse(err, file) { - PROJECTS_SCHEMA = JSON.parse(file) - webApp = newWebApp() - webApp.initialize() - } - } - } catch (err) { - console.log('[ERROR] err.stack = ' + err.stack) - } - } -} diff --git a/Desktop/UI/WebAppPreLoader.js b/Desktop/UI/WebAppPreLoader.js index 12e5fa54f..b3ea115ed 100644 --- a/Desktop/UI/WebAppPreLoader.js +++ b/Desktop/UI/WebAppPreLoader.js @@ -2,28 +2,36 @@ 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)) { + 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) } - loadModules() + loadGlobals() - function checkBrowserVersion () { + function loadGlobals() { + let path = "Globals.js" + REQUIREJS([path], onRequired) - 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]||'')} + function onRequired(pModule) { + setupEnvironment() } - if(M[1]==='Chrome'){ - tem=ua.match(/\bOPR|Edge\/(\d+)/) - if(tem!=null) {return {name:'Opera', version:tem[1]}} + } + + function setupEnvironment() { + httpRequest(undefined, 'Environment', onResponse) + + function onResponse(err, file) { + UI.environment = JSON.parse(file) + setupProjectsSchema() } - 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] + } + + function setupProjectsSchema() { + httpRequest(undefined, 'ProjectsSchema', onResponse) + + function onResponse(err, file) { + UI.schemas.projectSchema = JSON.parse(file) + loadModules() } } @@ -44,12 +52,12 @@ function httpRequest(pContentToSend, pPath, callBackFunction) { 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) + } 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 @@ -73,3 +81,22 @@ function httpRequest(pContentToSend, pPath, callBackFunction) { } } } + +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.js b/desktop.js index 3fe46bcf2..67f933c20 100644 --- a/desktop.js +++ b/desktop.js @@ -65,5 +65,5 @@ run() async function run() { DK.app = require('./Desktop/DesktopApp.js').newDesktopApp() await DK.app.run() - console.log('Superalgos Desktop App is Running.') + console.log('Superalgos Desktop App is Running!') }