Kaleido-Desktop/src/app/settings.ts
Elijah d9e22dde2e Handle stopped streams, live bandwidth, and rework the upscaling tiers
When the server owner stops a stream, Plex cuts the connection and repeats
the termination in every timeline reply to the client until it reports a
stop. The player now reads those replies (also when playback stalls or
fails), stops mpv, shows the owner's message and acknowledges it; a
termination on a session's first reply is left over from an earlier stream
and is cleared instead of cancelling the new one. Each title also starts
unpaused, as mpv keeps pause across files.

The dashboard's bandwidth graph refreshes every second. Plex's real-time
samples are bytes per second with idle seconds omitted, so they are laid on
a gap-free per-second axis (they were divided by six before).

Upscaling: Balanced is now the strongest shader chain, light nlmeans,
FSRCNNX 16, KrigBilateral and debanding. Measured against 1080p references
shrunk to 480p it beat FSRCNNX 8, two network passes, RAVU and
SSimSuperRes. The denoiser is AN3223's light profile with luma strength at
60%, which keeps texture the default profile smoothed away. Quality is now
NVIDIA RTX Video Super Resolution through mpv's d3d11vpp filter, sized to
the window and re-applied when it changes; it is offered only on Windows
with an NVIDIA RTX GPU (app_info now lists the adapters), runs Balanced for
HDR or at native size, and drops a tier if the driver refuses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 12:09:34 -07:00

154 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<string, { sort: string; filters: Record<string, string> }>;
}
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<K extends keyof Preferences>(key: K, value: Preferences[K]): void;
reset(): void;
}
export const useSettings = create<SettingsState>()(
persist(
(set) => ({
...defaults,
set: (key, value) => set({ [key]: value } as Partial<SettingsState>),
reset: () => set({ ...defaults }),
}),
{
name: 'kaleido.settings',
version: 2,
migrate: (persisted, version) => {
const p = (persisted ?? {}) as Record<string, unknown>;
// 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<Quality, string> = {
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<Exclude<Quality, 'original'>, { 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<SubtitlePosition, number> = { low: 14, normal: 34, high: 80 };
export const UPSCALING: Record<Upscaling, { label: string; detail: string }> = {
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' },
};