# Feature Implementation Plan

This document outlines the implementation plan for 4 new features to be added to MPV.Rocks Manager.

---

## Feature 1: `save-position-on-quit` Config Setting

### Overview
Add a new MPV config setting option to both Web UI and TUI that allows users to configure `save-position-on-quit`. Default is `no`, with option to change to `yes`.

### Explanation Text
> "When enabled, MPV will remember your playback position when you quit. The next time you open the same file, playback will resume from where you left off."

### Implementation Details

#### 1.1 Constants (`pkg/constants/constants.go`)
Add new constant:
```go
ConfigKeySavePositionOnQuit = "save-position-on-quit"
```

#### 1.2 Config Settings Model (`pkg/web/models.go`)
Add to `ConfigSettings` struct:
```go
SavePositionOnQuit string
```

#### 1.3 Web UI - Template (`internal/webassets/templates/config.html`)
Add new section in "Additional Settings":
```html
<div>
    <label class="block text-sm font-medium text-gray-300 mb-2">
        Save Position on Quit
    </label>
    <select id="save-position-on-quit" name="save_position_on_quit"
            class="w-full bg-gray-700 text-white rounded-lg px-4 py-2...">
        <option value="no" {{if eq .Config.SavePositionOnQuit "no"}}selected{{end}}>No (Default)</option>
        <option value="yes" {{if eq .Config.SavePositionOnQuit "yes"}}selected{{end}}>Yes</option>
    </select>
    <p class="text-xs text-gray-400 mt-1">
        When enabled, MPV remembers your playback position. Resume where you left off next time.
    </p>
</div>
```

#### 1.4 Web UI - API Handler (`pkg/web/api.go`)
- Add `SavePositionOnQuit` to `ConfigApplyRequest` struct
- Update `handleConfigApplyAPI()` to read and save the setting
- Update `handleConfigSettingsAPI()` to return current value

#### 1.5 Web UI - JavaScript (`internal/webassets/templates/config.html`)
Add to the JSON payload in `applySettings()`:
```javascript
save_position_on_quit: document.getElementById('save-position-on-quit').value
```

#### 1.6 Default MPV Config (`internal/assets/mpv.conf`)
Add default setting:
```conf
# Remember playback position on quit
save-position-on-quit=no
```

#### 1.7 TUI Implementation (`pkg/tui/`)
- Add new state for editing save-position-on-quit option
- Add menu item in config options
- Handle user input for yes/no selection

### Files to Modify
- `pkg/constants/constants.go` - Add config key constant
- `pkg/web/models.go` - Add to ConfigSettings struct
- `pkg/web/api.go` - Handle API requests
- `internal/webassets/templates/config.html` - Add UI element
- `internal/assets/mpv.conf` - Add default setting
- `pkg/tui/models.go` - Add state
- `pkg/tui/hwaccel_config.go` - Add menu option
- `pkg/tui/models_views.go` - Render option
- `pkg/tui/models_update.go` - Handle input

---

## Feature 2: MPV Keyboard Shortcuts Page

### Overview
Create a new page showing all MPV hotkeys/keyboard shortcuts. The list should be searchable/filterable with common shortcuts at the top. Web UI should have stylized keyboard keys.

### Implementation Details

#### 2.1 Data Structure (`pkg/hotkeys/hotkeys.go`)
Create new package with hotkey data:
```go
package hotkeys

type Hotkey struct {
    Key         string   // The key combination
    Description string   // What it does
    Category    string   // "playback", "seeking", "audio", "subtitle", etc.
    Priority    int      // Higher = shown first (common shortcuts)
    Aliases     []string // For search purposes
}

var Hotkeys = []Hotkey{
    {Key: "SPACE / p", Description: "Pause/Resume playback", Category: "playback", Priority: 100},
    {Key: "q", Description: "Stop playing and quit", Category: "playback", Priority: 100},
    {Key: "f", Description: "Toggle fullscreen", Category: "display", Priority: 90},
    // ... all other hotkeys from user's list
}
```

