# App

**Namespace:** `FrymasterBadgeApp`  
**Base Class:** `Microsoft.Maui.Controls.Application`  
**Purpose:** MAUI application entry point. Handles theme persistence, dependency injection, and graceful startup error handling.

## 🔑 Fields
| Name | Type | Access | Description |
|------|------|--------|-------------|
| `_serviceProvider` | `IServiceProvider` | `private` | Holds the DI container used to resolve services like `AppShell`. |
| `ThemePrefKey` | `const string` | `public` | Constant key (`"AppTheme"`) used to store/retrieve theme preference. Must match `SettingsPage`. |

## 🛠 Constructor
### `App(IServiceProvider serviceProvider)`
- **Access:** `public`
- **Parameters:** `serviceProvider` (`IServiceProvider`)
- **Behavior:**
  1. Logs constructor start.
  2. Calls `InitializeComponent()` to load XAML UI.
  3. Applies saved theme via `ApplySavedTheme()`.
  4. Stores the injected `IServiceProvider`.
  5. Catches and logs fatal XAML initialization errors.

## 📦 Methods

### `ApplySavedTheme()`
- **Access:** `private`
- **Returns:** `void`
- **Behavior:**
  1. Reads `"AppTheme"` from `Preferences.Default`. Defaults to `"System"`.
  2. Maps string to `AppTheme` enum (`Light`, `Dark`, `Unspecified`).
  3. Sets `Application.Current.UserAppTheme`.
  4. Logs success or warns on failure.

### `CreateWindow(IActivationState? activationState)`
- **Access:** `protected override`
- **Parameters:** `activationState` (`IActivationState?`)
- **Returns:** `Window`
- **Behavior:**
  1. Resolves `AppShell` via `_serviceProvider`.
  2. Returns new `Window` containing resolved `AppShell`.
  3. If resolution fails, returns a fallback `ContentPage` with `"Startup Failed"` title, exception message in red, and log reference. Prevents hard crash.

---
**Key Features:**
- ✅ Theme persistence across sessions
- ✅ DI-ready shell resolution
- ✅ Graceful startup failure UI
- ✅ Comprehensive initialization logging