diff --git a/Provider/Documentation/build_frontend.md b/Provider/Documentation/build_frontend.md index 33ab010..b29b728 100644 --- a/Provider/Documentation/build_frontend.md +++ b/Provider/Documentation/build_frontend.md @@ -69,7 +69,7 @@ Once the backend supports it (Phase 2+), you can update the frontend without usi 1. **Build the assets**: `npm run build:esp32` 2. **Package the image**: `npm run ota:package` - - This generates a `frontend/bin/www.bin` file. + - This generates a versioned binary in `frontend/bin/` (e.g., `www_v1.0.5.bin`). - **Configuration**: If the tool is not in your PATH, add its path to `frontend/.env`: ```env MKLITTLEFS_PATH=C:\path\to\mklittlefs.exe diff --git a/Provider/frontend/scripts/package.js b/Provider/frontend/scripts/package.js index 6024c88..48ed395 100644 --- a/Provider/frontend/scripts/package.js +++ b/Provider/frontend/scripts/package.js @@ -6,13 +6,13 @@ import { execSync } from 'child_process'; import { resolve, dirname } from 'path'; import { fileURLToPath } from 'url'; -import { existsSync, readFileSync, mkdirSync } from 'fs'; +import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs'; const __dirname = dirname(fileURLToPath(import.meta.url)); const projectRoot = resolve(__dirname, '..'); const distDir = resolve(projectRoot, 'dist'); const binDir = resolve(projectRoot, 'bin'); -const outputFile = resolve(binDir, 'www.bin'); +const versionFile = resolve(projectRoot, 'version.json'); // Ensure bin directory exists if (!existsSync(binDir)) { @@ -26,6 +26,33 @@ const PAGE_SIZE = 256; console.log('--- OTA Packaging ---'); +/** + * Handle versioning: Read current version + */ +function getVersion() { + if (existsSync(versionFile)) { + try { + return JSON.parse(readFileSync(versionFile, 'utf8')); + } catch (e) { + console.warn('Warning: Could not read version.json:', e.message); + } + } + return { major: 0, minor: 0, revision: 0 }; +} + +/** + * Increment and save revision + */ +function incrementVersion(version) { + try { + version.revision = (version.revision || 0) + 1; + writeFileSync(versionFile, JSON.stringify(version, null, 2)); + console.log(`Version incremented to: ${version.major}.${version.minor}.${version.revision} for next build.`); + } catch (e) { + console.warn('Warning: Could not update version.json:', e.message); + } +} + /** * Simple .env parser to load MKLITTLEFS_PATH without external dependencies */ @@ -51,6 +78,9 @@ function loadEnv() { } loadEnv(); +const version = getVersion(); +const versionStr = `${version.major}.${version.minor}.${version.revision}`; +const outputFile = resolve(binDir, `www_v${versionStr}.bin`); if (!existsSync(distDir)) { console.error('Error: dist/ directory not found. Run "npm run build:esp32" first.'); @@ -107,6 +137,9 @@ try { console.log(`Running: ${cmd}`); execSync(cmd, { stdio: 'inherit' }); console.log('Success: www.bin created.'); + + // Auto-increment for the next build + incrementVersion(version); } catch (e) { console.error('Error during packaging:', e.message); process.exit(1); diff --git a/Provider/frontend/src/App.svelte b/Provider/frontend/src/App.svelte index d807e55..7ba8160 100644 --- a/Provider/frontend/src/App.svelte +++ b/Provider/frontend/src/App.svelte @@ -57,12 +57,8 @@ } } - // Poll every 5 seconds - let pollInterval; $effect(() => { fetchInfo(); - pollInterval = setInterval(fetchInfo, 5000); - return () => clearInterval(pollInterval); }); const infoItems = $derived([ @@ -78,8 +74,8 @@
ESP32-S3 System Dashboard
+ESP32-S3 System Dashboard v{__APP_VERSION__}
@@ -169,11 +165,11 @@ Reboot
- Auto-refreshes every 5s -
- Update the dashboard UI without flashing the entire firmware. -
+- {errorMsg} -
- {/if} - {/if} -+ {errorMsg} +
+ {/if} + {/if} +