import { state } from './state.js'; import { config } from './config.js'; import { initDB, getFromDB } from './db.js'; import { MusicPlayer } from './musicPlayer.js'; import { ActivityViewer } from './activityViewer.js'; import { Chat } from './chat.js'; import { setupEventListeners } from './eventListeners.js'; import { fetchAllProviders, renderProviders, getRegions } from './providers.js'; import { loadInitialContent, initializeFavorites, initializeUserData, loadLocalContent, applyTheme, applyHeroVisibility } from './ui.js'; import { showNotification, _ } from './utils.js'; async function loadSettings() { if (typeof chrome === 'undefined' || !chrome.storage) { console.warn('Running outside of Chrome extension, skipping settings load from DB.'); return; } try { const settingsData = await getFromDB('settings'); if (settingsData && settingsData.length > 0) { state.settings = { ...state.settings, ...settingsData[0] }; } if (!state.settings.watchRegion) { const langToRegionMap = { 'es': 'ES', 'en': 'US', 'fr': 'FR', 'de': 'DE', 'it': 'IT', 'pt': 'PT' }; const userLang = chrome.i18n.getUILanguage().split('-')[0]; state.settings.watchRegion = langToRegionMap[userLang] || 'US'; } if (!state.settings.language) { state.settings.language = chrome.i18n.getUILanguage().split('-')[0]; } if (!state.settings.apiKey) { state.settings.apiKey = config.defaultApiKey; } const jellyfinSettingsData = await getFromDB('jellyfin_settings'); if (jellyfinSettingsData && jellyfinSettingsData.length > 0) { state.jellyfinSettings = { ...state.jellyfinSettings, ...jellyfinSettingsData[0] }; } } catch (error) { console.error("Could not load settings from DB, using defaults.", error); const userLang = chrome.i18n.getUILanguage(); const region = userLang.split('-')[1] || userLang.split('-')[0]; state.settings.watchRegion = region.toUpperCase(); } } function debugLog(message) { const debugOutput = document.getElementById('debug-output'); if (debugOutput) { const time = new Date().toLocaleTimeString(); debugOutput.innerHTML += `
${_("fatalInitErrorSub")}