# Changelog

All notable changes to this project will be documented in this file.

## [1.2.2] - 2025-08-21

### Added
- **Template Management System**: Complete HTML overlay template management with upload, delete, and real-time editing capabilities
- **Persistent Template Storage**: Cross-platform user template storage (Windows: %APPDATA%, macOS: ~/Library/Application Support, Linux: ~/.config)
- **Template Priority System**: Uploaded templates automatically override built-in templates with same filename
- **Custom URL Scheme Handler**: overlay:// protocol enables uploaded templates to access JavaScript overlay.js functionality
- **Template Code Viewer**: View and copy template source code directly from web interface with syntax highlighting
- **Live Template Switching**: Dashboard and video control forms now instantly switch to selected template with overlay updates
- **Template File Watcher**: Automatic template reloading when template files change on disk (using watchdog library)
- **Enhanced Template UI**:
  - Popup preview windows for better template testing
  - Template source code modal with copy-to-clipboard functionality
  - Dynamic template dropdown population from API
  - Comprehensive template management interface

### Fixed
- **API Endpoint Mismatch**: Fixed frontend calling wrong overlay update URL (/api/overlay/update vs /api/overlay)
- **Template Selection Issues**: Fixed template selection not working from video test page by adding automatic .html extension handling
- **JavaScript Accessibility**: Solved uploaded templates unable to access overlay.js by implementing custom overlay:// URL scheme
- **MessageBuilder Methods**: Added missing overlay_update() method to MessageBuilder class
- **Template Reload Logic**: Enhanced overlay update functionality to load specific template from form selection instead of just reloading current template

### Enhanced
- **Template Loading**: Prioritizes uploaded templates over built-in ones with same filename
- **File System Integration**: Qt Resource Collections (QRC) integration for JavaScript file embedding
- **Cross-Platform Paths**: Proper persistent storage paths for all operating systems
- **PyInstaller Compatibility**: Template system works correctly in compiled executable with persistent user data outside bundle
- **WebChannel Communication**: Enhanced Qt WebChannel integration between application and JavaScript overlay templates
- **Template Name Processing**: Automatic .html extension handling and proper template name normalization

### Technical Details
- Implemented OverlayUrlSchemeHandler for serving JavaScript files via custom overlay:// protocol
- Enhanced template loading with priority system (uploaded > built-in > default fallback)
- Added comprehensive file watcher monitoring both built-in and uploaded template directories
- Integrated Qt Resource system for embedding JavaScript files accessible via qrc:// URLs
- Enhanced template selection with automatic extension handling and proper fallback mechanisms
- Updated PyInstaller configuration to include templates directory and watchdog dependency

## [1.2.1] - 2025-08-20

### Fixed
- **Critical**: Qt video player display issue completely resolved - video frames now render properly on Linux
- **Critical**: WindowStaysOnTopHint interference with Qt video rendering eliminated by fixing always_on_top configuration
- **Critical**: Database configuration persistence issue resolved - old cached settings no longer override new defaults
- **UI**: Removed all toolbars, menu bars, status bars, and context menus for clean minimal video player interface
- Main thread architecture properly implemented for Qt event loop with background components on separate threads
- Window focus and OpenGL context management fixed for proper video frame rendering
- Configuration loading sequence corrected to prevent database overrides of updated settings

### Changed
- Qt player interface now completely clean with no UI chrome (toolbars, menus, status bars removed)
- All functionality accessible via keyboard shortcuts (F11: fullscreen, S: stats, Space: play/pause, M: mute, Escape: exit)
- Database reset mechanism implemented to clear old cached configuration on major setting changes
- Main application window behavior now matches test script (can go behind other applications)
- Overlay window properly separated from main window for correct layering

### Technical Details
- Fixed settings.py default always_on_top: bool = False to prevent WindowStaysOnTopHint on main window
- Implemented database configuration reset to eliminate cached settings conflicts
- Removed setMenuBar(), setStatusBar(), and setContextMenuPolicy() calls for clean interface
- Enhanced PlayerWindow.setup_ui() to disable all UI chrome elements
- Maintained complete keyboard control functionality while removing visual clutter

## [1.2.0] - 2025-08-20

