Merge pull request #1 from SergioGasquez/main

Use manifest and index
This commit is contained in:
Björn Quentin 2022-05-23 11:35:17 +02:00 committed by GitHub
commit 491ddd5509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,47 +46,121 @@ fn firmware(data: &State<PartsData>) -> Vec<u8> {
fn index() -> content::RawHtml<&'static str> { fn index() -> content::RawHtml<&'static str> {
content::RawHtml( content::RawHtml(
" "
<html> <html>
<script <body>
type=\"module\" <center>
src=\"https://unpkg.com/esp-web-tools@8.0.2/dist/web/install-button.js?module\"> <h1>ESP Web Flaher</h1>
</script>
<body>
<esp-web-install-button
manifest=\"/manifest.json\">
</esp-web-install-button>
</body> <div id=\"main\" style=\"display: none;\">
</html>
", <br>
<script type=\"module\" src=\"https://unpkg.com/esp-web-tools@8.0.2/dist/web/install-button.js?module\">
</script>
<esp-web-install-button id=\"installButton\" manifest=\"manifest.json\"></esp-web-install-button>
<br>
<span><i>NOTE: Make sure to close anything using your devices com port (e.g. Serial monitor)</i></span>
</div>
<div id=\"notSupported\" style=\"display: none;\">
Your browser does not support the Web Serial API. Try Chrome
</div>
</center>
<script>
if (navigator.serial) {
document.getElementById(\"notSupported\").style.display = 'none';
document.getElementById(\"main\").style.display = 'block';
} else {
document.getElementById(\"notSupported\").style.display = 'block';
document.getElementById(\"main\").style.display = 'none';
}
</script>
</body>
</html>
",
) )
} }
#[get("/manifest.json")] #[get("/manifest.json")]
fn manifest(data: &State<PartsData>) -> content::RawJson<String> { fn manifest() -> content::RawJson<&'static str> {
content::RawJson(format!( content::RawJson(
r#" r#"
{{ {
"name": "Something", "name": "ESP Application",
"version": "1", "new_install_prompt_erase": true,
"home_assistant_domain": "esphome", "builds": [
"funding_url": "https://esphome.io/guides/supporters.html", {
"new_install_prompt_erase": false, "chipFamily": "ESP32",
"builds": [ "parts": [
{{ {
"chipFamily": "{}", "path": "bootloader.bin",
"parts": [ "offset": 4096
{{ "path": "bootloader.bin", "offset": 4096 }}, },
{{ "path": "partitions.bin", "offset": 32768 }}, {
{{ "path": "firmware.bin", "offset": 65536 }} "path": "partitions.bin",
] "offset": 32768
}} },
] {
}} "path": "firmware.bin",
"#, "offset": 65536
data.chip }
)) ]
},
{
"chipFamily": "ESP32-C3",
"parts": [
{
"path": "bootloader.bin",
"offset": 0
},
{
"path": "partitions.bin",
"offset": 32768
},
{
"path": "firmware.bin",
"offset": 65536
}
]
},
{
"chipFamily": "ESP32-S2",
"parts": [
{
"path": "bootloader.bin",
"offset": 4096
},
{
"path": "partitions.bin",
"offset": 32768
},
{
"path": "firmware.bin",
"offset": 65536
}
]
},
{
"chipFamily": "ESP32-S3",
"parts": [
{
"path": "bootloader.bin",
"offset": 0
},
{
"path": "partitions.bin",
"offset": 32768
},
{
"path": "firmware.bin",
"offset": 65536
}
]
}
]
}
"#,
)
} }
struct PartsData { struct PartsData {