diff --git a/src/app/App.tsx b/src/app/App.tsx index 6623697..c0e8786 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -11,7 +11,7 @@ import { PageLoader } from '../ui/primitives'; import { Splash } from '../screens/Splash'; import { SignIn } from '../screens/SignIn'; import { ServerPicker } from '../screens/ServerPicker'; -import { isMac, win } from '../platform/native'; +import { isMac, isNative, win } from '../platform/native'; import { usePlayer } from '../player/store'; import { PlayerOverlay } from '../player/PlayerOverlay'; import { DialogHost } from '../screens/dialogs/DialogHost'; @@ -111,7 +111,9 @@ function useGlobalShortcuts() { win.isFullscreen().then((fs) => win.setFullscreen(!fs)); } else if ((e.key === 'Escape' || e.key === 'Backspace') && !isTyping(e.target) && !document.querySelector('.menu-layer, .dialog-layer')) { if (e.key === 'Escape' && document.fullscreenElement) return; - useRouter.getState().back(); + // Esc leaves full screen first (kept from the player when it went to the corner). + if (e.key === 'Escape' && isNative) win.isFullscreen().then((fs) => (fs ? win.setFullscreen(false) : useRouter.getState().back())); + else useRouter.getState().back(); } else if ((e.ctrlKey || e.metaKey) && e.key === ',') { e.preventDefault(); navigate({ name: 'settings', mode: 'app', tab: 'general' }); diff --git a/src/app/TopBar.tsx b/src/app/TopBar.tsx index 3c538fc..6007226 100644 --- a/src/app/TopBar.tsx +++ b/src/app/TopBar.tsx @@ -19,13 +19,21 @@ const NAV = [ /** Caption buttons drawn by the page; macOS shows its own traffic lights instead. */ export function WindowControls() { const [maximized, setMaximized] = useState(false); + const [fullscreen, setFullscreen] = useState(false); useEffect(() => { if (!isNative || isMac) return; let off: (() => void) | undefined; - const sync = () => win.isMaximized().then(setMaximized); + let gone = false; + const sync = () => { + win.isMaximized().then((m) => !gone && setMaximized(m)); + win.isFullscreen().then((f) => !gone && setFullscreen(f)); + }; sync(); - win.onResized(sync).then((u) => (off = u)); - return () => off?.(); + win.onResized(sync).then((u) => (gone ? u() : (off = u))); + return () => { + gone = true; + off?.(); + }; }, []); if (!isNative || isMac) return null; return ( @@ -33,9 +41,15 @@ export function WindowControls() { win.minimize()}> - win.toggleMaximize()}> - - + {fullscreen ? ( + win.setFullscreen(false)}> + + + ) : ( + win.toggleMaximize()}> + + + )} win.close()}> diff --git a/src/app/format.ts b/src/app/format.ts index 47d138a..a41b82d 100644 --- a/src/app/format.ts +++ b/src/app/format.ts @@ -174,17 +174,24 @@ export function plural(n: number, word: string, pluralWord = `${word}s`) { return `${n.toLocaleString()} ${n === 1 ? word : pluralWord}`; } -/** Hex UltraBlur colors → CSS gradient layers for the artwork colour wash. */ -export function washGradient(u: Item['ultraBlur'], strength = 1): string { - if (!u) return ''; +/** Hex UltraBlur colors → the wash's four corner colours, each at its own strength. */ +export function washColors(u: Item['ultraBlur'], strength = 1) { + if (!u) return null; const c = (hex: string, a: number) => { const n = parseInt(hex, 16); return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${(a * strength).toFixed(3)})`; }; + return { topRight: c(u.topRight, 0.95), topLeft: c(u.topLeft, 0.7), bottomRight: c(u.bottomRight, 0.55), bottomLeft: c(u.bottomLeft, 0.45) }; +} + +/** Hex UltraBlur colors → CSS gradient layers for the artwork colour wash. */ +export function washGradient(u: Item['ultraBlur'], strength = 1): string { + const c = washColors(u, strength); + if (!c) return ''; return [ - `radial-gradient(ellipse at 100% 0%, ${c(u.topRight, 0.95)} 0%, transparent 62%)`, - `radial-gradient(ellipse at 0% 0%, ${c(u.topLeft, 0.7)} 0%, transparent 55%)`, - `radial-gradient(ellipse at 100% 100%, ${c(u.bottomRight, 0.55)} 0%, transparent 60%)`, - `radial-gradient(ellipse at 0% 100%, ${c(u.bottomLeft, 0.45)} 0%, transparent 60%)`, + `radial-gradient(ellipse at 100% 0%, ${c.topRight} 0%, transparent 62%)`, + `radial-gradient(ellipse at 0% 0%, ${c.topLeft} 0%, transparent 55%)`, + `radial-gradient(ellipse at 100% 100%, ${c.bottomRight} 0%, transparent 60%)`, + `radial-gradient(ellipse at 0% 100%, ${c.bottomLeft} 0%, transparent 60%)`, ].join(', '); } diff --git a/src/player/store.ts b/src/player/store.ts index 3b1439d..ca60b1e 100644 --- a/src/player/store.ts +++ b/src/player/store.ts @@ -702,10 +702,12 @@ export const usePlayer = create((set, get) => ({ playServer = s; playDownload = download; localScrobbled = false; + // From the miniplayer the window may have gone full screen (or left it) since. + const fullscreenNow = await win.isFullscreen().catch(() => false); + if (stale()) return; if (!previous.open) { triedFallback = false; - wasFullscreenBeforePlay = await win.isFullscreen().catch(() => false); - if (stale()) return; + wasFullscreenBeforePlay = fullscreenNow; } set({ open: true, @@ -730,7 +732,7 @@ export const usePlayer = create((set, get) => ({ audioKey: opts.tracks?.audioKey ?? '', subKey: opts.tracks?.subKey ?? '__init', video: null, - fullscreen: wasFullscreenBeforePlay, + fullscreen: fullscreenNow, mini: false, videoGamma: '', enhance: { ...previous.enhance, bypass: false, preparing: false }, @@ -856,8 +858,12 @@ export const usePlayer = create((set, get) => ({ await mpv.show(false).catch(() => {}); } set({ open: false, mini: false, item: null, delivery: null, error: '', terminated: false, countdown: null, nextUp: null, prevUp: null, firstFrame: false }); - const fs = await win.isFullscreen().catch(() => false); - if (fs && !wasFullscreenBeforePlay) win.setFullscreen(false); + // Closing the full player hands back the window it found; closing the + // miniplayer leaves browsing as it is, full screen or not. + if (!st.mini) { + const fs = await win.isFullscreen().catch(() => false); + if (fs && !wasFullscreenBeforePlay) win.setFullscreen(false); + } if (st.item) invalidateLibrary(); }, @@ -913,12 +919,8 @@ export const usePlayer = create((set, get) => ({ async minimize() { const st = get(); if (!st.open || st.mini) return; + // Full screen stays for browsing; Esc or the window controls leave it. set({ mini: true }); - // Full screen was for the video; browsing goes back to the window. - if (st.fullscreen && !wasFullscreenBeforePlay) { - await win.setFullscreen(false).catch(() => {}); - set({ fullscreen: false }); - } if (separateMini) { // Once the page is opaque again (no video in it), the video moves into // the miniplayer's own window (miniWindow.ts). @@ -1025,6 +1027,13 @@ usePlayer.subscribe((st, prev) => { bridgeMiniWindow(usePlayer); +// Full screen can change outside the player (Esc or the window controls while +// browsing with the miniplayer, the OS): the player's controls follow it. +win.onResized(() => { + if (!usePlayer.getState().open) return; + win.isFullscreen().then((fs) => usePlayer.getState().fullscreen !== fs && usePlayer.setState({ fullscreen: fs }), () => {}); +}); + /** * Signing out, or switching server or profile, ends a stream from the old one: its * progress belongs to that account. A download keeps playing, without reporting. diff --git a/src/styles/app.css b/src/styles/app.css index a1d258e..8f670c6 100644 --- a/src/styles/app.css +++ b/src/styles/app.css @@ -515,6 +515,12 @@ html.splash-arrival .auth-screen { .backdrop-layer.ready { opacity: 1; } +/* The outgoing art fades too, a beat behind the incoming, so nothing of it is + left to vanish through the new art's faded edges. */ +.backdrop-layer.ready.leaving { + opacity: 0; + transition-delay: 180ms; +} /* The colour wash lives outside the clipped backdrop so it can carry on down the page behind the rows, fading out as it goes. */ .backdrop-tint { @@ -528,14 +534,42 @@ html.splash-arrival .auth-screen { -webkit-mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, 0.75) 45%, transparent 100%); mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, 0.75) 45%, transparent 100%); } +/* Registered as colours so a change of title blends the wash from one set of + colours to the next, instead of swapping the gradient outright. */ +@property --wash-tr { + syntax: ''; + inherits: false; + initial-value: transparent; +} +@property --wash-tl { + syntax: ''; + inherits: false; + initial-value: transparent; +} +@property --wash-br { + syntax: ''; + inherits: false; + initial-value: transparent; +} +@property --wash-bl { + syntax: ''; + inherits: false; + initial-value: transparent; +} .backdrop-wash { position: absolute; inset: 0; - opacity: 0; - transition: opacity 420ms var(--ease); -} -.backdrop-wash.ready { opacity: 0.5; + background: + radial-gradient(ellipse at 100% 0%, var(--wash-tr) 0%, transparent 62%), + radial-gradient(ellipse at 0% 0%, var(--wash-tl) 0%, transparent 55%), + radial-gradient(ellipse at 100% 100%, var(--wash-br) 0%, transparent 60%), + radial-gradient(ellipse at 0% 100%, var(--wash-bl) 0%, transparent 60%); + transition: + --wash-tr 700ms var(--ease), + --wash-tl 700ms var(--ease), + --wash-br 700ms var(--ease), + --wash-bl 700ms var(--ease); } .backdrop-art { position: absolute; diff --git a/src/ui/Backdrop.tsx b/src/ui/Backdrop.tsx index 15116b6..f3338a9 100644 --- a/src/ui/Backdrop.tsx +++ b/src/ui/Backdrop.tsx @@ -1,21 +1,25 @@ -import { useEffect, useRef, useState } from 'react'; +import { useEffect, useRef, useState, type CSSProperties } from 'react'; import type { Item } from '../plex/types'; import { useServer } from '../app/session'; import { useSettings } from '../app/settings'; -import { art, washGradient } from '../app/format'; +import { art, washColors } from '../app/format'; interface Layer { key: number; src: string; - wash: string; + blur: Item['ultraBlur']; ready: boolean; } +/** How long an outgoing layer lingers: its fade (with delay) plus a margin. */ +const LEAVE_MS = 700; + /** * Artwork-led page background. The image sits top-right and fades into the * page toward its left and bottom edges; the UltraBlur colour wash tints the - * page beneath it and carries on down behind the rows. Changes crossfade; the - * outgoing layer stays until the new image has decoded. + * page beneath it and carries on down behind the rows. Artwork crossfades + * once the new image has decoded, and the wash's colours blend into the new + * title's at the same moment (registered custom properties, app.css). */ export function Backdrop({ item, className = '', width = 1600, height = 900, wash: forceWash }: { item: Item | null | undefined; className?: string; width?: number; height?: number; wash?: Item['ultraBlur'] }) { const server = useServer(); @@ -25,39 +29,50 @@ export function Backdrop({ item, className = '', width = 1600, height = 900, was const path = item ? art.backdrop(item) : ''; const src = path ? server.image(path, width, height) : ''; const blur = forceWash ?? item?.ultraBlur ?? null; - const wash = colorWash && blur ? washGradient(blur) : ''; + const blurKey = blur ? `${blur.topLeft}${blur.topRight}${blur.bottomRight}${blur.bottomLeft}` : ''; useEffect(() => { - if (!src && !wash) return; + if (!src && !blur) return; setLayers((prev) => { - if (prev.length && prev[prev.length - 1].src === src) { - // Same art, maybe new wash. - return prev.map((l, i) => (i === prev.length - 1 ? { ...l, wash } : l)); - } - return [...prev.slice(-1), { key: ++counter.current, src, wash, ready: !src }]; + const last = prev[prev.length - 1]; + // Same art, maybe new colours: the wash blends to them in place. + if (last && last.src === src) return prev.map((l) => (l === last ? { ...l, blur } : l)); + // Keep only what is on screen (the newest layer that has shown) under the new one. + const shown = prev.filter((l) => l.ready).slice(-1); + return [...shown, { key: ++counter.current, src, blur, ready: !src }]; }); - }, [src, wash]); + }, [src, blurKey]); - const onReady = (key: number) => - setLayers((prev) => { - const idx = prev.findIndex((l) => l.key === key); - if (idx < 0) return prev; - const next = prev.map((l) => (l.key === key ? { ...l, ready: true } : l)); - // Drop older layers once the newest is visible (after its fade). - setTimeout(() => setLayers((p) => (p.length > 1 && p[p.length - 1].key === key ? p.slice(-1) : p)), 500); - return next; - }); + const onReady = (key: number) => setLayers((prev) => (prev.some((l) => l.key === key && !l.ready) ? prev.map((l) => (l.key === key ? { ...l, ready: true } : l)) : prev)); + + // Once the newest layer is in, the ones beneath fade out and then go. + const newest = layers[layers.length - 1]; + useEffect(() => { + if (!newest?.ready || layers.length < 2) return; + const t = setTimeout(() => setLayers((p) => (p[p.length - 1]?.key === newest.key ? p.slice(-1) : p)), LEAVE_MS); + return () => clearTimeout(t); + }, [newest?.key, newest?.ready, layers.length]); + + let top = -1; + layers.forEach((l, i) => l.ready && (top = i)); + const colors = top >= 0 ? washColors(layers[top].blur) : null; + const washStyle = { + '--wash-tr': colors?.topRight ?? 'transparent', + '--wash-tl': colors?.topLeft ?? 'transparent', + '--wash-br': colors?.bottomRight ?? 'transparent', + '--wash-bl': colors?.bottomLeft ?? 'transparent', + } as CSSProperties; return ( <> {colorWash && ( - {layers.map((l) => l.wash && )} + )} - {layers.map((l) => ( - + {layers.map((l, i) => ( + {l.src && onReady(l.key)} onError={() => onReady(l.key)} />} ))}