From 20dd2fb9376bd93a4261e58612a8befc5969470d Mon Sep 17 00:00:00 2001 From: audioscavenger Date: Wed, 14 Oct 2020 19:57:51 -0700 Subject: [PATCH] upgraded to electron 10 - updated: settings, remote.screen, app.getName - index.html loads renderers just like main.js loads main-process - import.js imports html with XMLHttpRequest synchronously - main.js setup updated with worldSafeExecuteJavaScript, enableRemoteModule - devtron disabled Signed-off-by: audioscavenger --- assets/demo-btns.js | 6 +- assets/imports.js | 63 ++++++++++++++++--- assets/nav.js | 4 +- index.html | 10 +++ main-process/menus/application-menu.js | 3 +- main.js | 12 +++- package.json | 41 ++++++------ renderer-process/system/screen-information.js | 2 + 8 files changed, 102 insertions(+), 39 deletions(-) diff --git a/assets/demo-btns.js b/assets/demo-btns.js index b00c781f..146979c9 100644 --- a/assets/demo-btns.js +++ b/assets/demo-btns.js @@ -12,15 +12,15 @@ Array.prototype.forEach.call(demoBtns, (btn) => { // Saves the active demo if it is open, or clears it if the demo was user // collapsed by the user if (parent.classList.contains('is-open')) { - settings.set('activeDemoButtonId', event.target.getAttribute('id')) + settings.setSync('activeDemoButtonId', event.target.getAttribute('id')) } else { - settings.delete('activeDemoButtonId') + settings.unset('activeDemoButtonId') } }) }) // Default to the demo that was active the last time the app was open -const buttonId = settings.get('activeDemoButtonId') +const buttonId = settings.getSync('activeDemoButtonId') if (buttonId) { document.getElementById(buttonId).click() } diff --git a/assets/imports.js b/assets/imports.js index e5533445..213af9c4 100644 --- a/assets/imports.js +++ b/assets/imports.js @@ -1,12 +1,55 @@ -const links = document.querySelectorAll('link[rel="import"]') +// this is deprecated since M80 https://www.chromestatus.com/features/5144752345317376 +// const links = document.querySelectorAll('link[rel="import"]') -// Import and add each page to the DOM -Array.prototype.forEach.call(links, (link) => { - let template = link.import.querySelector('.task-template') - let clone = document.importNode(template.content, true) - if (link.href.match('about.html')) { - document.querySelector('body').appendChild(clone) - } else { - document.querySelector('.content').appendChild(clone) +// // Import and add each page to the DOM +// Array.prototype.forEach.call(links, (link) => { +// let template = link.import.querySelector('.task-template') +// let clone = document.importNode(template.content, true) +// if (link.href.match('about.html')) { +// document.querySelector('body').appendChild(clone) +// } else { +// document.querySelector('.content').appendChild(clone) +// console.log(clone) +// } +// }) + +// GET can be synchronous, which we want +// source: https://www.w3schools.com/howto/howto_html_include.asp +// JSDOM would achieve same result with nicer code but more overhead: https://www.twilio.com/blog/web-scraping-and-parsing-html-in-node-js-with-jsdom +function includeHTML() { + var links, i, elmnt, href, request; + /* Loop through a collection of all HTML elements: */ + links = document.querySelectorAll('link[rel="import"]'); + // console.log(links) + for (i = 0; i < links.length; i++) { + elmnt = links[i]; + /*search for elements with a certain atrribute:*/ + href = elmnt.getAttribute('href'); + // console.log(href) + if (href) { + /* Make an HTTP request using the attribute value as the file name: */ + request = new XMLHttpRequest(); + request.onreadystatechange = function() { + if (this.readyState == 4) { + if (this.status == 200) {elmnt.innerHTML = this.responseText;} + if (this.status == 404) {elmnt.innerHTML = "Page not found.";} + // console.log(elmnt) // + let template = elmnt.querySelector('.task-template') + let clone = document.importNode(template.content, true) + if (href.match('about.html')) { + document.querySelector('body').appendChild(clone) + } else { + document.querySelector('.content').appendChild(clone) + } + elmnt.remove(); + includeHTML(); + } + } + request.open("GET", href, false); // `false` makes the request synchronous + request.send(); + /* Exit the function: */ + return; + } } -}) +} +includeHTML(); diff --git a/assets/nav.js b/assets/nav.js index 08b4a705..13e203c9 100644 --- a/assets/nav.js +++ b/assets/nav.js @@ -22,7 +22,7 @@ function handleSectionTrigger (event) { // Save currently active button in localStorage const buttonId = event.target.getAttribute('id') - settings.set('activeSectionButtonId', buttonId) + settings.setSync('activeSectionButtonId', buttonId) } function activateDefaultSection () { @@ -65,7 +65,7 @@ function displayAbout () { } // Default to the view that was active the last time the app was open -const sectionId = settings.get('activeSectionButtonId') +const sectionId = settings.getSync('activeSectionButtonId') if (sectionId) { showMainContent() const section = document.getElementById(sectionId) diff --git a/index.html b/index.html index b5b8b8af..f3fd0e44 100644 --- a/index.html +++ b/index.html @@ -108,6 +108,16 @@