================================================================================
COMPLETE REFERENCE: Config Struct Analysis
================================================================================

Two comprehensive analysis documents have been created:

1. analysis.txt (212 lines)
   - Complete technical breakdown
   - All code paths with exact line numbers
   - Detailed freezing point mechanisms
   - Complete execution timeline
   - Comparison tables

2. ANALYSIS_SUMMARY.md (226 lines)
   - Executive summary
   - Quick-reference guide
   - Visual diagrams and flows
   - What needs to be fixed
   - Implementation requirements

ABSOLUTE PATHS:
C:\Users\DG2210\OneDrive - Gemeente Vught\Documenten\Git\I-SecretUpdate\analysis.txt
C:\Users\DG2210\OneDrive - Gemeente Vught\Documenten\Git\I-SecretUpdate\ANALYSIS_SUMMARY.md

================================================================================
THE PROBLEM IN ONE SENTENCE
================================================================================

Config is loaded ONCE at startup and frozen in immutable data structures,
with NO code to reload it during runtime.

================================================================================
THE SOLUTION IN ONE SENTENCE
================================================================================

Implement file watching, config reloading, and mutable storage patterns to
enable hot-reload of configuration changes.

================================================================================
CRITICAL FINDINGS CHECKLIST
================================================================================

[✓] Config loaded once in main.rs:54
[✓] Config values COPIED into BackgroundRenderer (app.rs:28-34)
[✓] BackgroundRenderer stored in Arc (immutable)
[✓] Config stored in AzureAppManager.config field (app.rs:49)
[✓] Every frame reads same frozen values (app.rs:375-457)
[✓] No reload mechanism exists (zero file watching code)
[✓] No polling of config.toml (no modification tracking)
[✓] Both cargo run and standalone behave identically
[✓] File location is the ONLY difference between them
[✓] Users perceive difference due to process restart frequency

================================================================================
CODE CHANGES NEEDED FOR HOT-RELOAD
================================================================================

1. Add to Cargo.toml:
   notify = "6.0"

2. Modify src/app.rs:
   - Change: config: Config
   - To:     config: Arc<Mutex<Config>>
   
   - Change: state.background_renderer storage
   - To:     Arc<Mutex<BackgroundRenderer>> or recreate every frame

3. Add config reload function in src/config/window_config.rs:
   - pub fn reload_config_from_disk() -> Config

4. Add file watcher in main loop:
   - Detect config.toml changes
   - Call reload_config_from_disk()
   - Update Arc<Mutex<Config>>
   - Call ctx.request_repaint()

5. Add synchronization:
   - Lock config before reading
   - Lock config before writing
   - Handle lock contention

================================================================================
EVIDENCE FOR ONE-TIME INITIALIZATION
================================================================================

SEARCH 1: "load_config" calls
  Result: Found in main.rs:54 only
  Conclusion: Called ONCE during startup

SEARCH 2: "config =" mutations
  Result: Configuration field never reassigned after app.rs:49
  Conclusion: Never updated after initialization

SEARCH 3: "notify", "watch", "polling", "reload"
  Result: NOT FOUND in codebase
  Conclusion: No hot-reload mechanism exists

SEARCH 4: "Arc<Mutex<Config>>"
  Result: NOT FOUND
  Conclusion: No mutable shared access pattern used

SEARCH 5: "file.metadata", "modification_time"
  Result: NOT FOUND
  Conclusion: No file change detection exists

================================================================================
EVIDENCE FOR FROZEN BACKGROUND RENDERER
================================================================================

FREEZE POINT: src/app.rs:28-34

let background_renderer = Some(Arc::new(BackgroundRenderer::new(
    &cc.egui_ctx,
    &config.appearance.background_image,
    config.appearance.background_opacity,      // ← COPIED
    config.appearance.fallback_color,           // ← COPIED
    config.appearance.fallback_color_opacity,   // ← COPIED
)));

RESULT:
- Values copied into struct at this point
- Stored in Arc (prevents mutation)
- Never recreated
- Never updated

USAGE: src/app.rs:506
if let Some(bg) = &self.state.background_renderer {
    bg.render_fullscreen(ctx);  // Uses frozen values
}

CALLED: Every frame in update() method
RESULT: Same frozen values rendered 60+ times per second

================================================================================
EVIDENCE FOR FROZEN CONFIG FIELD
================================================================================

STORAGE POINT: src/app.rs:49

pub struct AzureAppManager {
    config: Config,  // ← Stored as owned field
    // ...
}

Self {
    config,  // ← Stored once, never updated
    // ...
}

RESULT:
- Config struct stored as owned value
- Not Arc, not Mutex, not mutable reference
- Can only be read, never mutated
- Never reloaded from disk

USAGE POINTS:
- app.rs:380 - Read colors: let colors = self.config.colors.as_ref();
- app.rs:467 - Read text sizing: &self.config.text_sizing
- app.rs:489 - Read position: self.config.window.position_offset_x

CALLED: Every frame in update() method
RESULT: Same frozen config values read 60+ times per second

================================================================================
PATH RESOLUTION FOR BOTH ENVIRONMENTS
================================================================================

Code Location: src/config/window_config.rs:234-240

let config_path = if let Ok(exe_path) = std::env::current_exe() {
    exe_path
        .parent()
        .map(|p| p.join("config.toml"))
        .unwrap_or_else(|| Path::new("./config.toml").to_path_buf())
} else {
    Path::new("./config.toml").to_path_buf()
};

CARGO RUN:
Step 1: std::env::current_exe() returns target\debug\create-app-secret.exe
Step 2: parent() = target\debug\
Step 3: Look for target\debug\config.toml → NOT FOUND
Step 4: Fall back to ./config.toml
Step 5: Resolve in repo root → FOUND ✓
Step 6: Load config from repo root

Result: Config found and loaded from repo root

STANDALONE EXE:
Step 1: std::env::current_exe() returns exe directory path
Step 2: parent() = exe directory
Step 3: Look for config.toml in exe directory → MAYBE FOUND
Step 4: If not found, fall back to ./config.toml
Step 5: Resolve relative path
Step 6: Load config if found

Result: Config found in exe directory OR user's working directory

KEY POINT: Different file locations, but same code executes in both cases

================================================================================
WHY CARGO RUN APPEARS TO WORK
================================================================================

User Perspective:

1. cargo run
   - Application starts
   - Config loaded from repo root
   - Application displays settings
   
2. User modifies config.toml
   - Still running in background
   - Changes have NO effect (no reload mechanism)
   
3. cargo run (run command again)
   - OLD PROCESS EXITS
   - NEW PROCESS STARTS
   - load_config() called in new process
   - Reads UPDATED config.toml
   - Application displays new settings
   
4. User thinks: "Config changes work with cargo run!"

Reality: The application didn't reload. The user created a new process.

================================================================================
WHY STANDALONE EXE APPEARS BROKEN
================================================================================

User Perspective:

1. Run Create-App-Secret.exe
   - Application starts
   - Config loaded
   - Application displays settings
   
2. User modifies config.toml
   - Application still running
   - Changes have NO effect (no reload mechanism)
   - User expects application to update automatically
   
3. Application does NOT update
