diff --git a/pio-scripts/output_bins.py b/pio-scripts/output_bins.py index 4d1594d843..d369ed7927 100644 --- a/pio-scripts/output_bins.py +++ b/pio-scripts/output_bins.py @@ -2,6 +2,7 @@ import os import shutil import gzip +import json OUTPUT_DIR = "build_output{}".format(os.path.sep) #OUTPUT_DIR = os.path.join("build_output") @@ -22,7 +23,8 @@ def create_release(source): release_name_def = _get_cpp_define_value(env, "WLED_RELEASE_NAME") if release_name_def: release_name = release_name_def.replace("\\\"", "") - version = _get_cpp_define_value(env, "WLED_VERSION") + with open("package.json", "r") as package: + version = json.load(package)["version"] release_file = os.path.join(OUTPUT_DIR, "release", f"WLED_{version}_{release_name}.bin") release_gz_file = release_file + ".gz" print(f"Copying {source} to {release_file}") diff --git a/pio-scripts/set_repo.py b/pio-scripts/set_metadata.py similarity index 69% rename from pio-scripts/set_repo.py rename to pio-scripts/set_metadata.py index c204c36370..7c8c223038 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,53 @@ 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 +# WLED version is managed by package.json; this is picked up in several places +# - It's integrated in to the UI code +# - Here, for wled_metadata.cpp +# - The output_bins script +# We always take it from package.json to ensure consistency +with open("package.json", "r") as package: + WLED_VERSION = json.load(package)["version"] + +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}\\\"")) + + cdefs.append(("WLED_VERSION", WLED_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'; + }); + }