#### 2.2 Categories
Organize hotkeys into categories:
- **Playback** (highest priority): SPACE, p, q, Q, m, ., ,, l, L
- **Seeking**: LEFT, RIGHT, UP, DOWN, HOME, PGUP, PGDWN, BACKSPACE
- **Audio/Volume**: /, *, 9, 0, #, _, Ctrl++/-
- **Subtitles**: v, Alt+v, j, J, z, Z, G, F, r, R, u, V
- **Video/Display**: f, ESC, T, w, W, A, Alt+arrows, Alt++/-
- **Screenshots**: s, S, Ctrl+s
- **Playlist**: <, >, ENTER, Shift+HOME, Shift+END, F8
- **Advanced**: i, I, ?, d, b, Ctrl+h, DEL, `
- **Menus**: g-p, g-s, g-a, g-v, etc.

#### 2.3 Web UI - Navigation (`pkg/web/models.go`)
Add to `NavItems`:
```go
{Icon: template.HTML("<i class='bx bx-keyboard'></i>"), Name: "Keyboard Shortcuts", URL: "/hotkeys"},
```

#### 2.4 Web UI - Template (`internal/webassets/templates/hotkeys.html`)
Create new template with:
- Search/filter input
- Category filter buttons
- Stylized keyboard keys using CSS

CSS for keyboard keys:
```css
.kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    padding: 0.25rem 0.5rem;
    background: linear-gradient(180deg, #4a4a4a 0%, #3a3a3a 100%);
    border: 1px solid #5a5a5a;
    border-radius: 4px;
    box-shadow: 0 2px 0 #2a2a2a;
    font-family: monospace;
    font-size: 0.875rem;
    color: #fff;
}
.kbd-group {
    display: inline-flex;
    gap: 0.25rem;
}
```

#### 2.5 Web UI - Route & Handler (`pkg/web/server.go`, `pkg/web/api.go`)
```go
mux.HandleFunc("/hotkeys", s.handleHotkeys)

func (s *Server) handleHotkeys(w http.ResponseWriter, r *http.Request) {
    // Render hotkeys page
}
```

#### 2.6 TUI Implementation
- Add new state `StateHotkeys`
- Add menu item in main menu
- Implement search/filter with text input
- Display list with keyboard-friendly navigation

### Files to Create
- `pkg/hotkeys/hotkeys.go` - Hotkey data and search functions
- `internal/webassets/templates/hotkeys.html` - Web UI template

### Files to Modify
- `pkg/web/models.go` - Add NavItem
- `pkg/web/server.go` - Add route
- `pkg/tui/models.go` - Add state
- `pkg/tui/models_views.go` - Render hotkeys view
- `pkg/tui/models_update.go` - Handle navigation

---

## Feature 3: Custom MPV UI Selection (UOSC / ModernZ)

### Overview
Add the ability to select between UOSC (current default) and ModernZ as the custom UI for MPV installs. This should work at install time and post-install via a button in the MPV app entry.

### ModernZ Requirements
- **Files needed:**
  - `modernz.lua` → `scripts/modernz.lua`
  - `fluent-system-icons.ttf` → `fonts/fluent-system-icons.ttf`
  - `material-design-icons.ttf` → `fonts/material-design-icons.ttf`
  - `thumbfast.lua` (optional) → `scripts/thumbfast.lua`
  - `modernz.conf` → `script-opts/modernz.conf`
- **Config change:** `osc=no` in mpv.conf (different from UOSC which uses `osc=yes`)
- **Source:** https://github.com/Samillion/ModernZ

### Implementation Details

#### 3.1 ReleaseInfo Structure Updates

**cmd/generate-info/main.go:**
```go
type Release struct {
    // ... existing fields ...
    UOSC struct { ... } `json:"uosc"`
    ModernZ struct {
        URL                    string `json:"url"`
        BLAKE3                 string `json:"blake3"`
        ConfURL                string `json:"conf_url"`
        ConfBLAKE3             string `json:"conf_blake3"`
        IconsFluentURL         string `json:"icons_fluent_url"`
        IconsFluentBLAKE3      string `json:"icons_fluent_blake3"`
        IconsMaterialURL       string `json:"icons_material_url"`
        IconsMaterialBLAKE3    string `json:"icons_material_blake3"`
        AppVersion             string `json:"app_version"`
    } `json:"modernz"`
    Thumbfast struct {
        URL        string `json:"url"`
        BLAKE3     string `json:"blake3"`
        AppVersion string `json:"app_version"`
    } `json:"thumbfast"`
}
```

**pkg/installer/installer.go:**
Mirror the same structure in `ReleaseInfo`

#### 3.2 Installer Config Tracking (`pkg/config/config.go`)
Add field to track installed UI:
```go
type InstalledApp struct {
    // ... existing fields ...
    CustomUI string `json:"custom_ui,omitempty"` // "uosc" or "modernz"
}
```

#### 3.3 UI Selection Modal

**Modal Type:**
```go
ModalTypeSelectCustomUI = "select-custom-ui"
```

**Modal Content:**
- Title: "Select MPV Custom UI"
- Two options displayed as cards:
  - **UOSC**: Description, (placeholder for screenshot)
  - **ModernZ**: Description, (placeholder for screenshot)
- Buttons: "Install UOSC", "Install ModernZ", "Cancel"

#### 3.4 Installer Functions (`pkg/installer/installer.go`)

```go
func (i *Installer) InstallModernZWithOutput(cr *CommandRunner, installDir string) error {
    // Download modernz.zip
    // Download fonts
    // Download modernz.conf
    // Extract to correct directories
    // Set osc=no in mpv.conf
}

