Skip to content

Commit cda8ea4

Browse files
committed
hide dashboard in fullscreen
1 parent 72ded6d commit cda8ea4

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

.cursor/rules/agent.mdc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ alwaysApply: true
44

55
- 不要自动跑任何 pnpm 命令
66
- 不要自动书写 README.md 文件
7+
- 尽量使用 for 循环, 尽量不实用 forEach
8+
- 在 Typescript 中, 不要使用 any, 尽量推导出来类型

pages/content-ui/src/Dashboard.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BBox, DemoMode, DiagnoseMode, IgnoredStatus, InteractionMode, RunningStatus } from './components';
22
import { DashboardEntry } from './DashboardEntry';
33
import { useContentUIState } from './hooks/useContentUIState';
4+
import { useFullscreenDetection } from './hooks/useFullscreenDetection';
45
import { useCallback } from 'react';
56
import type { FC } from 'react';
67

@@ -16,6 +17,9 @@ export const Dashboard: FC = () => {
1617
setHoveringOthers,
1718
} = useContentUIState();
1819

20+
// 全屏检测
21+
const isFullscreen = useFullscreenDetection();
22+
1923
// 简化的事件处理 - 确保状态互斥
2024
const handleEntryMouseEnter = useCallback(() => {
2125
setHovered(true);
@@ -52,6 +56,10 @@ export const Dashboard: FC = () => {
5256
paddingRight: 0,
5357
userSelect: 'none',
5458
// backgroundColor: 'rgba(0, 0, 0, 0.1)',
59+
// 全屏时隐藏 Dashboard
60+
opacity: isFullscreen ? 0 : 1,
61+
visibility: isFullscreen ? 'hidden' : 'visible',
62+
transition: 'opacity 0.2s ease-out, visibility 0.2s ease-out',
5563
};
5664

5765
const widgetAnimationStyle = {
@@ -60,6 +68,11 @@ export const Dashboard: FC = () => {
6068
transition: 'transform 0.1s ease-out, opacity 0.1s ease-out',
6169
};
6270

71+
// 如果处于全屏模式,不渲染 Dashboard
72+
if (isFullscreen) {
73+
return null;
74+
}
75+
6376
return (
6477
<div style={dashboardStyle}>
6578
<div onMouseEnter={handleEntryMouseEnter} onMouseLeave={handleEntryMouseLeave}>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { useEffect, useState } from 'react';
2+
3+
export const useFullscreenDetection = () => {
4+
const [isFullscreen, setIsFullscreen] = useState(false);
5+
6+
useEffect(() => {
7+
const checkFullscreen = () => {
8+
// 检查多种全屏状态
9+
const isFullscreenElement = !!(
10+
document.fullscreenElement ||
11+
(document as any).webkitFullscreenElement ||
12+
(document as any).mozFullScreenElement ||
13+
(document as any).msFullscreenElement
14+
);
15+
16+
// 检查是否处于全屏模式
17+
const isFullscreenMode = !!(
18+
(document as any).webkitIsFullScreen ||
19+
(document as any).mozFullScreen ||
20+
(document as any).msFullscreenElement
21+
);
22+
23+
// 检查视频元素是否全屏(YouTube 等视频网站常用)
24+
// 使用更安全的方法检查视频全屏状态
25+
const videos = document.querySelectorAll('video');
26+
let hasFullscreenVideo = false;
27+
28+
for (let i = 0; i < videos.length; i++) {
29+
const video = videos[i];
30+
if (
31+
video === document.fullscreenElement ||
32+
video === (document as any).webkitFullscreenElement ||
33+
video === (document as any).mozFullScreenElement ||
34+
video === (document as any).msFullscreenElement
35+
) {
36+
hasFullscreenVideo = true;
37+
break;
38+
}
39+
}
40+
41+
// 检查页面是否处于全屏状态
42+
const isPageFullscreen = window.innerHeight === window.screen.height && window.innerWidth === window.screen.width;
43+
44+
setIsFullscreen(isFullscreenElement || isFullscreenMode || hasFullscreenVideo || isPageFullscreen);
45+
};
46+
47+
// 初始检查
48+
checkFullscreen();
49+
50+
// 监听全屏变化事件
51+
const events = ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange'];
52+
53+
events.forEach(event => {
54+
document.addEventListener(event, checkFullscreen);
55+
});
56+
57+
// 监听窗口大小变化(用于检测页面全屏)
58+
window.addEventListener('resize', checkFullscreen);
59+
60+
return () => {
61+
events.forEach(event => {
62+
document.removeEventListener(event, checkFullscreen);
63+
});
64+
window.removeEventListener('resize', checkFullscreen);
65+
};
66+
}, []);
67+
68+
return isFullscreen;
69+
};

0 commit comments

Comments
 (0)