Skip to content

Commit

Permalink
Fixed build for newest platformio-version. Removed deprecated flutter…
Browse files Browse the repository at this point in the history
… features
  • Loading branch information
dchristl committed Aug 24, 2024
1 parent 672746f commit cf77533
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 69 deletions.
6 changes: 3 additions & 3 deletions firmware/ESP32/src/openhaystack_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void set_payload_from_key(uint8_t *payload, uint8_t *public_key)
payload[29] = public_key[0] >> 6;
}

uint get_key_count()
uint8_t get_key_count()
{
uint8_t keyCount[1];
if (load_bytes_from_partition(keyCount, sizeof(keyCount), 0) != ESP_OK)
Expand All @@ -172,8 +172,8 @@ void app_main(void)
ESP_LOGI(LOG_TAG, "application initialized");

/* Start with a random index */
uint key_count = get_key_count();
uint key_index = (esp_random() % key_count);
uint8_t key_count = get_key_count();
uint8_t key_index = (esp_random() % key_count);
uint8_t cycle = 0;
while (true)
{
Expand Down
83 changes: 19 additions & 64 deletions macless_haystack/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,80 +23,35 @@
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="openhaystack_mobile">
<meta name="apple-mobile-web-app-title" content="macless_haystack">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<title>Macless Haystack</title>
<link rel="icon" href="favicon.png">
<link rel="manifest" href="manifest.json">

<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}

if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state === 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
}
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});

// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
}
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
});
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions macless_haystack/web/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "OpenHaystack2.0",
"description": "Macless Haystack",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
Expand All @@ -32,4 +32,4 @@
"purpose": "maskable"
}
]
}
}

0 comments on commit cf77533

Please sign in to comment.