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 {
type BaseItemDto,
BaseItemKind,
ItemFields,
SortOrder,
} 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 type { SxProps } from "@mui/material";
import Button, { type ButtonProps } from "@mui/material/Button";
@@ -131,6 +134,7 @@ const PlayButton = ({
if (audio) {
// Album/Individual audio track playback
const playedItem = result?.item?.Items?.[0];
const playbackUrl = generateAudioStreamUrl(
result?.item?.Items?.[0].Id,
userId,
@@ -139,7 +143,68 @@ const PlayButton = ({
api.accessToken,
);
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") {
const index = result?.item?.Items?.map((i) => i.Id).indexOf(item.Id);
if (result?.item?.Items && index) {
+2
View File
@@ -25,6 +25,7 @@ import BackButton from "../buttons/backButton";
import CastButton from "../buttons/castButton";
import { FiltersDialogTrigger } from "../filtersDialog";
import { UserAvatarMenu } from "../userAvatarMenu";
import WindowControls from "../windowControls";
import "./libraryHeader.scss";
const route = getRouteApi("/_api/library/$id");
@@ -417,6 +418,7 @@ export const LibraryHeader = () => {
<div className="material-symbols-rounded">favorite</div>
</IconButton>
<UserAvatarMenu />
<WindowControls />
</div>
</AppBar>
<NavigationDrawer open={showDrawer} onClose={handleDrawerClose} />
@@ -20,13 +20,24 @@
--media-object-fit: fill;
}
&-drag-region {
&-titlebar {
position: absolute;
inset: 0 0 auto;
height: 38px;
z-index: 4;
cursor: default;
z-index: 3;
display: flex;
align-items: center;
gap: 0.75em;
padding: 4px 8px;
min-height: 46px;
user-select: none;
&-end {
display: flex;
align-items: center;
gap: 0.5em;
margin-left: auto;
min-width: 0;
}
}
&-osd {
@@ -53,22 +64,16 @@
}
&-back,
&-actions {
position: absolute;
top: 2em;
z-index: 3;
display: flex;
align-items: center;
flex: 0 0 auto;
padding: 0.3em;
border-radius: 999px;
border: 1px solid rgb(255 255 255 / 0.08);
background: rgb(0 0 0 / 0.28);
backdrop-filter: blur(12px);
}
&-back {
left: 3em;
}
&-actions {
right: 3em;
gap: 0.35em;
}
&-info {
@@ -117,4 +122,27 @@
border: 1.2px solid rgb(255 255 255 / 0.1);
}
}
}
// 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 QueueButton from "@/components/buttons/queueButton";
import BubbleSlider from "@/components/playback/videoPlayer/bubbleSlider";
import WindowControls from "@/components/windowControls";
import { secToTicks, ticksToSec } from "@/utils/date/time";
import { buildPlayDeepLink } from "@/utils/deepLinks";
import { getPlayerVideoElement } from "@/utils/methods/pictureInPicture";
import { openSyncPlayDialog } from "@/utils/methods/syncPlay";
import { useApiInContext } from "@/utils/store/api";
import { useShareStore } from "@/utils/store/share";
@@ -88,6 +88,7 @@ const VideoPlayerControls = ({
isPlayerPlaying,
toggleIsPlaying,
toggleIsPlayerFullscreen,
isPlayerFullscreen,
isUserSeeking,
// seekValue,
isPlayerMuted,
@@ -112,6 +113,7 @@ const VideoPlayerControls = ({
playsessionId: state.playsessionId,
toggleIsPlaying: state.toggleIsPlaying,
toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen,
isPlayerFullscreen: state.playerState.isPlayerFullscreen,
isUserSeeking: state.playerState.isUserSeeking,
seekValue: state.playerState.seekValue,
isPlayerMuted: state.playerState.isPlayerMuted,
@@ -153,69 +155,6 @@ const VideoPlayerControls = ({
const [settingsMenuRef, setSettingsMenuRef] =
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(
// (segment) => segment.Type === "Outro",
@@ -301,64 +240,60 @@ const VideoPlayerControls = ({
}}
>
<div
className="video-player-osd-back"
style={
videoFrame
? { top: videoFrame.top, left: videoFrame.left }
: undefined
}
className={`video-player-titlebar${isPlayerFullscreen ? " is-fullscreen" : ""}`}
data-tauri-drag-region
>
<IconButton
onClick={handleExitPlayer}
aria-label="Выйти из плеера"
title="Выйти из плеера"
>
<span className="material-symbols-rounded">arrow_back</span>
</IconButton>
</div>
<div
className="video-player-osd-actions"
style={
videoFrame
? { top: videoFrame.top, right: videoFrame.right }
: undefined
}
>
<IconButton
onClick={() =>
useShareStore
.getState()
.openShareDialog(
buildPlayDeepLink(
itemId ?? "",
currentTime > 0 ? ticksToSec(currentTime) : getCurrentTime(),
),
"Поделиться этой сценой",
)
}
aria-label="Поделиться сценой"
title="Поделиться сценой"
>
<span className="material-symbols-rounded">share</span>
</IconButton>
<IconButton
onClick={openSyncPlayDialog}
aria-label="Смотреть вместе"
title="Смотреть вместе"
>
<span className="material-symbols-rounded">groups</span>
</IconButton>
<IconButton
onClick={(e) => setSettingsMenuRef(e.currentTarget)}
aria-label="Настройки плеера"
title="Настройки плеера"
>
<span className="material-symbols-rounded">settings</span>
</IconButton>
<VideoPlayerSettingsMenu
settingsMenuRef={settingsMenuRef}
handleClose={() => setSettingsMenuRef(null)}
/>
<div className="video-player-osd-back">
<IconButton
onClick={handleExitPlayer}
aria-label="Выйти из плеера"
title="Выйти из плеера"
>
<span className="material-symbols-rounded">arrow_back</span>
</IconButton>
</div>
<div className="video-player-titlebar-end">
<div className="video-player-osd-actions">
<IconButton
onClick={() =>
useShareStore
.getState()
.openShareDialog(
buildPlayDeepLink(
itemId ?? "",
currentTime > 0
? ticksToSec(currentTime)
: getCurrentTime(),
),
"Поделиться этой сценой",
)
}
aria-label="Поделиться сценой"
title="Поделиться сценой"
>
<span className="material-symbols-rounded">share</span>
</IconButton>
<IconButton
onClick={openSyncPlayDialog}
aria-label="Смотреть вместе"
title="Смотреть вместе"
>
<span className="material-symbols-rounded">groups</span>
</IconButton>
<IconButton
onClick={(e) => setSettingsMenuRef(e.currentTarget)}
aria-label="Настройки плеера"
title="Настройки плеера"
>
<span className="material-symbols-rounded">settings</span>
</IconButton>
<VideoPlayerSettingsMenu
settingsMenuRef={settingsMenuRef}
handleClose={() => setSettingsMenuRef(null)}
/>
</div>
{!isPlayerFullscreen && <WindowControls />}
</div>
</div>
<div className="video-player-osd-info">
<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 =
upcoming.length > 0
? `${upcoming.length} ${upcoming.length === 1 ? "track" : "tracks"} · ${getRuntimeCompact(upcomingTicks)}`
? `${tracksLabel(upcoming.length)} · ${getRuntimeCompact(upcomingTicks)}`
: "Очередь пуста";
return (
+24 -20
View File
@@ -1,5 +1,5 @@
import { useLocation } from "@tanstack/react-router";
import React, { useEffect } from "react";
import React from "react";
import { shouldShowAppBar } from "@/components/appBar/appBar";
import WindowControls from ".";
@@ -7,11 +7,29 @@ import "./windowControls.scss";
const isMac = navigator.userAgent.includes("Macintosh");
const WindowChromeContent = () => {
useEffect(() => {
document.body.classList.add("has-window-chrome");
return () => document.body.classList.remove("has-window-chrome");
}, []);
/**
* 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.
*
* 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 (
<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;
@@ -41,18 +41,6 @@ html.is-linux .home-header .window-controls {
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 {
position: fixed;
inset: 0;