From 0c62e43a56506b8d994f3f3f1a59a24392adea4a Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 9 Feb 2026 03:38:57 -0600 Subject: [PATCH] feat(plex): redesign settings flow and gate local library integration cx --- .../components/views/LocalLibraryView.svelte | 32 +- src/lib/components/views/SettingsView.svelte | 777 ++++++++++++------ src/lib/i18n/locales/de.json | 24 + src/lib/i18n/locales/en.json | 23 + src/lib/i18n/locales/es.json | 23 + src/lib/i18n/locales/fr.json | 24 + 6 files changed, 660 insertions(+), 243 deletions(-) diff --git a/src/lib/components/views/LocalLibraryView.svelte b/src/lib/components/views/LocalLibraryView.svelte index d46244bb9..44991906a 100644 --- a/src/lib/components/views/LocalLibraryView.svelte +++ b/src/lib/components/views/LocalLibraryView.svelte @@ -1042,12 +1042,15 @@ // If not found in loaded albums, we need to fetch album list first if (!album) { + const includePlex = isPlexLibraryEnabled(); const [localAlbums, plexAlbumsRaw] = await Promise.all([ invoke('library_get_albums', { includeHidden: false, excludeNetworkFolders: shouldExcludeNetworkFolders() }), - invoke('plex_cache_get_albums').catch(() => []) + includePlex + ? invoke('plex_cache_get_albums').catch(() => []) + : Promise.resolve([]) ]); const allAlbums = [...localAlbums, ...plexAlbumsRaw.map(mapPlexAlbum)]; albums = allAlbums; @@ -1108,6 +1111,10 @@ } } + function isPlexLibraryEnabled(): boolean { + return getUserItem('qbz-plex-enabled') === 'true'; + } + function buildPlexArtworkUrl(path: string): string { const baseUrl = getUserItem('qbz-plex-poc-base-url') || ''; const token = getUserItem('qbz-plex-poc-token') || ''; @@ -1269,17 +1276,21 @@ console.log('[LocalLibrary] Calling library_get_albums with excludeNetwork:', excludeNetwork); const fetchStart = performance.now(); + const includePlex = isPlexLibraryEnabled(); const [albumsResult, statsResult, plexAlbumsRaw] = await Promise.all([ invoke('library_get_albums', { includeHidden: false, excludeNetworkFolders: excludeNetwork }), invoke('library_get_stats'), - invoke('plex_cache_get_albums').catch(() => []) + includePlex + ? invoke('plex_cache_get_albums').catch(() => []) + : Promise.resolve([]) ]); const fetchMs = performance.now() - fetchStart; let workingPlexAlbumsRaw = plexAlbumsRaw; const shouldAttemptRepair = + includePlex && !plexRepairAttempted && (isLikelyLegacyPlexCache(workingPlexAlbumsRaw) || workingPlexAlbumsRaw.length <= 1); if (shouldAttemptRepair) { @@ -1382,11 +1393,14 @@ loading = true; try { console.log('[LocalLibrary] Calling library_get_artists + plex_cache_get_albums'); + const includePlex = isPlexLibraryEnabled(); const [localArtists, plexAlbumsRaw] = await Promise.all([ invoke('library_get_artists', { excludeNetworkFolders: shouldExcludeNetworkFolders() }), - invoke('plex_cache_get_albums').catch(() => []) + includePlex + ? invoke('plex_cache_get_albums').catch(() => []) + : Promise.resolve([]) ]); const plexArtistMap = new Map(); @@ -1441,15 +1455,18 @@ loading = true; try { console.log('[LocalLibrary] Calling library_search + plex_cache_search_tracks'); + const includePlex = isPlexLibraryEnabled(); const [localTracks, plexTracksRaw] = await Promise.all([ invoke('library_search', { query, limit: 0, // 0 = no limit, virtualization handles any list size excludeNetworkFolders: shouldExcludeNetworkFolders() }), - invoke('plex_cache_search_tracks', { - query - }).catch(() => []) + includePlex + ? invoke('plex_cache_search_tracks', { + query + }).catch(() => []) + : Promise.resolve([]) ]); const mappedPlexTracks = plexTracksRaw.map(mapPlexTrack); tracks = [...localTracks, ...mappedPlexTracks]; @@ -1933,6 +1950,9 @@ async function fetchAlbumTracks(album: LocalAlbum): Promise { try { if (album.source === 'plex') { + if (!isPlexLibraryEnabled()) { + return []; + } const plexTracks = await invoke('plex_cache_get_album_tracks', { albumKey: album.id }); diff --git a/src/lib/components/views/SettingsView.svelte b/src/lib/components/views/SettingsView.svelte index 342d12082..703d6e582 100644 --- a/src/lib/components/views/SettingsView.svelte +++ b/src/lib/components/views/SettingsView.svelte @@ -5,7 +5,7 @@ import { getCurrentWebview } from '@tauri-apps/api/webview'; import { writeText as copyToClipboard } from '@tauri-apps/plugin-clipboard-manager'; import { ask } from '@tauri-apps/plugin-dialog'; - import { ArrowLeft, ChevronRight, ChevronDown, ChevronUp, Loader2, Sun, Moon, SunMoon, HelpCircle, Ban } from 'lucide-svelte'; + import { ArrowLeft, ChevronRight, ChevronDown, ChevronUp, Loader2, Sun, Moon, SunMoon, HelpCircle, Ban, Copy } from 'lucide-svelte'; import Toggle from '../Toggle.svelte'; import Dropdown from '../Dropdown.svelte'; import DeviceDropdown from '../DeviceDropdown.svelte'; @@ -740,12 +740,18 @@ let remoteControlCollapsed = $state(true); // Plex LAN POC state + let plexEnabled = $state(getUserItem('qbz-plex-enabled') === 'true'); + let plexConnectCollapsed = $state(getUserItem('qbz-plex-connect-collapsed') !== 'false'); + let plexManualTokenMode = $state(false); + let plexServerUrl = $state('http://127.0.0.1'); + let plexServerPort = $state('32400'); let plexBaseUrl = $state(getUserItem('qbz-plex-poc-base-url') || 'http://127.0.0.1:32400'); let plexToken = $state(getUserItem('qbz-plex-poc-token') || ''); let plexMetadataWriteEnabled = $state(getUserItem('qbz-plex-poc-metadata-write-enabled') === 'true'); let plexSections = $state([]); let plexTracks = $state([]); - let plexSelectedSectionKey = $state(''); + let plexSectionTrackCounts = $state>({}); + let plexSelectedSectionKeys = $state([]); let plexStatusKey = $state('settings.integrations.plexStatusIdle'); let plexStatusValues = $state>({}); let plexBusy = $state(false); @@ -757,6 +763,9 @@ let plexAuthClientId = $state(getUserItem('qbz-plex-poc-client-id') || ''); let plexAuthPollTimer: ReturnType | null = null; + const PLEX_ENABLED_KEY = 'qbz-plex-enabled'; + const PLEX_CONNECT_COLLAPSED_KEY = 'qbz-plex-connect-collapsed'; + const PLEX_CACHE_SELECTED_SECTIONS_KEY = 'qbz-plex-poc-selected-sections'; const PLEX_CACHE_SELECTED_SECTION_KEY = 'qbz-plex-poc-selected-section'; const PLEX_CACHE_SERVER_ID_KEY = 'qbz-plex-poc-machine-id'; const PLEX_CLIENT_ID_KEY = 'qbz-plex-poc-client-id'; @@ -841,8 +850,11 @@ loadRemoteControlStatus(); // Warm-start Plex panel from local cache and refresh in background - void loadPlexCachedState(); - void refreshPlexInBackground(); + hydratePlexAddressFieldsFromBaseUrl(); + if (plexEnabled) { + void loadPlexCachedState(); + void refreshPlexInBackground(); + } // Load notification preferences loadToastsPreference(); @@ -1130,11 +1142,128 @@ } } + function sanitizePlexPort(value: string): string { + const digits = value.replace(/\D+/g, ''); + if (!digits) return '32400'; + const num = Math.max(1, Math.min(65535, Number(digits))); + return String(num); + } + + function isValidPlexPort(value: string): boolean { + return /^\d+$/.test(value) && Number(value) >= 1 && Number(value) <= 65535; + } + + function normalizePlexServerUrl(value: string): string { + const trimmed = value.trim(); + if (!trimmed) return ''; + return /^https?:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`; + } + + function isPrivateIpv4(hostname: string): boolean { + if (!/^\d+\.\d+\.\d+\.\d+$/.test(hostname)) return false; + const octets = hostname.split('.').map(Number); + if (octets.some((octet) => Number.isNaN(octet) || octet < 0 || octet > 255)) return false; + if (octets[0] === 10) return true; + if (octets[0] === 127) return true; + if (octets[0] === 192 && octets[1] === 168) return true; + if (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31) return true; + return false; + } + + function isLocalPlexAddress(urlInput: string): boolean { + const normalized = normalizePlexServerUrl(urlInput); + if (!normalized) return false; + try { + const parsed = new URL(normalized); + const host = parsed.hostname.toLowerCase(); + if (host === 'localhost' || host === '::1') return true; + if (host.endsWith('.local') || host.endsWith('.lan')) return true; + if (!host.includes('.')) return true; + return isPrivateIpv4(host); + } catch { + return false; + } + } + + function resolvePlexBaseUrl(): string { + const normalizedUrl = normalizePlexServerUrl(plexServerUrl); + if (!normalizedUrl) return ''; + try { + const parsed = new URL(normalizedUrl); + if (!['http:', 'https:'].includes(parsed.protocol)) return ''; + parsed.port = sanitizePlexPort(plexServerPort); + return `${parsed.protocol}//${parsed.host}`; + } catch { + return ''; + } + } + + function hydratePlexAddressFieldsFromBaseUrl() { + try { + const parsed = new URL(plexBaseUrl || 'http://127.0.0.1:32400'); + plexServerUrl = `${parsed.protocol}//${parsed.hostname}`; + plexServerPort = parsed.port || '32400'; + } catch { + plexServerUrl = 'http://127.0.0.1'; + plexServerPort = '32400'; + } + } + + function canUsePlexRequests(): boolean { + return plexEnabled && isLocalPlexAddress(plexServerUrl) && isValidPlexPort(plexServerPort) && !!plexToken.trim(); + } + function persistPlexConfig() { - setUserItem('qbz-plex-poc-base-url', plexBaseUrl.trim()); + plexServerPort = sanitizePlexPort(plexServerPort); + plexBaseUrl = resolvePlexBaseUrl(); + setUserItem('qbz-plex-poc-base-url', plexBaseUrl); setUserItem('qbz-plex-poc-token', plexToken.trim()); } + function persistPlexSelectedSections() { + setUserItem(PLEX_CACHE_SELECTED_SECTIONS_KEY, JSON.stringify(plexSelectedSectionKeys)); + if (plexSelectedSectionKeys.length === 1) { + setUserItem(PLEX_CACHE_SELECTED_SECTION_KEY, plexSelectedSectionKeys[0]); + } else { + removeUserItem(PLEX_CACHE_SELECTED_SECTION_KEY); + } + } + + function readPersistedPlexSelectedSections(): string[] { + const raw = getUserItem(PLEX_CACHE_SELECTED_SECTIONS_KEY); + if (raw) { + try { + const parsed = JSON.parse(raw); + if (Array.isArray(parsed)) { + return parsed.filter((item): item is string => typeof item === 'string' && item.trim().length > 0); + } + } catch (error) { + console.warn('Failed parsing persisted Plex section keys:', error); + } + } + const legacySingle = getUserItem(PLEX_CACHE_SELECTED_SECTION_KEY); + return legacySingle ? [legacySingle] : []; + } + + function togglePlexConnectionBlock() { + plexConnectCollapsed = !plexConnectCollapsed; + setUserItem(PLEX_CONNECT_COLLAPSED_KEY, plexConnectCollapsed ? 'true' : 'false'); + } + + function handlePlexEnabledToggle(enabled: boolean) { + plexEnabled = enabled; + setUserItem(PLEX_ENABLED_KEY, enabled ? 'true' : 'false'); + if (!enabled) { + plexStatusKey = 'settings.integrations.plexStatusDisabled'; + plexStatusValues = {}; + return; + } + plexStatusKey = 'settings.integrations.plexStatusIdle'; + plexStatusValues = {}; + void loadPlexCachedState(); + void refreshPlexInBackground(); + } + function handlePlexMetadataWriteToggle(enabled: boolean) { plexMetadataWriteEnabled = enabled; setUserItem(PLEX_METADATA_WRITE_KEY, enabled ? 'true' : 'false'); @@ -1151,14 +1280,13 @@ } async function handlePlexConnectEasy() { - if (plexAuthBusy) return; + if (!plexEnabled || plexAuthBusy || !isLocalPlexAddress(plexServerUrl) || !isValidPlexPort(plexServerPort)) return; plexAuthBusy = true; plexLastError = ''; + persistPlexConfig(); try { const clientIdentifier = ensurePlexClientId(); - const pin = await invoke('plex_auth_pin_start', { - clientIdentifier - }); + const pin = await invoke('plex_auth_pin_start', { clientIdentifier }); plexAuthPinId = pin.pinId; plexAuthCode = pin.code; plexAuthUrl = pin.authUrl; @@ -1177,6 +1305,7 @@ pinId: plexAuthPinId, code: plexAuthCode || null }); + if (check.authorized && check.authToken) { plexToken = check.authToken; persistPlexConfig(); @@ -1188,7 +1317,7 @@ } plexAuthPinId = null; plexAuthCode = ''; - void handlePlexPing(); + void runPlexAutoSetup(); } else if (check.expired) { plexStatusKey = 'settings.integrations.plexStatusAuthExpired'; plexStatusValues = {}; @@ -1230,6 +1359,20 @@ } } + async function handlePlexTokenBlur() { + persistPlexConfig(); + if (canUsePlexRequests()) { + await runPlexAutoSetup(); + } + } + + function setPlexError(error: unknown) { + const message = String(error); + plexLastError = message; + plexStatusKey = 'settings.integrations.plexStatusError'; + plexStatusValues = { error: message }; + } + async function handlePlexDisconnect() { const confirmed = await ask(get(t)('settings.integrations.plexDisconnectConfirmDesc'), { title: get(t)('settings.integrations.plexDisconnectConfirmTitle'), @@ -1251,12 +1394,13 @@ plexToken = ''; plexSections = []; plexTracks = []; - plexSelectedSectionKey = ''; + plexSelectedSectionKeys = []; plexStatusKey = 'settings.integrations.plexStatusDisconnected'; plexStatusValues = {}; plexLastError = ''; removeUserItem('qbz-plex-poc-token'); + removeUserItem(PLEX_CACHE_SELECTED_SECTIONS_KEY); removeUserItem(PLEX_CACHE_SELECTED_SECTION_KEY); removeUserItem(PLEX_CACHE_SERVER_ID_KEY); @@ -1278,13 +1422,10 @@ try { await invoke('plex_cache_clear'); - plexSections = []; plexTracks = []; - plexSelectedSectionKey = ''; plexStatusKey = 'settings.integrations.plexStatusCacheCleared'; plexStatusValues = {}; plexLastError = ''; - removeUserItem(PLEX_CACHE_SELECTED_SECTION_KEY); removeUserItem(PLEX_CACHE_SERVER_ID_KEY); } catch (error) { console.error('Failed clearing Plex cache:', error); @@ -1293,19 +1434,20 @@ } async function loadPlexCachedState() { + if (!plexEnabled) return; try { const cachedSections = await invoke('plex_cache_get_sections'); if (Array.isArray(cachedSections) && cachedSections.length > 0) { plexSections = cachedSections; } - const cachedSelectedSection = getUserItem(PLEX_CACHE_SELECTED_SECTION_KEY); - if (cachedSelectedSection) { - plexSelectedSectionKey = cachedSelectedSection; + const persistedSections = readPersistedPlexSelectedSections(); + if (persistedSections.length > 0) { + plexSelectedSectionKeys = persistedSections; } const cachedTracks = await invoke('plex_cache_get_tracks', { - sectionKey: plexSelectedSectionKey || null + sectionKey: null }); if (Array.isArray(cachedTracks) && cachedTracks.length > 0) { plexTracks = cachedTracks; @@ -1318,66 +1460,12 @@ } async function refreshPlexInBackground() { - if (!plexBaseUrl.trim() || !plexToken.trim()) return; - try { - const info = await invoke('plex_ping', { - baseUrl: plexBaseUrl.trim(), - token: plexToken.trim() - }); - if (info.machineIdentifier) { - setUserItem(PLEX_CACHE_SERVER_ID_KEY, info.machineIdentifier); - } - - const sections = await invoke('plex_get_music_sections', { - baseUrl: plexBaseUrl.trim(), - token: plexToken.trim() - }); - plexSections = sections; - await invoke('plex_cache_save_sections', { - serverId: info.machineIdentifier ?? null, - sections - }); - - if (sections.length > 0 && !sections.some((section) => section.key === plexSelectedSectionKey)) { - plexSelectedSectionKey = sections[0].key; - } - if (plexSelectedSectionKey) { - setUserItem(PLEX_CACHE_SELECTED_SECTION_KEY, plexSelectedSectionKey); - } - - if (!plexSelectedSectionKey) return; - - const tracks = await invoke('plex_get_section_tracks', { - baseUrl: plexBaseUrl.trim(), - token: plexToken.trim(), - sectionKey: plexSelectedSectionKey - }); - plexTracks = tracks; - await invoke('plex_cache_save_tracks', { - serverId: info.machineIdentifier ?? (getUserItem(PLEX_CACHE_SERVER_ID_KEY) || null), - sectionKey: plexSelectedSectionKey, - tracks - }); - plexStatusKey = 'settings.integrations.plexStatusTracksLoaded'; - plexStatusValues = { count: tracks.length }; - } catch (error) { - console.warn('Plex background refresh failed:', error); - // Keep cached data visible; only surface error if nothing cached is available. - if (plexTracks.length === 0) { - setPlexError(error); - } - } + if (!canUsePlexRequests()) return; + await runPlexAutoSetup(); } - function setPlexError(error: unknown) { - const message = String(error); - plexLastError = message; - plexStatusKey = 'settings.integrations.plexStatusError'; - plexStatusValues = { error: message }; - } - - async function handlePlexPing() { - if (!plexBaseUrl.trim() || !plexToken.trim()) return; + async function handlePlexPing(): Promise { + if (!canUsePlexRequests()) return false; plexBusy = true; plexLastError = ''; persistPlexConfig(); @@ -1394,16 +1482,70 @@ server: info.friendlyName || info.machineIdentifier || 'Plex', version: info.version || '?' }; + return true; } catch (error) { console.error('Failed Plex ping:', error); setPlexError(error); + return false; + } finally { + plexBusy = false; + } + } + + async function syncSelectedPlexLibraries() { + if (!canUsePlexRequests()) return; + plexBusy = true; + plexLastError = ''; + try { + const serverId = getUserItem(PLEX_CACHE_SERVER_ID_KEY) || null; + await invoke('plex_cache_clear'); + + if (plexSections.length > 0) { + await invoke('plex_cache_save_sections', { + serverId, + sections: plexSections + }); + } + + if (plexSelectedSectionKeys.length === 0) { + plexTracks = []; + plexStatusKey = 'settings.integrations.plexStatusTracksLoaded'; + plexStatusValues = { count: 0 }; + return; + } + + let totalCount = 0; + const sectionCounts: Record = {}; + for (const sectionKey of plexSelectedSectionKeys) { + const sectionTracks = await invoke('plex_get_section_tracks', { + baseUrl: plexBaseUrl.trim(), + token: plexToken.trim(), + sectionKey + }); + const count = sectionTracks.length; + sectionCounts[sectionKey] = count; + totalCount += count; + await invoke('plex_cache_save_tracks', { + serverId, + sectionKey, + tracks: sectionTracks + }); + } + + plexSectionTrackCounts = { ...plexSectionTrackCounts, ...sectionCounts }; + plexTracks = await invoke('plex_cache_get_tracks', { sectionKey: null }); + plexStatusKey = 'settings.integrations.plexStatusTracksLoaded'; + plexStatusValues = { count: totalCount }; + } catch (error) { + console.error('Failed syncing selected Plex libraries:', error); + setPlexError(error); } finally { plexBusy = false; } } - async function handlePlexLoadSections() { - if (!plexBaseUrl.trim() || !plexToken.trim()) return; + async function handlePlexLoadSections(options: { autoSyncSelected?: boolean } = {}) { + if (!canUsePlexRequests()) return; plexBusy = true; plexLastError = ''; persistPlexConfig(); @@ -1417,14 +1559,18 @@ serverId: getUserItem(PLEX_CACHE_SERVER_ID_KEY) || null, sections }); - if (sections.length > 0 && !sections.some((section) => section.key === plexSelectedSectionKey)) { - plexSelectedSectionKey = sections[0].key; - } - if (plexSelectedSectionKey) { - setUserItem(PLEX_CACHE_SELECTED_SECTION_KEY, plexSelectedSectionKey); - } + + const available = new Set(sections.map((section) => section.key)); + const persisted = readPersistedPlexSelectedSections().filter((key) => available.has(key)); + plexSelectedSectionKeys = persisted.length > 0 ? persisted : sections.map((section) => section.key); + persistPlexSelectedSections(); + plexStatusKey = 'settings.integrations.plexStatusSectionsLoaded'; plexStatusValues = { count: sections.length }; + + if (options.autoSyncSelected !== false) { + await syncSelectedPlexLibraries(); + } } catch (error) { console.error('Failed loading Plex sections:', error); setPlexError(error); @@ -1433,31 +1579,27 @@ } } - async function handlePlexLoadTracks() { - if (!plexBaseUrl.trim() || !plexToken.trim() || !plexSelectedSectionKey) return; - plexBusy = true; - plexLastError = ''; - persistPlexConfig(); - try { - const tracks = await invoke('plex_get_section_tracks', { - baseUrl: plexBaseUrl.trim(), - token: plexToken.trim(), - sectionKey: plexSelectedSectionKey - }); - plexTracks = tracks; - await invoke('plex_cache_save_tracks', { - serverId: getUserItem(PLEX_CACHE_SERVER_ID_KEY) || null, - sectionKey: plexSelectedSectionKey, - tracks - }); - plexStatusKey = 'settings.integrations.plexStatusTracksLoaded'; - plexStatusValues = { count: tracks.length }; - } catch (error) { - console.error('Failed loading Plex tracks:', error); - setPlexError(error); - } finally { - plexBusy = false; + async function runPlexAutoSetup() { + const connected = await handlePlexPing(); + if (!connected) return; + await handlePlexLoadSections({ autoSyncSelected: true }); + } + + async function handlePlexLibraryToggle(sectionKey: string, checked: boolean) { + const current = new Set(plexSelectedSectionKeys); + if (checked) { + current.add(sectionKey); + } else { + current.delete(sectionKey); + const nextCounts = { ...plexSectionTrackCounts }; + delete nextCounts[sectionKey]; + plexSectionTrackCounts = nextCounts; } + plexSelectedSectionKeys = plexSections + .map((section) => section.key) + .filter((key) => current.has(key)); + persistPlexSelectedSections(); + await syncSelectedPlexLibraries(); } async function loadRemoteControlStatus() { @@ -3349,116 +3491,211 @@ -
-
- {$t('settings.integrations.plexPoc')} - {$t('settings.integrations.plexPocDesc')} +
+
+ {$t('settings.integrations.plexConnection')}
- {$t('settings.integrations.plexLibraryIntegrationNote')} - {$t('settings.integrations.plexLocalOnlyDirectPlayNote')} + +
+ + {#if plexEnabled}
-
- {$t('settings.integrations.plexMetadataWrite')} - {$t('settings.integrations.plexMetadataWriteDesc')} -
- + {$t('settings.integrations.plexConnectionLore')}
-
-
- {$t('settings.integrations.plexEasyConnectTitle')} - {$t('settings.integrations.plexEasyConnectDesc')} +
+
+ + persistPlexConfig()} + />
+
+ + plexServerPort = sanitizePlexPort(plexServerPort)} + onblur={() => persistPlexConfig()} + /> +
+
-
- +
+ + {#if !plexConnectCollapsed} +
+ {$t('settings.integrations.plexAuthorizeSectionLore')} +
+
+ {$t('settings.integrations.plexAuthorizeHelp')} +
+
+ {$t('settings.integrations.plexAuthorizeLabel')} + - {#if plexAuthUrl} - - {/if} - -
+ +
+ +
+ +
- {#if plexAuthCode} -
- {$t('settings.integrations.plexCodeLabel')} -
{plexAuthCode}
-
- -
+
+ + +
+ +
+ +
+ +
+ + {#if plexManualTokenMode} +
+ {$t('settings.integrations.plexToken')} +
{/if} -
+ {/if} -
- - -
- -
- - -
- -
- -
+ +
+
+ {$t('settings.integrations.plexGetLibrariesLabel')} + {$t('settings.integrations.plexGetLibrariesHelp')} +
+
-
- {$t('settings.integrations.plexMusicSection')} -
- - +
+ {$t('settings.integrations.plexMusicLibraries')} +
+ {#each plexSections as plexSection} + + {/each}
+ {#if plexLastError} + {plexLastError} + {/if}
- {$t(plexStatusKey, { values: plexStatusValues })} - {#if plexLastError} - {plexLastError} - {/if} -
+
+ {$t('settings.integrations.plexDisconnectRowLabel')} + +
+ +
+
+ {$t('settings.integrations.plexClearCacheRowLabel')} + {$t('settings.integrations.plexClearCacheRowHelp')} +
+ +
+ {/if} @@ -5130,66 +5367,132 @@ flatpak override --user --filesystem=/home/USUARIO/Música com.blitzfc.qbz word-break: break-all; } - .plex-poc-panel { - margin-top: 10px; - display: grid; + .plex-server-row { + align-items: end; gap: 10px; } - .plex-actions { - display: flex; - gap: 8px; - flex-wrap: wrap; - } - - .plex-inline-row { - margin-top: 2px; - margin-bottom: 2px; - padding-top: 0; - padding-bottom: 0; - } - - .plex-connect-wizard { + .plex-server-field { + flex: 1; + min-width: 0; display: grid; - gap: 10px; - padding: 12px; - border: 1px solid var(--border-subtle); - border-radius: 10px; - background: var(--bg-secondary); + gap: 6px; } - .plex-wizard-header { + .plex-port-field { + width: 130px; display: grid; - gap: 4px; + gap: 6px; } - .plex-code-card { - display: grid; - gap: 10px; - padding: 14px; - border-radius: 10px; - border: 1px solid var(--accent-primary); - background: color-mix(in srgb, var(--accent-primary) 10%, var(--bg-tertiary)); + .plex-port-input::-webkit-outer-spin-button, + .plex-port-input::-webkit-inner-spin-button { + -webkit-appearance: none; + margin: 0; } - .plex-code-value { - font-family: 'JetBrains Mono', 'Fira Code', monospace; - font-size: 32px; - line-height: 1; - letter-spacing: 0.16em; - font-weight: 700; - color: var(--text-primary); + .plex-port-input { + -moz-appearance: textfield; + appearance: textfield; } - .plex-section-controls { + .plex-collapse-trigger { + width: 100%; + justify-content: space-between; + } + + .plex-two-column-row { + align-items: center; + } + + .plex-divider { + width: 100%; + height: 1px; + background: var(--border-subtle); + margin: 2px 0; + } + + .plex-code-row { display: flex; align-items: center; gap: 8px; } - .plex-section-select { - min-width: 240px; - width: 240px; + .plex-code-input { + flex: 1; + font-family: 'JetBrains Mono', 'Fira Code', monospace; + letter-spacing: 0.06em; + } + + .copy-icon-btn { + width: 34px; + height: 34px; + border: 1px solid var(--border-subtle); + border-radius: 8px; + background: var(--bg-tertiary); + color: var(--text-secondary); + display: inline-flex; + align-items: center; + justify-content: center; + cursor: pointer; + transition: all 0.15s ease; + } + + .copy-icon-btn:hover:not(:disabled) { + color: var(--text-primary); + border-color: var(--border-default); + } + + .copy-icon-btn:disabled { + opacity: 0.45; + cursor: not-allowed; + } + + .plex-manual-toggle { + display: inline-flex; + align-items: center; + gap: 8px; + cursor: pointer; + } + + .plex-libraries-block { + display: grid; + gap: 8px; + align-items: start; + } + + .plex-libraries-grid { + border: 1px solid var(--border-subtle); + border-radius: 10px; + background: var(--bg-tertiary); + padding: 10px; + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 8px 16px; + max-height: 130px; + overflow-y: auto; + } + + .plex-library-item { + display: inline-flex; + align-items: center; + gap: 8px; + min-height: 28px; + color: var(--text-primary); + } + + .plex-library-name { + font-size: 13px; + font-weight: 500; + } + + .plex-library-count { + font-size: 11px; + color: var(--text-muted); + } + + .plex-connected-note { + color: #86efac; } .plex-error-note { diff --git a/src/lib/i18n/locales/de.json b/src/lib/i18n/locales/de.json index a8be24e60..73203dc98 100644 --- a/src/lib/i18n/locales/de.json +++ b/src/lib/i18n/locales/de.json @@ -670,6 +670,8 @@ "plexAuthCode": "Plex-Code: {code}", "plexCodeCopied": "Plex-Code kopiert.", "plexCodeCopyFailed": "Plex-Code konnte nicht kopiert werden.", + "plexStatusIdle": "Bereit für Plex-LAN-Prüfungen.", + "plexStatusDisabled": "Die Plex-Verbindung ist deaktiviert.", "plexStatusAuthPending": "Plex-Anmeldung gestartet. Schließe die Autorisierung mit dem Code {code} ab.", "plexStatusAuthConnected": "Plex-Token erfolgreich empfangen.", "plexStatusAuthExpired": "Der Plex-Anmeldecode ist abgelaufen. Starte die Verbindung erneut.", @@ -709,6 +711,28 @@ "remoteControlQrHelp": "Diesen QR-Code mit QBZ-Control scannen, um zu koppeln.", "remoteControlUrlLabel": "Lokale URL", "remoteControlQrAlt": "QR-Code zur Kopplung", + "plexConnection": "Plex-Verbindung", + "plexConnectionLore": "Greife direkt aus der QBZ Local Library auf deine Plex-Bibliothek zu. Diese Integration unterstützt nur lokale und LAN-Plex-Server, um Direct Play zu garantieren.", + "plexServerUrl": "Plex-Server-URL", + "plexServerUrlPlaceholder": "http://lokale-ip-adresse", + "plexServerPort": "Port", + "plexLocalAddressRequired": "Verwende eine lokale oder LAN-Plex-Adresse. Remote-Endpunkte werden in diesem Modus nicht unterstützt.", + "plexAuthorizeSectionTitle": "QBZ autorisieren", + "plexAuthorizeSectionLore": "Autorisiere QBZ, um sich mit deinem Plex-Server zu verbinden.", + "plexAuthorizeHelp": "Prüfe deinen externen Browser, um die Autorisierung abzuschließen.", + "plexAuthorizeLabel": "QBZ für die Verbindung mit deinem Plex-Server autorisieren", + "plexCodeEmpty": "Noch kein Code erzeugt", + "plexCodeTooltip": "Code kopieren", + "plexManualTokenToggle": "Oder gib dein Plex X-Token direkt ein", + "plexConnectionCheckLabel": "Plex-Verbindung prüfen", + "plexGetLibrariesLabel": "Plex-Musikbibliotheken laden", + "plexGetLibrariesHelp": "Neu synchronisieren, wenn auf dem Plex-Server neue Bibliotheken hinzugefügt wurden.", + "plexMusicLibraries": "Musikbibliotheken", + "plexTracksShort": "Titel", + "plexDisconnectRowLabel": "Plex trennen", + "plexClearCacheRowLabel": "Plex-Cache in QBZ leeren", + "plexClearCacheRowHelp": "Empfohlen bei Inkonsistenzen in der Bibliothek.", + "plexClearButton": "Leeren", "plexStatusCacheLoaded": "{count} zwischengespeicherte Titel geladen. Aktualisierung von Plex im Hintergrund." }, "storage": { diff --git a/src/lib/i18n/locales/en.json b/src/lib/i18n/locales/en.json index cf4b50e16..b80a1ad94 100644 --- a/src/lib/i18n/locales/en.json +++ b/src/lib/i18n/locales/en.json @@ -702,6 +702,28 @@ "remoteControlQrHelp": "Scan this QR code with QBZ-Control to pair.", "remoteControlUrlLabel": "Local URL", "remoteControlQrAlt": "Pairing QR code", + "plexConnection": "Plex Connection", + "plexConnectionLore": "Access your Plex library directly from QBZ Local Library. This integration supports only local and LAN Plex servers to guarantee direct play.", + "plexServerUrl": "Plex Server URL", + "plexServerUrlPlaceholder": "http://local-ip-address", + "plexServerPort": "Port", + "plexLocalAddressRequired": "Use a local or LAN Plex address. Remote Plex endpoints are not supported for this mode.", + "plexAuthorizeSectionTitle": "Authorize QBZ", + "plexAuthorizeSectionLore": "Authorize QBZ to connect with your Plex server.", + "plexAuthorizeHelp": "Check your external web browser to complete authorization.", + "plexAuthorizeLabel": "Authorize QBZ to connect with your Plex server", + "plexCodeEmpty": "No code generated yet", + "plexCodeTooltip": "Copy code", + "plexManualTokenToggle": "Or enter your Plex X-Token directly", + "plexConnectionCheckLabel": "Check Plex connection", + "plexGetLibrariesLabel": "Get Plex music libraries", + "plexGetLibrariesHelp": "Re-sync if new libraries were added on your Plex server.", + "plexMusicLibraries": "Music libraries", + "plexTracksShort": "tracks", + "plexDisconnectRowLabel": "Disconnect Plex", + "plexClearCacheRowLabel": "Clear Plex cache in QBZ", + "plexClearCacheRowHelp": "Recommended if you notice library inconsistencies.", + "plexClearButton": "Clear", "plexPoc": "Plex LAN POC", "plexPocDesc": "Experimental local-only integration. Uses direct media parts from Plex without replacing QBZ playback.", "plexLibraryIntegrationNote": "Plex music is integrated into Local Library (same queue/player flow, no separate tab).", @@ -732,6 +754,7 @@ "plexMusicSection": "Music Section", "plexSelectSection": "Select a section", "plexStatusIdle": "Ready for Plex LAN checks.", + "plexStatusDisabled": "Plex connection is disabled.", "plexStatusAuthPending": "Plex sign-in started. Complete authorization with code {code}.", "plexStatusAuthConnected": "Plex token received successfully.", "plexStatusAuthExpired": "Plex sign-in code expired. Start the connection again.", diff --git a/src/lib/i18n/locales/es.json b/src/lib/i18n/locales/es.json index 3dd78da06..5659a5573 100644 --- a/src/lib/i18n/locales/es.json +++ b/src/lib/i18n/locales/es.json @@ -702,6 +702,28 @@ "remoteControlQrHelp": "Escanea este código QR con QBZ-Control para emparejar.", "remoteControlUrlLabel": "URL local", "remoteControlQrAlt": "Código QR de emparejamiento", + "plexConnection": "Conexión Plex", + "plexConnectionLore": "Accede a tu biblioteca de Plex desde QBZ Local Library. Esta integración solo soporta servidores Plex locales o en LAN para garantizar direct play.", + "plexServerUrl": "URL del servidor Plex", + "plexServerUrlPlaceholder": "http://ip-local", + "plexServerPort": "Puerto", + "plexLocalAddressRequired": "Usa una dirección Plex local o LAN. Los endpoints remotos no están soportados en este modo.", + "plexAuthorizeSectionTitle": "Autorizar QBZ", + "plexAuthorizeSectionLore": "Autoriza QBZ para conectarse con tu servidor Plex.", + "plexAuthorizeHelp": "Revisa tu navegador externo para completar la autorización.", + "plexAuthorizeLabel": "Autorizar QBZ para conectarse con tu servidor Plex", + "plexCodeEmpty": "Aún no se generó código", + "plexCodeTooltip": "Copiar código", + "plexManualTokenToggle": "O ingresa tu Plex X-Token manualmente", + "plexConnectionCheckLabel": "Comprobar conexión con Plex", + "plexGetLibrariesLabel": "Obtener bibliotecas de música de Plex", + "plexGetLibrariesHelp": "Re-sincroniza si agregaste bibliotecas nuevas en tu servidor Plex.", + "plexMusicLibraries": "Bibliotecas de música", + "plexTracksShort": "pistas", + "plexDisconnectRowLabel": "Desconectar Plex", + "plexClearCacheRowLabel": "Limpiar caché de Plex en QBZ", + "plexClearCacheRowHelp": "Recomendado si notas inconsistencias en la biblioteca.", + "plexClearButton": "Limpiar", "plexPoc": "Plex LAN POC", "plexPocDesc": "Integración experimental solo local. Usa partes directas de medios desde Plex sin reemplazar la reproducción de QBZ.", "plexLibraryIntegrationNote": "La música de Plex se integra en Local Library (misma cola/reproductor, sin pestaña separada).", @@ -732,6 +754,7 @@ "plexMusicSection": "Sección de música", "plexSelectSection": "Selecciona una sección", "plexStatusIdle": "Listo para pruebas LAN con Plex.", + "plexStatusDisabled": "La conexión con Plex está desactivada.", "plexStatusAuthPending": "Inicio de sesión de Plex iniciado. Completa la autorización con el código {code}.", "plexStatusAuthConnected": "Token de Plex recibido correctamente.", "plexStatusAuthExpired": "El código de inicio de Plex expiró. Inicia la conexión nuevamente.", diff --git a/src/lib/i18n/locales/fr.json b/src/lib/i18n/locales/fr.json index 5575916df..5f0f8c2c4 100644 --- a/src/lib/i18n/locales/fr.json +++ b/src/lib/i18n/locales/fr.json @@ -670,6 +670,8 @@ "plexAuthCode": "Code Plex : {code}", "plexCodeCopied": "Code Plex copié.", "plexCodeCopyFailed": "Impossible de copier le code Plex.", + "plexStatusIdle": "Prêt pour les vérifications Plex LAN.", + "plexStatusDisabled": "La connexion Plex est désactivée.", "plexStatusAuthPending": "Connexion Plex démarrée. Terminez l'autorisation avec le code {code}.", "plexStatusAuthConnected": "Jeton Plex reçu avec succès.", "plexStatusAuthExpired": "Le code de connexion Plex a expiré. Relancez la connexion.", @@ -709,6 +711,28 @@ "remoteControlQrHelp": "Scannez ce code QR avec QBZ-Control pour appairer.", "remoteControlUrlLabel": "URL locale", "remoteControlQrAlt": "Code QR d'appairage", + "plexConnection": "Connexion Plex", + "plexConnectionLore": "Accédez à votre bibliothèque Plex depuis la Local Library de QBZ. Cette intégration prend uniquement en charge les serveurs Plex locaux et LAN pour garantir le direct play.", + "plexServerUrl": "URL du serveur Plex", + "plexServerUrlPlaceholder": "http://adresse-ip-locale", + "plexServerPort": "Port", + "plexLocalAddressRequired": "Utilisez une adresse Plex locale ou LAN. Les endpoints distants ne sont pas pris en charge dans ce mode.", + "plexAuthorizeSectionTitle": "Autoriser QBZ", + "plexAuthorizeSectionLore": "Autorisez QBZ à se connecter à votre serveur Plex.", + "plexAuthorizeHelp": "Vérifiez votre navigateur externe pour terminer l'autorisation.", + "plexAuthorizeLabel": "Autoriser QBZ à se connecter à votre serveur Plex", + "plexCodeEmpty": "Aucun code généré pour le moment", + "plexCodeTooltip": "Copier le code", + "plexManualTokenToggle": "Ou saisissez directement votre Plex X-Token", + "plexConnectionCheckLabel": "Vérifier la connexion Plex", + "plexGetLibrariesLabel": "Récupérer les bibliothèques musicales Plex", + "plexGetLibrariesHelp": "Re-synchronisez si de nouvelles bibliothèques ont été ajoutées sur votre serveur Plex.", + "plexMusicLibraries": "Bibliothèques musicales", + "plexTracksShort": "pistes", + "plexDisconnectRowLabel": "Déconnecter Plex", + "plexClearCacheRowLabel": "Effacer le cache Plex dans QBZ", + "plexClearCacheRowHelp": "Recommandé si vous remarquez des incohérences dans la bibliothèque.", + "plexClearButton": "Effacer", "plexStatusCacheLoaded": "{count} pistes en cache chargées. Actualisation depuis Plex en arrière-plan." }, "storage": {