mirror of
https://github.com/Boof2015/prism.git
synced 2026-08-18 19:44:16 +02:00
add initial support for more integrations in the now playing panel
This commit is contained in:
+33
-11
@@ -12,7 +12,7 @@ import {
|
||||
type PrismProfileFileV2,
|
||||
type PrismProfileLocalStateV1,
|
||||
} from '../types/profile'
|
||||
import { AUDIO_SCOPE_KINDS, SCOPE_KINDS, type ScopeKind } from '../types/scope'
|
||||
import { AUDIO_SCOPE_KINDS, SCOPE_KINDS, normalizeScopeKind, type ScopeKind } from '../types/scope'
|
||||
import { DEFAULT_SCOPE_SETTINGS, type ScopeSettings } from '../types/settings'
|
||||
import { normalizeSpectrumPeakInfoMode } from '../types/spectrum'
|
||||
|
||||
@@ -27,11 +27,11 @@ export const DEFAULT_SCOPE_WIDTH_WEIGHTS: Record<ScopeKind, number> = {
|
||||
vumeter: 0.5,
|
||||
lufsmeter: 0.5,
|
||||
waveform: 1,
|
||||
astra: 1,
|
||||
nowPlaying: 1,
|
||||
}
|
||||
|
||||
export function isScopeKind(value: unknown): value is ScopeKind {
|
||||
return typeof value === 'string' && SCOPE_KINDS.includes(value as ScopeKind)
|
||||
return normalizeScopeKind(value) !== null
|
||||
}
|
||||
|
||||
export function cloneScopeSettings(settings: ScopeSettings): ScopeSettings {
|
||||
@@ -73,11 +73,12 @@ export function normalizeWindowBounds(
|
||||
export function normalizeScopeOrder(raw: unknown): ScopeKind[] {
|
||||
if (!Array.isArray(raw)) return [...DEFAULT_SCOPE_ORDER]
|
||||
|
||||
const valid = raw.filter(isScopeKind)
|
||||
const seen = new Set<ScopeKind>()
|
||||
const normalized: ScopeKind[] = []
|
||||
|
||||
for (const kind of valid) {
|
||||
for (const rawKind of raw) {
|
||||
const kind = normalizeScopeKind(rawKind)
|
||||
if (!kind) continue
|
||||
if (seen.has(kind)) continue
|
||||
seen.add(kind)
|
||||
normalized.push(kind)
|
||||
@@ -97,16 +98,25 @@ export function normalizeHiddenScopes(raw: unknown): ScopeKind[] {
|
||||
return SCOPE_KINDS.filter((kind) => !DEFAULT_VISIBLE.includes(kind))
|
||||
}
|
||||
|
||||
return raw.filter(isScopeKind)
|
||||
const seen = new Set<ScopeKind>()
|
||||
const normalized: ScopeKind[] = []
|
||||
for (const rawKind of raw) {
|
||||
const kind = normalizeScopeKind(rawKind)
|
||||
if (!kind || seen.has(kind)) continue
|
||||
seen.add(kind)
|
||||
normalized.push(kind)
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
export function normalizeWidthWeights(raw: unknown): Record<ScopeKind, number> {
|
||||
const parsed = typeof raw === 'object' && raw !== null
|
||||
? raw as Partial<Record<ScopeKind, unknown>>
|
||||
: {}
|
||||
const legacyParsed = parsed as Partial<Record<ScopeKind | 'astra', unknown>>
|
||||
|
||||
return SCOPE_KINDS.reduce((acc, kind) => {
|
||||
const value = parsed[kind]
|
||||
const value = legacyParsed[kind] ?? (kind === 'nowPlaying' ? legacyParsed.astra : undefined)
|
||||
acc[kind] = typeof value === 'number' && Number.isFinite(value)
|
||||
? Math.max(0.1, value)
|
||||
: DEFAULT_SCOPE_WIDTH_WEIGHTS[kind]
|
||||
@@ -118,9 +128,15 @@ export function mergeScopeSettings(raw: unknown): ScopeSettings {
|
||||
const parsed = typeof raw === 'object' && raw !== null
|
||||
? raw as Partial<ScopeSettings>
|
||||
: {}
|
||||
const legacyParsed = parsed as Partial<ScopeSettings> & {
|
||||
astra?: Partial<ScopeSettings['nowPlaying']>
|
||||
}
|
||||
const rawSpectrum: Partial<ScopeSettings['spectrum']> = typeof parsed.spectrum === 'object' && parsed.spectrum !== null
|
||||
? parsed.spectrum
|
||||
: {}
|
||||
const rawNowPlaying: Partial<ScopeSettings['nowPlaying']> = typeof legacyParsed.nowPlaying === 'object' && legacyParsed.nowPlaying !== null
|
||||
? legacyParsed.nowPlaying
|
||||
: (typeof legacyParsed.astra === 'object' && legacyParsed.astra !== null ? legacyParsed.astra : {})
|
||||
|
||||
return {
|
||||
spectrum: {
|
||||
@@ -134,7 +150,7 @@ export function mergeScopeSettings(raw: unknown): ScopeSettings {
|
||||
vumeter: { ...DEFAULT_SCOPE_SETTINGS.vumeter, ...(parsed.vumeter ?? {}) },
|
||||
lufsmeter: { ...DEFAULT_SCOPE_SETTINGS.lufsmeter, ...(parsed.lufsmeter ?? {}) },
|
||||
waveform: { ...DEFAULT_SCOPE_SETTINGS.waveform, ...(parsed.waveform ?? {}) },
|
||||
astra: { ...DEFAULT_SCOPE_SETTINGS.astra, ...(parsed.astra ?? {}) },
|
||||
nowPlaying: { ...DEFAULT_SCOPE_SETTINGS.nowPlaying, ...rawNowPlaying },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +159,10 @@ export function normalizeScopePopouts(raw: unknown): ScopePopoutStateMap {
|
||||
const parsed = typeof raw === 'object' && raw !== null
|
||||
? raw as Partial<Record<ScopeKind, Partial<ScopePopoutStateMap[ScopeKind]>>>
|
||||
: {}
|
||||
const legacyParsed = parsed as Partial<Record<ScopeKind | 'astra', Partial<ScopePopoutStateMap[ScopeKind]>>>
|
||||
|
||||
for (const kind of SCOPE_KINDS) {
|
||||
const value = parsed[kind]
|
||||
const value = legacyParsed[kind] ?? (kind === 'nowPlaying' ? legacyParsed.astra : undefined)
|
||||
defaults[kind] = {
|
||||
poppedOut: Boolean(value?.poppedOut),
|
||||
windowBounds: normalizeWindowBounds(value?.windowBounds),
|
||||
@@ -192,9 +209,11 @@ export function normalizeProfileFileScopePopouts(raw: unknown): PrismProfileFile
|
||||
const parsed = typeof raw === 'object' && raw !== null
|
||||
? raw as Partial<Record<ScopeKind, { poppedOut?: unknown }>>
|
||||
: {}
|
||||
const legacyParsed = parsed as Partial<Record<ScopeKind | 'astra', { poppedOut?: unknown }>>
|
||||
|
||||
return SCOPE_KINDS.reduce((acc, kind) => {
|
||||
acc[kind] = { poppedOut: Boolean(parsed[kind]?.poppedOut) }
|
||||
const value = legacyParsed[kind] ?? (kind === 'nowPlaying' ? legacyParsed.astra : undefined)
|
||||
acc[kind] = { poppedOut: Boolean(value?.poppedOut) }
|
||||
return acc
|
||||
}, {} as PrismProfileFileScopePopoutMap)
|
||||
}
|
||||
@@ -253,7 +272,10 @@ export function normalizeProfileLocalMetadata(raw: unknown): ProfileLocalMetadat
|
||||
|
||||
const scopePopoutBounds = typeof parsed.scopePopoutBounds === 'object' && parsed.scopePopoutBounds !== null
|
||||
? SCOPE_KINDS.reduce((acc, kind) => {
|
||||
const bounds = normalizeWindowBounds(parsed.scopePopoutBounds?.[kind])
|
||||
const legacyBounds = parsed.scopePopoutBounds as Partial<Record<ScopeKind | 'astra', unknown>> | undefined
|
||||
const bounds = normalizeWindowBounds(
|
||||
legacyBounds?.[kind] ?? (kind === 'nowPlaying' ? legacyBounds?.astra : undefined),
|
||||
)
|
||||
if (bounds) {
|
||||
acc[kind] = bounds
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user