func (i *Installer) InstallThumbfastWithOutput(cr *CommandRunner, installDir string) error {
    // Optional: Download and install thumbfast.lua
}
```

#### 3.5 Config Editor Updates (`pkg/config/editor.go`)
```go
func SetOSCEnabled(configPath string, enabled bool) error {
    // Set osc=yes or osc=no
}
```

#### 3.6 Web UI - Install Flow
1. User clicks "Install" on MPV
2. Show modal asking which custom UI to install
3. User selects UOSC or ModernZ
4. Installation proceeds with selected UI
5. Track selection in config

#### 3.7 Web UI - Post-Install Change UI
1. Add "Change UI" button on MPV app entry (only for non-wrapped installs)
2. Button opens the same UI selection modal
3. After selection:
   - Remove old UI files
   - Update mpv.conf (osc=yes for UOSC, osc=no for ModernZ)
   - Install new UI files
   - Update config with new custom_ui value

#### 3.8 TUI Implementation
- Add UI selection step during install
- Add "Change UI" option in installed app details
- Handle UI switching

### Files to Create
- `pkg/installer/modernz.go` - ModernZ installation logic

### Files to Modify
- `cmd/generate-info/main.go` - Add ModernZ/Thumbfast to release structure
- `pkg/installer/installer.go` - Add ModernZ to ReleaseInfo
- `pkg/config/config.go` - Add CustomUI field
- `pkg/config/editor.go` - Add OSC toggle function
- `pkg/web/api.go` - Add UI selection modal and handlers
- `pkg/web/models.go` - Add modal type
- `pkg/constants/constants.go` - Add modal type constant
- `internal/webassets/templates/apps.html` - Add "Change UI" button
- `internal/webassets/templates/modal.html` - Add UI selection modal
- `pkg/installer/windows.go`, `linux.go`, `macos.go` - Call correct UI installer
- TUI files for install flow

---

## Feature 4: Update Checking for UOSC, ModernZ, FFmpeg

### Overview
Add the ability to check for and update UOSC, ModernZ, and FFmpeg versions separately from MPV app updates. These should appear in the "Check for Updates" flow but not be listed as installed apps.

### Implementation Details

#### 4.1 Version Tracking (`pkg/config/config.go`)
```go
type ComponentVersion struct {
    Name    string `json:"name"`
    Version string `json:"version"`
    Updated string `json:"updated"` // ISO date
}

