import logging import sqlite3 from backend.services.usb_monitor import get_db_path from backend.gaming.capture_engine import capture_engine from backend.gaming.audio_capture import GameAudioCapture logger = logging.getLogger(__name__) class GamingSession: def __init__(self): # We reuse the global capture engine since it has failsafes built in self.screen = capture_engine self.audio = GameAudioCapture() self.active = False self.id = None self.game_id = None async def start_session(self, game_id: str): import uuid self.id = uuid.uuid4().hex self.game_id = game_id self.screen.start() self.audio.start() self.active = True # Log to SQLite try: with sqlite3.connect(get_db_path()) as conn: conn.execute('PRAGMA journal_mode=WAL') conn.execute("INSERT INTO gaming_sessions (id, game_id) VALUES (?, ?)", (self.id, self.game_id)) logger.info(f"JARVIS 10X: Session {self.id} started for {self.game_id}") except Exception as e: logger.error(f"Failed to log session start: {e}") async def end_session(self): if not self.active: return self.screen.stop() self.audio.stop() self.active = False # Log session end try: with sqlite3.connect(get_db_path()) as conn: conn.execute('PRAGMA journal_mode=WAL') conn.execute("UPDATE gaming_sessions SET ended_at = CURRENT_TIMESTAMP WHERE id = ?", (self.id,)) logger.info(f"JARVIS 10X: Session {self.id} ended") except Exception as e: logger.error(f"Failed to log session end: {e}") # Global registry for active sessions session_registry = {}