diff --git a/pio-scripts/set_repo.py b/pio-scripts/set_metadata.py
similarity index 71%
rename from pio-scripts/set_repo.py
rename to pio-scripts/set_metadata.py
index c204c36370..f89b424c54 100644
--- a/pio-scripts/set_repo.py
+++ b/pio-scripts/set_metadata.py
@@ -1,5 +1,6 @@
Import('env')
import subprocess
+import json
import re
def get_github_repo():
@@ -42,7 +43,7 @@ def get_github_repo():
# Check if it's a GitHub URL
if 'github.com' not in remote_url.lower():
- return 'unknown'
+ return None
# Parse GitHub URL patterns:
# https://github.com/owner/repo.git
@@ -63,17 +64,56 @@ def get_github_repo():
if ssh_match:
return ssh_match.group(1)
- return 'unknown'
+ return None
except FileNotFoundError:
# Git CLI is not installed or not in PATH
- return 'unknown'
+ return None
except subprocess.CalledProcessError:
# Git command failed (e.g., not a git repo, no remote, etc.)
- return 'unknown'
+ return None
except Exception:
# Any other unexpected error
- return 'unknown'
+ return None
-repo = get_github_repo()
-env.Append(BUILD_FLAGS=[f'-DWLED_REPO=\\"{repo}\\"'])
\ No newline at end of file
+PACKAGE_FILE = "package.json"
+
+def get_version():
+ with open(PACKAGE_FILE, "r") as package:
+ return json.load(package)["version"]
+ return None
+
+
+def has_def(cppdefs, name):
+ """ Returns true if a given name is set in a CPPDEFINES collection """
+ for f in cppdefs:
+ if isinstance(f, tuple):
+ f = f[0]
+ if f == name:
+ return True
+ return False
+
+
+def add_wled_metadata_flags(env, node):
+ cdefs = env["CPPDEFINES"].copy()
+
+ if not has_def(cdefs, "WLED_REPO"):
+ repo = get_github_repo()
+ if repo:
+ cdefs.append(("WLED_REPO", f"\\\"{repo}\\\""))
+
+ if not has_def(cdefs, "WLED_VERSION"):
+ version = get_version()
+ if version:
+ cdefs.append(("WLED_VERSION", get_version()))
+
+ # This transforms the node in to a Builder; it cannot be modified again
+ return env.Object(
+ node,
+ CPPDEFINES=cdefs
+ )
+
+env.AddBuildMiddleware(
+ add_wled_metadata_flags,
+ "*/wled_metadata.cpp"
+)
diff --git a/pio-scripts/set_version.py b/pio-scripts/set_version.py
deleted file mode 100644
index 1d8e076ea8..0000000000
--- a/pio-scripts/set_version.py
+++ /dev/null
@@ -1,8 +0,0 @@
-Import('env')
-import json
-
-PACKAGE_FILE = "package.json"
-
-with open(PACKAGE_FILE, "r") as package:
- version = json.load(package)["version"]
- env.Append(BUILD_FLAGS=[f"-DWLED_VERSION={version}"])
diff --git a/platformio.ini b/platformio.ini
index d1b884b083..07760de037 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -110,8 +110,7 @@ ldscript_4m1m = eagle.flash.4m1m.ld
[scripts_defaults]
extra_scripts =
- pre:pio-scripts/set_version.py
- pre:pio-scripts/set_repo.py
+ pre:pio-scripts/set_metadata.py
post:pio-scripts/output_bins.py
post:pio-scripts/strip-floats.py
pre:pio-scripts/user_config_copy.py
diff --git a/tools/cdata.js b/tools/cdata.js
index c05b28e522..d2950ac162 100644
--- a/tools/cdata.js
+++ b/tools/cdata.js
@@ -388,12 +388,6 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
name: "PAGE_update",
method: "gzip",
filter: "html-minify",
- mangle: (str) =>
- str
- .replace(
- /function GetV().*\<\/script\>/gms,
- ""
- )
},
{
file: "welcome.htm",
diff --git a/wled00/data/update.htm b/wled00/data/update.htm
index 783a609ece..d8b8876ef2 100644
--- a/wled00/data/update.htm
+++ b/wled00/data/update.htm
@@ -17,7 +17,26 @@
}
window.open(getURL("/update?revert"),"_self");
}
- function GetV() {/*injected values here*/}
+ function GetV() {
+ // Fetch device info via JSON API instead of compiling it in
+ fetch('/json/info')
+ .then(response => response.json())
+ .then(data => {
+ document.querySelector('.installed-version').textContent = `${data.brand} ${data.ver} (${data.vid})`;
+ document.querySelector('.release-name').textContent = data.release;
+ // TODO - assemble update URL
+ // TODO - can this be done at build time?
+ if (data.arch == "esp8266") {
+ toggle('rev');
+ }
+ })
+ .catch(error => {
+ console.log('Could not fetch device info:', error);
+ // Fallback to compiled-in value if API call fails
+ document.querySelector('.installed-version').textContent = 'Unknown';
+ document.querySelector('.release-name').textContent = 'Unknown';
+ });
+ }