type Config struct {
    // ... existing fields ...
    ComponentVersions []ComponentVersion `json:"component_versions,omitempty"`
}
```

#### 4.2 Update Check Logic (`pkg/web/api.go`)
Extend `handleCheckUpdatesAPI()` to also check:
- UOSC version vs `ReleaseInfo.UOSC.AppVersion`
- ModernZ version vs `ReleaseInfo.ModernZ.AppVersion`
- FFmpeg version vs `ReleaseInfo.FFmpeg` (needs version tracking in release JSON)

#### 4.3 Update Response Structure
```go
type ComponentUpdateInfo struct {
    Name            string `json:"name"`
    CurrentVersion  string `json:"current_version"`
    AvailableVersion string `json:"available_version"`
    UpdateAvailable bool   `json:"update_available"`
    Type            string `json:"type"` // "ui", "utility"
}
```

#### 4.4 Web UI - Updates Display
In the "Check for Updates" section, show:
```
Updates Available:
├── MPV 0.40.0 → 0.41.0
├── UOSC 5.11.0 → 5.12.0
├── ModernZ 1.0.0 → 1.1.0
└── FFmpeg N-11234 → N-11345

[Update All] [Update Selected]
```

#### 4.5 Update API Endpoints
```go
// POST /api/components/update
type ComponentUpdateRequest struct {
    Components []string `json:"components"` // ["uosc", "modernz", "ffmpeg"]
}

// Start job to update selected components
```

#### 4.6 FFmpeg Version Tracking
FFmpeg binaries are installed for portable/binary MPV installs. Track:
- Installation location
- Current version
- Platform (arch)

### Files to Modify
- `pkg/config/config.go` - Add ComponentVersion tracking
- `pkg/web/api.go` - Extend update checking
- `pkg/web/models.go` - Add ComponentUpdateInfo
- `pkg/installer/installer.go` - Track versions during install
- `internal/webassets/templates/apps.html` - Show component updates
- `cmd/generate-info/main.go` - Add FFmpeg version to release JSON

---

## Implementation Order

### Phase 1: Config Setting (Feature 1)
**Estimated: 2-3 hours**
1. Add constant
2. Update models
3. Add Web UI element
4. Update API handler
5. Add default to mpv.conf
6. Add TUI support

### Phase 2: Keyboard Shortcuts Page (Feature 2)
**Estimated: 3-4 hours**
1. Create hotkeys package with data
2. Create Web UI template
3. Add route and handler
4. Add navigation item
5. Add TUI support

### Phase 3: Custom UI Selection (Feature 3)
**Estimated: 6-8 hours**
1. Update release structure
2. Create ModernZ installer
3. Add config tracking
4. Create selection modal
5. Integrate into install flow
6. Add post-install change UI
7. TUI support

### Phase 4: Component Updates (Feature 4)
**Estimated: 3-4 hours**
1. Add version tracking
2. Extend update checking
3. Create update API
4. Update UI to show component updates
5. Add update functionality

---

## Testing Checklist

### Feature 1
- [ ] Setting appears in Web UI config page
- [ ] Setting saves correctly to mpv.conf
- [ ] Setting loads correctly on page refresh
- [ ] TUI shows and saves setting
- [ ] Default value is "no"

### Feature 2
- [ ] Hotkeys page accessible from sidebar
- [ ] All hotkeys displayed
- [ ] Search filters results correctly
- [ ] Categories filter correctly
- [ ] Common shortcuts at top
- [ ] Keyboard keys styled correctly
- [ ] TUI navigation works

### Feature 3
- [ ] Modal shows during MPV install
- [ ] UOSC installs correctly
- [ ] ModernZ installs correctly with all files
- [ ] mpv.conf updated correctly (osc=yes/no)
- [ ] Custom UI tracked in config
- [ ] Post-install UI change works
- [ ] Old UI files removed when switching

### Feature 4
- [ ] Component versions tracked
- [ ] Updates detected correctly
- [ ] Updates displayed in UI
- [ ] Update installation works
- [ ] Version updated after install

---

## Notes

1. **ModernZ Fonts**: Two font files are required for ModernZ icons. These need to be downloaded and placed in the fonts directory.

2. **Thumbfast**: This is optional for ModernZ but provides thumbnail preview. Consider bundling it.

3. **Screenshot Previews**: The user mentioned screenshot previews for the UI selection modal. These will be placeholder images until actual screenshots are provided.

4. **FFmpeg Version**: The release JSON may need to track FFmpeg version separately since it's a different build from the MPV Windows builds.

5. **Backward Compatibility**: Existing UOSC installations should continue to work. The `custom_ui` field defaults to "uosc" if not set.
