diff --git a/CLAUDE.md b/CLAUDE.md index df30c02..c3a575a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -121,11 +121,28 @@ The entire Flask application lives in `rotary_phone_web.py` (~2000 lines). This - **Extra Button Sounds**: Separate PyAudio instance to prevent blocking main recording - **Hook Detection**: Direct GPIO reads during playback/recording loops for immediate response -### HTML Template Generation -The Flask app generates `templates/index.html` programmatically on first run. The template is defined as a string in the Python code and written to disk. To update the UI: -1. Delete `templates/` directory -2. Restart the application -3. Updated template will be regenerated +### HTML Template Generation and Versioning +The Flask app generates `templates/index.html` programmatically with automatic version tracking: + +**Version System:** +- `TEMPLATE_VERSION` constant (line ~84) tracks template changes +- Version embedded as HTML comment: `` +- `check_template_version()` compares embedded version with current code version +- Template auto-regenerates on version mismatch + +**How It Works:** +1. On startup, `check_template_version()` reads existing template +2. If version matches `TEMPLATE_VERSION`, template is up-to-date +3. If version mismatches or template missing, regeneration occurs automatically +4. User sees: "Template up-to-date (v1.3.0)" or "Template version mismatch - regenerating" + +**When to Update:** +- Increment `TEMPLATE_VERSION` whenever HTML/CSS/JS changes are made +- Format: "X.Y.Z" (major.minor.patch) +- Add comment describing the change + +**Manual Regeneration:** +If needed, delete `templates/` directory and restart - not required with version system ## Configuration diff --git a/rotary_phone_web.py b/rotary_phone_web.py index 634cb2b..07e4c86 100644 --- a/rotary_phone_web.py +++ b/rotary_phone_web.py @@ -80,6 +80,9 @@ BACKUP_ON_WRITE = BACKUP_CONFIG.get('backup_on_write', True) # Web server settings WEB_PORT = SYS_CONFIG['web']['port'] +# Template version - increment this when HTML template changes +TEMPLATE_VERSION = "1.3.0" # Updated: Added download all recordings feature + # Flask app app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = SYS_CONFIG['web']['max_upload_size_mb'] * 1024 * 1024 @@ -924,6 +927,22 @@ def get_local_ip(): except: return "127.0.0.1" +def check_template_version(template_file): + """Check if template needs regeneration based on version""" + if not os.path.exists(template_file): + return False # Template doesn't exist, needs creation + + try: + with open(template_file, 'r') as f: + content = f.read() + # Look for version comment in template + if f'' in content: + return True # Version matches, no regeneration needed + else: + return False # Version mismatch or missing, needs regeneration + except: + return False # Error reading, regenerate to be safe + def main(): """Main entry point for the wedding phone application""" # Create templates directory and HTML template @@ -931,14 +950,21 @@ def main(): templates_dir = os.path.join(script_dir, 'templates') os.makedirs(templates_dir, exist_ok=True) - # Create the HTML template if it doesn't exist + # Check if template needs regeneration template_file = os.path.join(templates_dir, 'index.html') - if not os.path.exists(template_file): - print(f"Creating template at {template_file}") + template_up_to_date = check_template_version(template_file) + + if not template_up_to_date: + if os.path.exists(template_file): + print(f"Template version mismatch - regenerating template at {template_file}") + else: + print(f"Creating new template at {template_file}") + with open(template_file, 'w') as f: - f.write(''' + f.write(f'''
+