fix(ui): unify titlebar and playback state

- window buttons live in the page header on library/search pages and in a shared chrome strip where a page has no header; removed the 44px root padding toggle that made pages jump on navigation
- video player gets its own titlebar row with window controls; the audio player hides the global app bar
- starting a video stops music and vice versa; a single track queues the rest of its album, or the artist's songs when AlbumId is missing
- album page no longer crashes on albums without AlbumArtists
- queue summary is localized
This commit is contained in:
1xDed committed 2026-12-01 02:47:40 +03:00
1 parent d9bce4de04
commit fcf61012db
13 files changed
+245 -171

No files matched your search

+66 -1
View File
@@ -1,7 +1,10 @@
import { import {
type BaseItemDto, type BaseItemDto,
BaseItemKind, BaseItemKind,
ItemFields,
SortOrder,
} from "@jellyfin/sdk/lib/generated-client"; } from "@jellyfin/sdk/lib/generated-client";
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
import { getShowApi } from "@jellyfin/sdk/lib/utils/api/show-api"; import { getShowApi } from "@jellyfin/sdk/lib/utils/api/show-api";
import type { SxProps } from "@mui/material"; import type { SxProps } from "@mui/material";
import Button, { type ButtonProps } from "@mui/material/Button"; import Button, { type ButtonProps } from "@mui/material/Button";
@@ -131,6 +134,7 @@ const PlayButton = ({
if (audio) { if (audio) {
// Album/Individual audio track playback // Album/Individual audio track playback
const playedItem = result?.item?.Items?.[0];
const playbackUrl = generateAudioStreamUrl( const playbackUrl = generateAudioStreamUrl(
result?.item?.Items?.[0].Id, result?.item?.Items?.[0].Id,
userId, userId,
@@ -139,7 +143,68 @@ const PlayButton = ({
api.accessToken, api.accessToken,
); );
playAudio(playbackUrl, result?.item?.Items?.[0], undefined); playAudio(playbackUrl, result?.item?.Items?.[0], undefined);
setQueue(result?.item?.Items ?? [], 0);
if (
playedItem?.Type === BaseItemKind.Audio &&
(result?.item?.Items?.length ?? 0) <= 1
) {
// A single track has no queue of its own. Queue the record it
// belongs to; when the server does not expose AlbumId, fall
// back to the artist's songs so "Очередь" is never empty.
const loadQueue = async (): Promise<{
items: BaseItemDto[];
index: number;
}> => {
if (playedItem.AlbumId) {
const albumTracks = await getLibraryApi(api).getItems({
parentId: playedItem.AlbumId,
userId,
sortOrder: [SortOrder.Ascending],
sortBy: ["IndexNumber"],
fields: [ItemFields.MediaSources],
});
const items = albumTracks.data.Items ?? [];
if (items.length > 0) {
return {
items,
index: Math.max(
items.findIndex((t) => t.Id === playedItem.Id),
0,
),
};
}
}
const artistName =
playedItem.Artists?.[0] ?? playedItem.AlbumArtists?.[0]?.Name;
if (artistName) {
const artistTracks = await getLibraryApi(api).getItems({
userId,
includeItemTypes: [BaseItemKind.Audio],
artists: [artistName],
recursive: true,
sortBy: ["SortName"],
sortOrder: [SortOrder.Ascending],
fields: [ItemFields.MediaSources],
});
const items = artistTracks.data.Items ?? [];
const index = items.findIndex((t) => t.Id === playedItem.Id);
if (items.length > 1 && index >= 0) {
return { items, index };
}
}
return { items: [playedItem], index: 0 };
};
try {
const nextQueue = await loadQueue();
setQueue(nextQueue.items, nextQueue.index);
} catch (error) {
console.warn("Could not build the audio queue", error);
setQueue([playedItem], 0);
}
} else {
setQueue(result?.item?.Items ?? [], 0);
}
} else if (item.Type === "Photo") { } else if (item.Type === "Photo") {
const index = result?.item?.Items?.map((i) => i.Id).indexOf(item.Id); const index = result?.item?.Items?.map((i) => i.Id).indexOf(item.Id);
if (result?.item?.Items && index) { if (result?.item?.Items && index) {
+2
View File
@@ -25,6 +25,7 @@ import BackButton from "../buttons/backButton";
import CastButton from "../buttons/castButton"; import CastButton from "../buttons/castButton";
import { FiltersDialogTrigger } from "../filtersDialog"; import { FiltersDialogTrigger } from "../filtersDialog";
import { UserAvatarMenu } from "../userAvatarMenu"; import { UserAvatarMenu } from "../userAvatarMenu";
import WindowControls from "../windowControls";
import "./libraryHeader.scss"; import "./libraryHeader.scss";
const route = getRouteApi("/_api/library/$id"); const route = getRouteApi("/_api/library/$id");
@@ -417,6 +418,7 @@ export const LibraryHeader = () => {
<div className="material-symbols-rounded">favorite</div> <div className="material-symbols-rounded">favorite</div>
</IconButton> </IconButton>
<UserAvatarMenu /> <UserAvatarMenu />
<WindowControls />
</div> </div>
</AppBar> </AppBar>
<NavigationDrawer open={showDrawer} onClose={handleDrawerClose} /> <NavigationDrawer open={showDrawer} onClose={handleDrawerClose} />
@@ -20,13 +20,24 @@
--media-object-fit: fill; --media-object-fit: fill;
} }
&-drag-region { &-titlebar {
position: absolute; position: absolute;
inset: 0 0 auto; inset: 0 0 auto;
height: 38px; z-index: 3;
z-index: 4; display: flex;
cursor: default; align-items: center;
gap: 0.75em;
padding: 4px 8px;
min-height: 46px;
user-select: none; user-select: none;
&-end {
display: flex;
align-items: center;
gap: 0.5em;
margin-left: auto;
min-width: 0;
}
} }
&-osd { &-osd {
@@ -53,22 +64,16 @@
} }
&-back, &-back,
&-actions { &-actions {
position: absolute;
top: 2em;
z-index: 3;
display: flex; display: flex;
align-items: center; align-items: center;
flex: 0 0 auto;
padding: 0.3em; padding: 0.3em;
border-radius: 999px; border-radius: 999px;
border: 1px solid rgb(255 255 255 / 0.08); border: 1px solid rgb(255 255 255 / 0.08);
background: rgb(0 0 0 / 0.28); background: rgb(0 0 0 / 0.28);
backdrop-filter: blur(12px); backdrop-filter: blur(12px);
} }
&-back {
left: 3em;
}
&-actions { &-actions {
right: 3em;
gap: 0.35em; gap: 0.35em;
} }
&-info { &-info {
@@ -118,3 +123,26 @@
} }
} }
} }
// The window is frameless outside macOS: the player draws the titlebar row and
// the window buttons in the same strip the rest of the app uses on Windows and
// Linux, so they sit on the window edge instead of floating over the picture.
// macOS keeps its native traffic lights inside the overlay titlebar, so the
// player only has to clear them.
html.is-macos .video-player-titlebar {
padding-left: 84px;
padding-top: 14px;
min-height: 60px;
}
html.is-macos .video-player-titlebar.is-fullscreen {
padding-left: 8px;
padding-top: 4px;
min-height: 46px;
}
// A faded-out OSD keeps its buttons clickable otherwise; the titlebar would
// then catch clicks in the top corners while invisible.
.video-player-osd:not(.hovering) .video-player-titlebar {
pointer-events: none;
}
+56 -121
View File
@@ -15,9 +15,9 @@ import PlayNextButton from "@/components/buttons/playNextButton";
import PlayPreviousButton from "@/components/buttons/playPreviousButtom"; import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
import QueueButton from "@/components/buttons/queueButton"; import QueueButton from "@/components/buttons/queueButton";
import BubbleSlider from "@/components/playback/videoPlayer/bubbleSlider"; import BubbleSlider from "@/components/playback/videoPlayer/bubbleSlider";
import WindowControls from "@/components/windowControls";
import { secToTicks, ticksToSec } from "@/utils/date/time"; import { secToTicks, ticksToSec } from "@/utils/date/time";
import { buildPlayDeepLink } from "@/utils/deepLinks"; import { buildPlayDeepLink } from "@/utils/deepLinks";
import { getPlayerVideoElement } from "@/utils/methods/pictureInPicture";
import { openSyncPlayDialog } from "@/utils/methods/syncPlay"; import { openSyncPlayDialog } from "@/utils/methods/syncPlay";
import { useApiInContext } from "@/utils/store/api"; import { useApiInContext } from "@/utils/store/api";
import { useShareStore } from "@/utils/store/share"; import { useShareStore } from "@/utils/store/share";
@@ -88,6 +88,7 @@ const VideoPlayerControls = ({
isPlayerPlaying, isPlayerPlaying,
toggleIsPlaying, toggleIsPlaying,
toggleIsPlayerFullscreen, toggleIsPlayerFullscreen,
isPlayerFullscreen,
isUserSeeking, isUserSeeking,
// seekValue, // seekValue,
isPlayerMuted, isPlayerMuted,
@@ -112,6 +113,7 @@ const VideoPlayerControls = ({
playsessionId: state.playsessionId, playsessionId: state.playsessionId,
toggleIsPlaying: state.toggleIsPlaying, toggleIsPlaying: state.toggleIsPlaying,
toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen, toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen,
isPlayerFullscreen: state.playerState.isPlayerFullscreen,
isUserSeeking: state.playerState.isUserSeeking, isUserSeeking: state.playerState.isUserSeeking,
seekValue: state.playerState.seekValue, seekValue: state.playerState.seekValue,
isPlayerMuted: state.playerState.isPlayerMuted, isPlayerMuted: state.playerState.isPlayerMuted,
@@ -153,69 +155,6 @@ const VideoPlayerControls = ({
const [settingsMenuRef, setSettingsMenuRef] = const [settingsMenuRef, setSettingsMenuRef] =
useState<HTMLButtonElement | null>(null); useState<HTMLButtonElement | null>(null);
const [videoFrame, setVideoFrame] = useState<{
top: number;
left: number;
right: number;
} | null>(null);
// Keep the back button and the top action buttons on one line inside the
// visible video area, below any letterbox bars.
useEffect(() => {
let frame = 0;
const update = () => {
const video = getPlayerVideoElement();
if (!video) return;
const rect = video.getBoundingClientRect();
const ratio =
video.videoWidth > 0 && video.videoHeight > 0
? video.videoWidth / video.videoHeight
: null;
const contentWidth = ratio
? Math.min(rect.width, rect.height * ratio)
: rect.width;
const contentHeight = ratio ? contentWidth / ratio : rect.height;
const contentLeft = rect.left + (rect.width - contentWidth) / 2;
const contentTop = rect.top + (rect.height - contentHeight) / 2;
setVideoFrame((current) => {
const next = {
// 14% keeps the controls inside the picture even when the
// file has letterbox bars baked into a 16:9 frame.
top: Math.round(
contentTop + Math.max(28, contentHeight * 0.14),
),
left: Math.round(contentLeft + 24),
right: Math.round(
window.innerWidth - contentLeft - contentWidth + 24,
),
};
return current?.top === next.top &&
current?.left === next.left &&
current?.right === next.right
? current
: next;
});
};
const schedule = () => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(update);
};
schedule();
const video = getPlayerVideoElement();
video?.addEventListener("loadedmetadata", schedule);
window.addEventListener("resize", schedule);
const interval = window.setInterval(schedule, 1000);
return () => {
cancelAnimationFrame(frame);
window.clearInterval(interval);
video?.removeEventListener("loadedmetadata", schedule);
window.removeEventListener("resize", schedule);
};
}, [playsessionId]);
// const creditInfo = mediaSegments?.Items?.find( // const creditInfo = mediaSegments?.Items?.find(
// (segment) => segment.Type === "Outro", // (segment) => segment.Type === "Outro",
@@ -301,64 +240,60 @@ const VideoPlayerControls = ({
}} }}
> >
<div <div
className="video-player-osd-back" className={`video-player-titlebar${isPlayerFullscreen ? " is-fullscreen" : ""}`}
style={ data-tauri-drag-region
videoFrame
? { top: videoFrame.top, left: videoFrame.left }
: undefined
}
> >
<IconButton <div className="video-player-osd-back">
onClick={handleExitPlayer} <IconButton
aria-label="Выйти из плеера" onClick={handleExitPlayer}
title="Выйти из плеера" aria-label="Выйти из плеера"
> title="Выйти из плеера"
<span className="material-symbols-rounded">arrow_back</span> >
</IconButton> <span className="material-symbols-rounded">arrow_back</span>
</div> </IconButton>
<div </div>
className="video-player-osd-actions" <div className="video-player-titlebar-end">
style={ <div className="video-player-osd-actions">
videoFrame <IconButton
? { top: videoFrame.top, right: videoFrame.right } onClick={() =>
: undefined useShareStore
} .getState()
> .openShareDialog(
<IconButton buildPlayDeepLink(
onClick={() => itemId ?? "",
useShareStore currentTime > 0
.getState() ? ticksToSec(currentTime)
.openShareDialog( : getCurrentTime(),
buildPlayDeepLink( ),
itemId ?? "", "Поделиться этой сценой",
currentTime > 0 ? ticksToSec(currentTime) : getCurrentTime(), )
), }
"Поделиться этой сценой", aria-label="Поделиться сценой"
) title="Поделиться сценой"
} >
aria-label="Поделиться сценой" <span className="material-symbols-rounded">share</span>
title="Поделиться сценой" </IconButton>
> <IconButton
<span className="material-symbols-rounded">share</span> onClick={openSyncPlayDialog}
</IconButton> aria-label="Смотреть вместе"
<IconButton title="Смотреть вместе"
onClick={openSyncPlayDialog} >
aria-label="Смотреть вместе" <span className="material-symbols-rounded">groups</span>
title="Смотреть вместе" </IconButton>
> <IconButton
<span className="material-symbols-rounded">groups</span> onClick={(e) => setSettingsMenuRef(e.currentTarget)}
</IconButton> aria-label="Настройки плеера"
<IconButton title="Настройки плеера"
onClick={(e) => setSettingsMenuRef(e.currentTarget)} >
aria-label="Настройки плеера" <span className="material-symbols-rounded">settings</span>
title="Настройки плеера" </IconButton>
> <VideoPlayerSettingsMenu
<span className="material-symbols-rounded">settings</span> settingsMenuRef={settingsMenuRef}
</IconButton> handleClose={() => setSettingsMenuRef(null)}
<VideoPlayerSettingsMenu />
settingsMenuRef={settingsMenuRef} </div>
handleClose={() => setSettingsMenuRef(null)} {!isPlayerFullscreen && <WindowControls />}
/> </div>
</div> </div>
<div className="video-player-osd-info"> <div className="video-player-osd-info">
<div> <div>
+11 -1
View File
@@ -132,9 +132,19 @@ const QueueView = ({ variant, onClose }: QueueViewProps) => {
]); ]);
}; };
const tracksLabel = (count: number) => {
const mod10 = count % 10;
const mod100 = count % 100;
if (mod10 === 1 && mod100 !== 11) return `${count} трек`;
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) {
return `${count} трека`;
}
return `${count} треков`;
};
const summary = const summary =
upcoming.length > 0 upcoming.length > 0
? `${upcoming.length} ${upcoming.length === 1 ? "track" : "tracks"} · ${getRuntimeCompact(upcomingTicks)}` ? `${tracksLabel(upcoming.length)} · ${getRuntimeCompact(upcomingTicks)}`
: "Очередь пуста"; : "Очередь пуста";
return ( return (
+24 -20
View File
@@ -1,5 +1,5 @@
import { useLocation } from "@tanstack/react-router"; import { useLocation } from "@tanstack/react-router";
import React, { useEffect } from "react"; import React from "react";
import { shouldShowAppBar } from "@/components/appBar/appBar"; import { shouldShowAppBar } from "@/components/appBar/appBar";
import WindowControls from "."; import WindowControls from ".";
@@ -7,11 +7,29 @@ import "./windowControls.scss";
const isMac = navigator.userAgent.includes("Macintosh"); const isMac = navigator.userAgent.includes("Macintosh");
const WindowChromeContent = () => { /**
useEffect(() => { * Frameless-window fallback for pages that do not draw the app header:
document.body.classList.add("has-window-chrome"); * a small drag strip plus the window buttons in the top-right corner.
return () => document.body.classList.remove("has-window-chrome"); *
}, []); * Pages with a header (home, library, search, player) put the window buttons
* in that header's row instead, so every page has one titlebar plane and the
* buttons never float over the avatar or the page controls.
*/
const WindowChrome = () => {
const { pathname } = useLocation();
if (isMac) return null;
// The global app header owns the window buttons on these routes.
if (shouldShowAppBar(pathname)) return null;
// The home page draws its own header inside the hero frame.
if (pathname === "/home") return null;
// The video/photo players have their own fullscreen UI.
if (pathname.startsWith("/player")) return null;
// Library and search headers draw the window buttons themselves.
if (pathname.startsWith("/library") || pathname.startsWith("/search")) {
return null;
}
// The remote control page has its own titlebar with window buttons.
if (pathname.startsWith("/remote")) return null;
return ( return (
<div className="window-chrome"> <div className="window-chrome">
@@ -23,18 +41,4 @@ const WindowChromeContent = () => {
); );
}; };
/**
* Frameless-window fallback for pages that do not draw the app header:
* a small drag strip plus the window buttons in the top-right corner.
*/
const WindowChrome = () => {
const { pathname } = useLocation();
if (isMac) return null;
if (pathname === "/home" || shouldShowAppBar(pathname)) return null;
// The video player has its own fullscreen UI.
if (pathname.startsWith("/player")) return null;
return <WindowChromeContent />;
};
export default WindowChrome; export default WindowChrome;
@@ -41,18 +41,6 @@ html.is-linux .home-header .window-controls {
margin-left: 0.6rem; margin-left: 0.6rem;
} }
// Reserve a strip for the custom titlebar on routes without the app header.
html.is-windows body.has-window-chrome #root,
html.is-linux body.has-window-chrome #root {
padding-top: 44px;
}
// Search uses a fixed header; move it below the custom titlebar strip.
html.is-windows body.has-window-chrome .search-header,
html.is-linux body.has-window-chrome .search-header {
top: calc(1em + 44px) !important;
}
.window-resize-handles { .window-resize-handles {
position: fixed; position: fixed;
inset: 0; inset: 0;
+17 -2
View File
@@ -98,14 +98,29 @@ function Library() {
} */ } */
return ( return (
<main className="scrollY library padded-top"> <main
className={`scrollY library padded-top${
currentLib.data.CollectionType === "music"
? " music-library music-page"
: ""
}`}
>
<LibraryHeader /> <LibraryHeader />
<Suspense fallback={<LibraryItemsSkeleton />}> <Suspense fallback={<LibraryItemsSkeleton />}>
<div className="library-items"> <div className="library-items">
<LibraryItemsGrid /> <LibraryItemsGrid />
</div> </div>
<div style={{ position: "fixed", right: 14, top: 80 }}> <div
style={{
position: "fixed",
right:
currentLib.data.CollectionType === "music"
? "max(14px, calc((100vw - 1180px) / 2 + 18px))"
: 14,
top: 80,
}}
>
<AlphaSelector /> <AlphaSelector />
</div> </div>
</Suspense> </Suspense>
-1
View File
@@ -768,7 +768,6 @@ export function VideoPlayer() {
onMouseMove={handleMouseMove} onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
> >
<div className="video-player-drag-region" data-tauri-drag-region />
<LoadingIndicator /> <LoadingIndicator />
<ErrorDisplay <ErrorDisplay
error={error} error={error}
+3 -1
View File
@@ -29,6 +29,7 @@ import { useShallow } from "zustand/shallow";
import { NavigationDrawer } from "@/components/appBar/navigationDrawer"; import { NavigationDrawer } from "@/components/appBar/navigationDrawer";
import BackButton from "@/components/buttons/backButton"; import BackButton from "@/components/buttons/backButton";
import { UserAvatarMenu } from "@/components/userAvatarMenu"; import { UserAvatarMenu } from "@/components/userAvatarMenu";
import WindowControls from "@/components/windowControls";
import { useApiInContext } from "@/utils/store/api"; import { useApiInContext } from "@/utils/store/api";
import useDebounce from "@/utils/hooks/useDebounce"; import useDebounce from "@/utils/hooks/useDebounce";
import { useCentralStore } from "@/utils/store/central"; import { useCentralStore } from "@/utils/store/central";
@@ -110,7 +111,7 @@ function SearchPage() {
<div <div
className="search-page-content" className="search-page-content"
style={{ style={{
paddingTop: "2.4em", paddingTop: "4.4em",
}} }}
> >
{debouncedSearchTerm ? ( {debouncedSearchTerm ? (
@@ -361,6 +362,7 @@ function SearchAppBar({
<div className="material-symbols-rounded">favorite</div> <div className="material-symbols-rounded">favorite</div>
</IconButton> </IconButton>
<UserAvatarMenu /> <UserAvatarMenu />
<WindowControls />
</div> </div>
</AppBar> </AppBar>
<NavigationDrawer <NavigationDrawer
+8
View File
@@ -8,6 +8,14 @@
padding: 0; padding: 0;
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
// Frameless window on Windows/Linux: the floating window buttons
// sit in the top 44px, so the settings grid starts below that strip.
html.is-windows &,
html.is-linux & {
padding-top: 44px;
box-sizing: border-box;
}
} }
&-scrollY { &-scrollY {
padding: 2em; padding: 2em;
+15
View File
@@ -59,6 +59,21 @@ export const playAudio = (
playlistItemId?: string | undefined, playlistItemId?: string | undefined,
startTimeTicks = 0, startTimeTicks = 0,
): void => { ): void => {
// Only one medium at a time: starting music stops video playback.
if (typeof document !== "undefined") {
const video = (document
.querySelector("hls-video")
?.shadowRoot?.querySelector("video") ??
document.querySelector("video")) as HTMLVideoElement | null;
if (video && !video.paused) video.pause();
}
void import("./playback").then(({ usePlaybackStore }) => {
const state = usePlaybackStore.getState();
if (state.mediaSource?.id || state.playerState.isPlayerPlaying) {
usePlaybackStore.setState(usePlaybackStore.getInitialState());
}
});
useAudioPlayback.setState({ useAudioPlayback.setState({
display: true, display: true,
url, url,
+4 -1
View File
@@ -29,7 +29,7 @@ import {
} from "../storage/player"; } from "../storage/player";
import type audioPlaybackInfo from "../types/audioPlaybackInfo"; import type audioPlaybackInfo from "../types/audioPlaybackInfo";
import type subtitlePlaybackInfo from "../types/subtitlePlaybackInfo"; import type subtitlePlaybackInfo from "../types/subtitlePlaybackInfo";
import { generateAudioStreamUrl, playAudio } from "./audioPlayback"; import { generateAudioStreamUrl, playAudio, stopPlayback } from "./audioPlayback";
import useQueue, { setQueue } from "./queue"; import useQueue, { setQueue } from "./queue";
type PlaybackStoreState = { type PlaybackStoreState = {
@@ -731,6 +731,9 @@ export const initializePlayback = async (args: {
subtitleStreamIndex, subtitleStreamIndex,
} = args; } = args;
// Only one medium at a time: starting a video stops music playback.
stopPlayback();
if (!mediaSource.MediaSources?.[0]?.Id) { if (!mediaSource.MediaSources?.[0]?.Id) {
throw new Error("Media source is undefined in initializePlayback"); throw new Error("Media source is undefined in initializePlayback");
} }