import { create } from 'zustand'; import { persist } from 'zustand/middleware'; export type Quality = 'original' | '2160' | '1080' | '720' | '480'; export type SkipMode = 'off' | 'button' | 'auto'; export type SubtitleMode = 'auto' | 'always' | 'forced' | 'off'; export type SubtitleEdge = 'outline' | 'shadow' | 'raised' | 'none'; export type SubtitleBox = 'none' | 'translucent' | 'solid'; export type SubtitlePosition = 'low' | 'normal' | 'high'; export type Upscaling = 'off' | 'performance' | 'balanced' | 'quality'; export interface Preferences { // Playback quality: Quality; remoteQuality: Quality; hwdec: boolean; hdrPassthrough: boolean; autoplayNext: boolean; countdownSeconds: number; skipIntro: SkipMode; skipCredits: SkipMode; watchedPercent: number; audioLanguage: string; subtitleMode: SubtitleMode; subtitleLanguage: string; subtitleScale: number; subtitleColor: string; subtitleEdge: SubtitleEdge; subtitleBox: SubtitleBox; subtitleBold: boolean; subtitlePosition: SubtitlePosition; volume: number; seekStep: number; /** Video enhancement, chosen in the player, and its optional stages. */ upscaling: Upscaling; enhanceDeband: boolean; enhanceSharpen: boolean; enhanceDenoise: boolean; // Interface startPage: 'home' | 'movies' | 'shows'; colorWash: boolean; reducedMotion: boolean; posterSize: 'compact' | 'comfortable' | 'large'; heroRotation: boolean; themeMusic: boolean; themeVolume: number; // Libraries shown for Movies and TV Shows movieSection: string; showSection: string; // Downloads downloadDir: string; // Remembered library views per section libraryViews: Record }>; } export const defaults: Preferences = { quality: 'original', remoteQuality: '1080', hwdec: true, hdrPassthrough: true, autoplayNext: true, countdownSeconds: 8, skipIntro: 'button', skipCredits: 'button', watchedPercent: 90, audioLanguage: '', subtitleMode: 'auto', subtitleLanguage: '', subtitleScale: 1, subtitleColor: '#FFFFFF', subtitleEdge: 'outline', subtitleBox: 'none', subtitleBold: false, subtitlePosition: 'normal', volume: 100, seekStep: 10, upscaling: 'off', enhanceDeband: true, enhanceSharpen: true, enhanceDenoise: true, startPage: 'home', colorWash: true, reducedMotion: false, posterSize: 'comfortable', heroRotation: true, themeMusic: false, themeVolume: 30, movieSection: '', showSection: '', downloadDir: '', libraryViews: {}, }; interface SettingsState extends Preferences { set(key: K, value: Preferences[K]): void; reset(): void; } export const useSettings = create()( persist( (set) => ({ ...defaults, set: (key, value) => set({ [key]: value } as Partial), reset: () => set({ ...defaults }), }), { name: 'kaleido.settings', version: 2, migrate: (persisted, version) => { const p = (persisted ?? {}) as Record; // 1 → 2: the subtitle background switch became a box style. if (version < 2 && 'subtitleBackground' in p) { p.subtitleBox = p.subtitleBackground ? 'translucent' : 'none'; delete p.subtitleBackground; } return p as unknown as SettingsState; }, }, ), ); export const QUALITY_LABEL: Record = { original: 'Original quality', '2160': '4K (40 Mbps)', '1080': '1080p (20 Mbps)', '720': '720p (4 Mbps)', '480': '480p (1.5 Mbps)', }; export const QUALITY_PROFILE: Record, { kbps: number; width: number; height: number }> = { '2160': { kbps: 40000, width: 3840, height: 2160 }, '1080': { kbps: 20000, width: 1920, height: 1080 }, '720': { kbps: 4000, width: 1280, height: 720 }, '480': { kbps: 1500, width: 854, height: 480 }, }; export const SUBTITLE_COLORS: { value: string; label: string }[] = [ { value: '#FFFFFF', label: 'White' }, { value: '#FFE14D', label: 'Yellow' }, { value: '#7FE3F0', label: 'Cyan' }, { value: '#9BE58A', label: 'Green' }, { value: '#F4A6D7', label: 'Pink' }, { value: '#BFC5CA', label: 'Grey' }, ]; /** Bottom margin in mpv's scaled pixels (720 = window height). */ export const SUBTITLE_MARGIN: Record = { low: 14, normal: 34, high: 80 }; export const UPSCALING: Record = { off: { label: 'Off', detail: 'mpv’s standard scaling' }, performance: { label: 'Performance', detail: 'Sharp scaling, debanding and light sharpening' }, balanced: { label: 'Balanced', detail: 'Light denoising, neural upscaling (FSRCNNX 16), colour reconstruction, debanding and sharpening' }, quality: { label: 'Quality', detail: 'NVIDIA RTX Video Super Resolution: AI upscaling that also cleans up compression. SDR video; HDR uses Balanced' }, };