-
diff --git a/data-src/index.js b/data-src/index.js
index 06a09ec..444b929 100644
--- a/data-src/index.js
+++ b/data-src/index.js
@@ -579,9 +579,6 @@ async function initSockets() {
case 'memStatus':
firmware.procMemoryStatus(msg);
break;
- case 'updateProgress':
- firmware.procUpdateProgress(msg);
- break;
case 'fwStatus':
firmware.procFwStatus(msg);
break;
@@ -4569,268 +4566,11 @@ class Firmware {
}
procFwStatus(rel) {
- console.log(rel);
let div = document.getElementById('divFirmwareUpdate');
- if (rel.available && rel.status === 0 && rel.checkForUpdate !== false) {
- div.style.color = 'black';
- div.innerHTML = `Firmware ${rel.fwVersion.name} Installed ${rel.latest.name} Available`;
- }
- else {
- switch (rel.status) {
- case 2: // Awaiting update.
- div.style.color = 'red';
- div.innerHTML = `Preparing firmware update`;
- break;
- case 3: // Updating -- this will be set by the update progress.
- break;
- case 4: // Complete
- if (rel.error !== 0) {
- div.style.color = 'red';
- let e = errors.find(x => x.code === rel.error) || { code: rel.error, desc: 'Unspecified error' };
- let inst = document.getElementById('divGitInstall');
- if (inst) {
- inst.remove();
- ui.errorMessage(e.desc);
- }
- div.innerHTML = e.desc;
- }
- else {
- div.innerHTML = `Firmware update complete`;
- // Throw up a wait message this will be cleared on the reload.
- ui.waitMessage(document.getElementById('divContainer'));
- }
- break;
- case 5:
- div.style.color = 'red';
- div.innerHTML = `Cancelling firmware update`;
- break;
- case 6:
- div.style.color = 'red';
- div.innerHTML = `Firmware update cancelled`;
- break;
-
- default:
- div.style.color = 'black';
- div.innerHTML = `Firmware ${rel.fwVersion.name} Installed`;
- break;
- }
- }
+ div.style.color = 'black';
+ div.innerHTML = `Firmware ${rel.fwVersion.name} Installed`;
div.style.display = '';
}
- procUpdateProgress(prog) {
- let pct = Math.round((prog.loaded / prog.total) * 100);
- let file = prog.part === 100 ? 'Application' : 'Firmware';
- let div = document.getElementById('divFirmwareUpdate');
- if (div) {
- div.style.color = 'red';
- div.innerHTML = `Updating ${file} to ${prog.ver} ${pct}%`;
- }
- general.reloadApp = true;
- let git = document.getElementById('divGitInstall');
- if (git) {
- // Update the status on the client that started the install.
- if (pct >= 100 && prog.part === 100) git.remove();
- else {
- if (prog.part === 100) {
- document.getElementById('btnCancelUpdate').style.display = 'none';
- }
- let p = prog.part === 100 ? document.getElementById('progApplicationDownload') : document.getElementById('progFirmwareDownload');
- if (p) {
- p.style.setProperty('--progress', `${pct}%`);
- p.setAttribute('data-progress', `${pct}%`);
- }
- }
- }
-
- }
- async installGitRelease(div) {
- if (!this.isMobile()) {
- console.log('Starting backup');
- try {
- await firmware.backup();
- console.log('Backup Complete');
- }
- catch (err) {
- ui.serviceError(el, err);
- return;
- }
- }
-
- let obj = ui.fromElement(div);
- console.log(obj);
- putJSONSync(`/downloadFirmware?ver=${obj.version}`, {}, (err, ver) => {
- if (err) ui.serviceError(err);
- else {
- general.reloadApp = true;
- // Change the display and allow the percentage to be shown when the socket emits the progress.
- let html = `
Installing ${ver.name}
Please wait as the files are downloaded and installed. Once the application update process starts you may no longer cancel the update as this will corrupt the downloaded files.
`;
- html += ``;
- html += ``;
- html += ``;
- html += ``;
- html += `
`;
- html += ``;
- html += `
`;
- div.innerHTML = html;
- }
- });
- }
- cancelInstallGit(div) {
- putJSONSync(`/cancelFirmware`, {}, (err, ver) => {
- if (err) ui.serviceError(err);
- else console.log(ver);
- div.remove();
- });
- }
- updateGithub() {
- getJSONSync('/getReleases', (err, rel) => {
- if (err) ui.serviceError(err);
- else {
- console.log(rel);
- let div = document.createElement('div');
- let chip = document.getElementById('divContainer').getAttribute('data-chipmodel');
- div.setAttribute('id', 'divGitInstall')
- div.setAttribute('class', 'inst-overlay');
- div.style.width = '100%';
- div.style.alignContent = 'center';
- // Sort the releases so that the pre-releases are at the bottom.
- rel.releases.sort((a, b) => a.preRelease === b.preRelease && b.draft === a.draft ? 0 : a.preRelease ? 1 : -1);
-
- let html = `
Select a version from the repository to install using the dropdown below. Then press the update button to install that version.
Select Main to install the most recent alpha version from the repository.
`;
- html += `
WARNING
You have selected a pre-released beta version that has not been fully tested or published for general use.
`;
- html += `
`;
- html += `
`;
- html += ``;
- if (this.isMobile()) {
- html += `
WARNING
`;
- html += '
This browser does not support automatic backups. It is highly recommended that you back up your configuration using the backup button before proceeding.
';
- }
- else {
- html += '
A backup file for your configuration will be downloaded to your browser. If the firmware update process fails please restore this file using the restore button after going through the onboarding process.
'
- }
- html += `
`;
- if (this.isMobile()) {
- html += ``;
- }
- html += ``;
- html += ``;
-
- html += `
`;
-
- div.innerHTML = html;
- document.getElementById('divContainer').appendChild(div);
- this.gitReleaseSelected(div);
- }
- });
-
- }
- gitReleaseSelected(div) {
- let obj = ui.fromElement(div);
- let divNotes = div.querySelector('#divReleaseNotes');
- let divPre = div.querySelector('#divPrereleaseWarning');
-
- let sel = div.querySelector('#selVersion');
- if (sel && sel.selectedIndex !== -1 && makeBool(sel.options[sel.selectedIndex].getAttribute('data-prerelease'))) {
- if (divPre) divPre.style.display = '';
- }
- else
- if (divPre) divPre.style.display = 'none';
-
- if (divNotes) {
- if (!obj.version || obj.version === 'main' || obj.version === '') divNotes.style.display = 'none';
- else divNotes.style.display = '';
- }
- }
- async getReleaseInfo(tag) {
- let overlay = ui.waitMessage(document.getElementById('divContainer'));
- try {
- let ret = {};
- ret.resp = await fetch(`https://api.github.com/repos/cjkas/espsomfy-rts/releases/tags/${tag}`);
- if (ret.resp.ok)
- ret.info = await ret.resp.json();
- return ret;
- }
- catch (err) {
- return { err: err };
- }
- finally { overlay.remove(); }
- }
- async showReleaseNotes(tagName) {
- console.log(tagName);
- let r = await this.getReleaseInfo(tagName);
- console.log(r);
- let fnToItem = (txt, tag) => { }
- if (r.resp.ok) {
- // Convert this to html.
- let lines = r.info.body.split('\r\n');
- let ctx = { html: '', llvl: 0, lines: r.info.body.split('\r\n'), ndx: 0 };
- ctx.toHead = function (txt) {
- let num = txt.indexOf(' ');
- return `${txt.substring(num).trim()}`;
- };
- ctx.toUL = function () {
- let txt = this.lines[this.ndx++];
- let tok = this.token(txt);
- this.html += `
${this.toLI(tok.txt)}`;
- while (this.ndx < this.lines.length) {
- txt = this.lines[this.ndx];
- let t = this.token(txt);
- if (t.ch === '*') {
- if (t.indent !== tok.indent) this.toUL();
- else {
- this.html += this.toLI(t.txt);
- this.ndx++;
- }
- }
- else break;
- }
- this.html += '
';
- };
- ctx.toLI = function (txt) { return `
${txt.trim()}
`; }
- ctx.token = function (txt) {
- let tok = { ch: '', indent: 0, txt:'' }
- for (let i = 0; i < txt.length; i++) {
- if (txt[i] === ' ') tok.indent++;
- else {
- tok.ch = txt[i];
- let tmp = txt.substring(tok.indent);
- tok.txt = tmp.substring(tmp.indexOf(' '));
- break;
- }
- }
- return tok;
- };
- ctx.next = function () {
- if (this.ndx >= this.lines.length) return false;
- let tok = this.token(this.lines[this.ndx]);
- switch (tok.ch) {
- case '#':
- this.html += this.toHead(this.lines[this.ndx]);
- this.ndx++;
- break;
- case '*':
- this.toUL();
- break;
- case '':
- this.ndx++;
- this.html += `