Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix video osd not hiding in experimental layout #5517

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/apps/experimental/components/AppToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ const ExperimentalAppToolbar: FC<AppToolbarProps> = ({
onDrawerButtonClick
}) => {
const location = useLocation();

// The video osd does not show the standard toolbar
if (location.pathname === '/video') return null;

const isTabsAvailable = isTabPath(location.pathname);
const isPublicPath = location.pathname === '/selectserver.html';
thornbill marked this conversation as resolved.
Show resolved Hide resolved

return (
<AppToolbar
buttons={
buttons={!isPublicPath && (
<>
<SyncPlayButton />
<RemotePlayButton />
Expand All @@ -45,10 +50,11 @@ const ExperimentalAppToolbar: FC<AppToolbarProps> = ({
</IconButton>
</Tooltip>
</>
}
)}
isDrawerAvailable={isDrawerAvailable}
isDrawerOpen={isDrawerOpen}
onDrawerButtonClick={onDrawerButtonClick}
isUserMenuAvailable={!isPublicPath}
>
{isTabsAvailable && (<AppTabs isDrawerOpen={isDrawerOpen} />)}
</AppToolbar>
Expand Down
10 changes: 0 additions & 10 deletions src/apps/experimental/routes/legacyRoutes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ export const LEGACY_USER_ROUTES: LegacyRoute[] = [
controller: 'user/subtitles/index',
view: 'user/subtitles/index.html'
}
}, {
path: 'video',
pageProps: {
controller: 'playback/video/index',
view: 'playback/video/index.html',
type: 'video-osd',
isFullscreen: true,
isNowPlayingBarEnabled: false,
isThemeMediaSupported: true
}
}, {
path: 'queue',
pageProps: {
Expand Down
10 changes: 9 additions & 1 deletion src/apps/experimental/routes/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { toAsyncPageRoute } from 'components/router/AsyncRoute';
import { toViewManagerPageRoute } from 'components/router/LegacyRoute';
import { toRedirectRoute } from 'components/router/Redirect';
import AppLayout from '../AppLayout';

import { ASYNC_USER_ROUTES } from './asyncRoutes';
import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes';
import VideoPage from './video';

export const EXPERIMENTAL_APP_ROUTES: RouteObject[] = [
{
Expand All @@ -20,7 +22,13 @@ export const EXPERIMENTAL_APP_ROUTES: RouteObject[] = [
element: <ConnectionRequired isUserRequired />,
children: [
...ASYNC_USER_ROUTES.map(toAsyncPageRoute),
...LEGACY_USER_ROUTES.map(toViewManagerPageRoute)
...LEGACY_USER_ROUTES.map(toViewManagerPageRoute),

// The video page is special since it combines new controls with the legacy view
{
path: 'video',
element: <VideoPage />
}
]
},

Expand Down
71 changes: 71 additions & 0 deletions src/apps/experimental/routes/video/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Box from '@mui/material/Box/Box';
import Fade from '@mui/material/Fade/Fade';
import React, { useRef, type FC, useEffect, useState } from 'react';

import RemotePlayButton from 'apps/experimental/components/AppToolbar/RemotePlayButton';
import SyncPlayButton from 'apps/experimental/components/AppToolbar/SyncPlayButton';
import AppToolbar from 'components/toolbar/AppToolbar';
import ViewManagerPage from 'components/viewManager/ViewManagerPage';
import Events, { type Event } from 'utils/events';

/**
* Video player page component that renders mui controls for the top controls and the legacy view for everything else.
*/
const VideoPage: FC = () => {
const documentRef = useRef<Document>(document);
const [ isVisible, setIsVisible ] = useState(true);

const onShowVideoOsd = (_e: Event, isShowing: boolean) => {
setIsVisible(isShowing);
};

useEffect(() => {
const doc = documentRef.current;

if (doc) Events.on(doc, 'showVideoOsd', onShowVideoOsd);

return () => {
if (doc) Events.off(doc, 'showVideoOsd', onShowVideoOsd);
};
}, []);

return (
<>
<Fade
in={isVisible}
easing='fade-out'
>
<Box sx={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
color: 'white'
}}>
<AppToolbar
isDrawerAvailable={false}
isDrawerOpen={false}
isUserMenuAvailable={false}
buttons={
<>
<SyncPlayButton />
<RemotePlayButton />
</>
}
/>
</Box>
</Fade>

<ViewManagerPage
controller='playback/video/index'
view='playback/video/index.html'
type='video-osd'
isFullscreen
isNowPlayingBarEnabled={false}
isThemeMediaSupported
/>
</>
);
};

export default VideoPage;
27 changes: 11 additions & 16 deletions src/components/toolbar/AppToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import IconButton from '@mui/material/IconButton';
import Toolbar from '@mui/material/Toolbar';
import Tooltip from '@mui/material/Tooltip';
import React, { FC, ReactNode } from 'react';
import { useLocation } from 'react-router-dom';

import { appRouter } from 'components/router/appRouter';
import { useApi } from 'hooks/useApi';
Expand All @@ -17,7 +16,8 @@ interface AppToolbarProps {
buttons?: ReactNode
isDrawerAvailable: boolean
isDrawerOpen: boolean
onDrawerButtonClick: (event: React.MouseEvent<HTMLElement>) => void
onDrawerButtonClick?: (event: React.MouseEvent<HTMLElement>) => void,
isUserMenuAvailable?: boolean
}

const onBackButtonClick = () => {
Expand All @@ -32,17 +32,14 @@ const AppToolbar: FC<AppToolbarProps> = ({
children,
isDrawerAvailable,
isDrawerOpen,
onDrawerButtonClick
onDrawerButtonClick = () => { /* no-op */ },
isUserMenuAvailable = true
}) => {
const { user } = useApi();
const isUserLoggedIn = Boolean(user);
const currentLocation = useLocation();

const isBackButtonAvailable = appRouter.canGoBack();

// Handles a specific case to hide the user menu on the select server page while authenticated
const isUserMenuAvailable = currentLocation.pathname !== '/selectserver.html';

return (
<Toolbar
variant='dense'
Expand Down Expand Up @@ -84,16 +81,14 @@ const AppToolbar: FC<AppToolbarProps> = ({

{children}

{isUserLoggedIn && isUserMenuAvailable && (
<>
<Box sx={{ display: 'flex', flexGrow: 1, justifyContent: 'flex-end' }}>
{buttons}
</Box>
<Box sx={{ display: 'flex', flexGrow: 1, justifyContent: 'flex-end' }}>
{buttons}
</Box>

<Box sx={{ flexGrow: 0 }}>
<UserMenuButton />
</Box>
</>
{isUserLoggedIn && isUserMenuAvailable && (
<Box sx={{ flexGrow: 0 }}>
<UserMenuButton />
</Box>
)}
</Toolbar>
);
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/playback/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,14 @@ export default function (view) {
let mouseIsDown = false;

function showOsd(focusElement) {
Events.trigger(document, 'showVideoOsd', [ true ]);
slideDownToShow(headerElement);
showMainOsdControls(focusElement);
resetIdle();
}

function hideOsd() {
Events.trigger(document, 'showVideoOsd', [ false ]);
slideUpToHide(headerElement);
hideMainOsdControls();
mouseManager.hideCursor();
Expand Down
Loading