From 8b8987dd28867d86bd88933336f6e91d9cf8e7aa Mon Sep 17 00:00:00 2001 From: TheGreyDiamond Date: Tue, 24 Nov 2020 17:07:23 +0100 Subject: [PATCH] last --- index.js | 87 +++++++++++++++++++++++++++++++++-------------- package-lock.json | 10 +++--- package.json | 3 +- 3 files changed, 69 insertions(+), 31 deletions(-) diff --git a/index.js b/index.js index 831fa5c..2d11e2f 100644 --- a/index.js +++ b/index.js @@ -4,23 +4,52 @@ const { win32 } = require("path"); const sysInf = require("systeminformation"); var aWin2 = undefined; -var header = undefined; -header = fs.readFileSync("ui_templates/header.html").toString(); +var preLoadedAmount = 0; /// !!!-----------!!! /// PAGE LOOKUP TABLE +var preloadedPageLookup = {}; + var pageLookup = {}; pageLookup["index"] = "index.html"; pageLookup["session"] = "sessions.html"; +pageLookup["header"] = "header.html" -fs.readFile('ui_templates/sessions.html', 'utf8', function (err,data) { + + +for (const [key, value] of Object.entries(pageLookup)) { + // check if the property/key is defined in the object itself, not in parent + if (pageLookup.hasOwnProperty(key)) { + fs.readFile('ui_templates/' + value, 'utf8', function (err,data) { + preLoadedAmount++; + if (err) { + return console.log(err); + } + preloadedPageLookup[key] = data; + + }); + } +} + +function loadPage(name){ + load = preloadedPageLookup[name] + if(load == undefined){ + load = fs.readFileSync("ui_templates/" + pageLookup[name]).toString(); + console.warn("Loading fallback for page " + name); + } + return(load) +} + +/* +fs.readFile('ui_templates/index.html', 'utf8', function (err,data) { + preLoadedAmount++; if (err) { return console.log(err); } - pageLookup["sessionPRELOAD"] = data; + preloadedPageLookup["index"] = data; }); - +*/ function createWindow() { const win = new BrowserWindow({ width: screen.getPrimaryDisplay().size.width, @@ -32,7 +61,10 @@ function createWindow() { win.setFullScreen(true); win.setMenuBarVisibility(false); win.setAutoHideMenuBar(true); - main = fs.readFileSync("ui_templates/index.html").toString(); + main = loadPage("index") + header = loadPage("header") + + // //header = fs.readFileSync("ui_templates/header.html").toString(); toLoad = header + main; fs.writeFileSync("ui_templates/temp.html", toLoad) @@ -60,23 +92,29 @@ function createStartupInfo() { function doneLoading() { var fadeOutI = 1; - aWin2.webContents.executeJavaScript( - "document.getElementById('current').innerHTML = 'Done';" - ); - var fadeIntervall = setInterval(function () { - try { - if (fadeOutI < 0) { + if(Object.keys(pageLookup).length == preLoadedAmount){ + aWin2.webContents.executeJavaScript( + "document.getElementById('current').innerHTML = 'Done';" + ); + var fadeIntervall = setInterval(function () { + try { + if (fadeOutI < 0) { + clearInterval(fadeIntervall); + aWin2.webContents.executeJavaScript("window.close()"); + } else { + aWin2.setOpacity(fadeOutI); + fadeOutI = fadeOutI - 0.05; + } + } catch (e) { + console.warn("Startup window got destroyed!"); clearInterval(fadeIntervall); - aWin2.webContents.executeJavaScript("window.close()"); - } else { - aWin2.setOpacity(fadeOutI); - fadeOutI = fadeOutI - 0.05; } - } catch (e) { - console.warn("Startup window got destroyed!"); - clearInterval(fadeIntervall); - } - }, 20); + }, 20); + }else{ + console.warn("Had to reschedule load finish") + setTimeout(doneLoading, 200); + } + //aWin2.webContents.executeJavaScript("window.close()") } @@ -141,10 +179,9 @@ function init() { }else if (String(arg).includes("PAGE:change")) { newPage = String(arg).split(".")[1] - main = pageLookup[newPage + "PRELOAD"] - if(main == undefined){ - main = fs.readFileSync("ui_templates/" + pageLookup[newPage]).toString(); - } + main = header = loadPage(newPage) + + header = loadPage("header") toLoad = header + main; fs.writeFileSync("ui_templates/temp.html", toLoad) win.loadFile("ui_templates/temp.html") diff --git a/package-lock.json b/package-lock.json index af0491a..62fb5d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -317,11 +317,6 @@ "minimatch": "^3.0.4" } }, - "font-awesome": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/font-awesome/-/font-awesome-4.7.0.tgz", - "integrity": "sha1-j6jPBBGhoxr9B7BtKQK7n8gVoTM=" - }, "fs-extra": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", @@ -752,6 +747,11 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, + "yarn": { + "version": "1.22.10", + "resolved": "https://registry.npmjs.org/yarn/-/yarn-1.22.10.tgz", + "integrity": "sha512-IanQGI9RRPAN87VGTF7zs2uxkSyQSrSPsju0COgbsKQOOXr5LtcVPeyXWgwVa0ywG3d8dg6kSYKGBuYK021qeA==" + }, "yauzl": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", diff --git a/package.json b/package.json index 2646644..4a523ef 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "dependencies": { "ejs": "^3.1.5", "electron": "^11.0.2", - "systeminformation": "^4.30.1" + "systeminformation": "^4.30.1", + "yarn": "^1.22.10" } }