-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
382 additions
and
139 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "static_html.h" | ||
|
||
|
||
String staticHTML_head() | ||
{ | ||
return String("<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef STATIC_HTML_H | ||
#define STATIC_HTML_H | ||
|
||
#include "../globals.h" | ||
|
||
String staticHTML_head(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "static_js.h" | ||
|
||
String staticJS_updates() | ||
{ | ||
String js = ""; | ||
js += "<script>"; | ||
js += "function i(t){return document.getElementById(t)}function r(t,e){return t=t.replace('v',''),e=e.replace('v',''),t.startsWith(e+'-')?-1:e.startsWith(t+'-')?1:t.localeCompare(e,void 0,{numeric:!0,sensitivity:'case',caseFirst:'upper'})}function o(t){return t.browser_download_url.split('/').pop()}async function getLatestGithubRelease(t){var e,a=await(await fetch('https://api.github.com/repos/speeduino/AirBear/releases/latest')).json(),n=a.tag_name;if(1==r(i('latest_release_txt').innerHTML=n,t)){i('update_btn').disabled=!1;for(const s of a.assets)s.name.includes('littlefs')?(e='http://speeduino.com/fw/AirBear/'+n+'/'+o(s),i('newData_url').value=e):(e='http://speeduino.com/fw/AirBear/'+n+'/'+o(s),i('newFW_url').value=e)}}async function scanWifi(){var t=i('ssid');for(const a of(await(await fetch('/wifi')).json()).networks){var e=document.createElement('option');e.value=a.ssid,e.text=a.ssid,t.add(e)}}function toggleData(){var t=i('newData_url');t.disabled=!t.disabled}function a(t,e){t.innerHTML=e}function updateProgress(){setTimeout(async()=>{let t;try{var e=await fetch('/updateStatus');t=await e.json()}catch(t){updateProgress()}t&&(a(i('updateStatus'),t.updateStatus),a(i('updateComplete'),t.updateProgress),a(i('updateSize'),t.updateSize),e=Math.floor(t.updateProgress/t.updateSize*100),a(i('updatePercent'),e),98<=e?window.location.href='/':updateProgress())},1500)}"; | ||
js += "</script>"; | ||
|
||
return js; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef STATIC_JS_H | ||
#define STATIC_JS_H | ||
|
||
#include "../globals.h" | ||
|
||
String staticJS_updates(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//This file is uglified using UglifyJS 3 and the config file within this directory. | ||
//The output of this is placed into static_js.cpp | ||
//This can be generaetd with the cmd: uglifyjs --config-file uglifyjs.config.json static_js.js | ||
|
||
function getElementByID(id) | ||
{ | ||
return document.getElementById(id) | ||
} | ||
|
||
|
||
function semverCompare(a, b) | ||
{ | ||
a = a.replace('v','') | ||
b = b.replace('v','') | ||
if (a.startsWith(b + '-')) return -1 | ||
if (b.startsWith(a + '-')) return 1 | ||
return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' }) | ||
} | ||
|
||
function getfileName(asset) | ||
{ | ||
return asset.browser_download_url.split('/').pop() | ||
} | ||
|
||
async function getLatestGithubRelease(currentVersion) | ||
{ | ||
const jsonData = await (await fetch('https://api.github.com/repos/speeduino/AirBear/releases/latest')).json(); | ||
const latestVersion = jsonData.tag_name; | ||
getElementByID('latest_release_txt').innerHTML = latestVersion | ||
if(semverCompare(latestVersion, currentVersion) == 1) //Value of 1 means a > b | ||
{ | ||
getElementByID('update_btn').disabled = false | ||
|
||
for(const asset of jsonData.assets) | ||
{ | ||
if(asset.name.includes('littlefs')) | ||
{ | ||
const newData_url = 'http://speeduino.com/fw/AirBear/' + latestVersion + '/' + getfileName(asset) | ||
getElementByID('newData_url').value = newData_url | ||
console.log("Data file: " + newData_url) | ||
} | ||
else | ||
{ | ||
const newFW_url = 'http://speeduino.com/fw/AirBear/' + latestVersion + '/' + getfileName(asset) | ||
getElementByID('newFW_url').value = newFW_url | ||
console.log("FW file: " + newFW_url) | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function scanWifi() | ||
{ | ||
const s = getElementByID('ssid') | ||
const jsonData = await (await fetch('/wifi')).json() | ||
for(const network of jsonData.networks) | ||
{ | ||
const opt = document.createElement('option'); | ||
opt.value = network.ssid; | ||
opt.text = network.ssid; | ||
s.add(opt) | ||
} | ||
} | ||
|
||
function toggleData() | ||
{ | ||
const dataField = getElementByID('newData_url') | ||
dataField.disabled = !dataField.disabled | ||
} | ||
|
||
function setInnerHTML(id, val) | ||
{ | ||
id.innerHTML = val | ||
} | ||
|
||
function updateProgress() | ||
{ | ||
setTimeout(async () => { | ||
let jsonData | ||
try { | ||
const response = await fetch('/updateStatus') | ||
jsonData = await response.json(); | ||
} | ||
catch (error) | ||
{ | ||
console.log(error) | ||
updateProgress() | ||
} | ||
|
||
if(jsonData) | ||
{ | ||
setInnerHTML(getElementByID('updateStatus'), jsonData.updateStatus) | ||
setInnerHTML(getElementByID('updateComplete'), jsonData.updateProgress) | ||
setInnerHTML(getElementByID('updateSize'), jsonData.updateSize) | ||
const percentComplete = Math.floor((jsonData.updateProgress / jsonData.updateSize) * 100) | ||
setInnerHTML(getElementByID('updatePercent'), percentComplete) | ||
console.log(percentComplete) | ||
if(percentComplete >= 98) { window.location.href = '/' } | ||
else { updateProgress() } | ||
} | ||
}, 1500); | ||
} |
Oops, something went wrong.