### Added
- **Qt Player Overlay System**: Dual overlay system with command-line switchable options between QWebEngineView and native Qt widgets
- **Admin Dashboard Shutdown**: Admin-only quit button in web dashboard with guaranteed force termination
- **Enhanced Overlay Templates**: Improved video overlay rendering with reduced JavaScript timing errors
- **Native Qt Widget Overlays**: Stable alternative to WebEngine overlays for better performance and reliability

### Fixed
- **Critical**: Qt player window close now properly exits entire application without deadlocks
- **Critical**: Ctrl+C signal handling fully restored and functional across all components
- **Critical**: Background thread management fixed - all threads now properly daemonized to prevent exit blocking
- **Critical**: Circular dependency deadlocks eliminated in shutdown process using force-exit mechanism
- **Critical**: WebEngine overlay timing errors significantly reduced with enhanced DOM readiness checks
- **Critical**: Desktop transparency bleed-through issues resolved by removing problematic transparency attributes
- Video controls removed for clean overlay-only interface
- JavaScript DOM safety enhanced with comprehensive error handling
- Qt threading architecture optimized for better stability

### Changed
- Background threads now run as daemon threads to prevent application exit blocking
- Qt signal integration enhanced with aboutToQuit signal handling for proper lifecycle management
- Shutdown message handling improved with sender-specific logic to avoid circular dependencies
- WebEngine readiness checks enhanced for safer overlay updates
- Force-exit mechanism implemented using os._exit(0) with delayed execution to bypass Qt event loop issues

### Technical Details
- Fixed closeEvent() in Qt player to remove forced os._exit(0) and allow proper Qt shutdown sequence
- Enhanced signal_handler() in main.py to detect Qt applications and use qt_app.quit() appropriately
- Modified ThreadManager to set daemon=True for all background threads ensuring clean process termination
- Added /api/system/shutdown endpoint with admin authentication and immediate HTTP response before force termination
- Implemented comprehensive background component cleanup in _qt_about_to_quit() method
- Added desktop transparency prevention by removing WA_TranslucentBackground window attribute
- Enhanced WebEngine overlay safety with try-catch blocks and DOM state validation

## [1.1.0] - 2025-08-19

### Added
- Enhanced token creation workflow with professional modal dialogs
- Comprehensive troubleshooting section in README
- Default admin user creation on first run
- Permanent token deletion functionality
- Section-based configuration updates
- Database operation stability improvements

### Fixed
- **Critical**: Application now exits gracefully with single Ctrl+C press
- **Critical**: API tokens properly display after creation in web interface
- **Critical**: User creation now saves properly and displays immediately
- **Critical**: Configuration updates through web dashboard now work correctly
- **Critical**: Qt player thread freezing issue resolved by running Qt event loop on main thread
- SQLAlchemy session binding issues causing data access errors
- Token revocation now permanently deletes tokens from database
- Frontend JavaScript token management and display
- Database operations extract data before session closure
- Signal handler optimization with reduced timeouts
- Web dashboard routing and static file loading issues
- ConfigManager missing update_section method
 
### Changed
- Reduced application shutdown timeouts for faster exit (10s→3s, 5s→2s)
- Updated README with comprehensive troubleshooting guide
- Enhanced API documentation with all endpoints
- Improved error handling across all components
- Qt player now runs Qt event loop on main thread instead of background thread

### Technical Details
- Fixed database session binding by extracting data to dictionaries
- Added proper signal handling flow: signal → shutdown event → cleanup → exit
- Enhanced frontend with Bootstrap modal dialogs for token display
- Implemented section-based configuration management
- Added comprehensive session lifecycle management
- Qt player thread freezing fixed by running Qt event loop on main thread instead of background thread
- Qt player no longer inherits from ThreadedComponent to comply with Qt threading requirements
- Message processing for Qt player now runs in a separate thread while Qt event loop runs on main thread

## [1.0.0] - 2025-08-15

### Added
- Initial release of MbetterClient
- PyQt video player with overlay support
- Flask web dashboard with authentication
- REST API client with configurable endpoints
- Multi-threaded architecture with message bus
- SQLite database with versioning system
- PyInstaller build configuration
- Cross-platform support (Windows, Linux, macOS)
- JWT and long-lived API token management
- User management system
- Configuration management interface
- Video upload and playback testing

### Features
- Fullscreen and windowed video playback modes
- Customizable video overlay templates
- Web-based administration interface
- API token creation and management
- User authentication and authorization
- Database migrations system
- Message-based inter-thread communication
- Comprehensive logging system
- Configuration persistence