Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): refresh video visibility after fullscreen exit

DavidShen264eb5c4222f
diff --git a/apps/desktop/src/renderer/components/chat/ChatVideoView.tsx b/apps/desktop/src/renderer/components/chat/ChatVideoView.tsx
index 0e85ce885f..9d436e6431 100644
--- a/apps/desktop/src/renderer/components/chat/ChatVideoView.tsx
+++ b/apps/desktop/src/renderer/components/chat/ChatVideoView.tsx
@@ -69,14 +69,27 @@ export function ChatVideoView({ src, filename, variant, sessionId }: ChatVideoVi
const observer = new IntersectionObserver(([entry]) => {
if (!entry.isIntersecting && document.fullscreenElement !== video) video.pause();
});
+ let wasFullscreen = document.fullscreenElement === video;
+ const onFullscreenChange = () => {
+ const isFullscreen = document.fullscreenElement === video;
+ if (wasFullscreen && !isFullscreen) {
+ // A hidden notification ignored during fullscreen may not repeat on
+ // exit. Resubscribe for a fresh sample of the restored inline bounds.
+ observer.unobserve(video);
+ observer.observe(video);
+ }
+ wasFullscreen = isFullscreen;
+ };
const onVisibility = () => {
if (document.hidden) video.pause();
};
observer.observe(video);
+ document.addEventListener('fullscreenchange', onFullscreenChange);
document.addEventListener('visibilitychange', onVisibility);
return () => {
unregister();
observer.disconnect();
+ document.removeEventListener('fullscreenchange', onFullscreenChange);
document.removeEventListener('visibilitychange', onVisibility);
video.pause();
};
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/ChatVideoView.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/ChatVideoView.test.tsx
index 3a5d5c1f47..6d28400c58 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/ChatVideoView.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/ChatVideoView.test.tsx
@@ -12,19 +12,22 @@ vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => k
vi.mock('@/hooks/useRemoteMediaUrl', () => ({ useRemoteMediaUrl: (url: string) => url }));
vi.mock('@/lib/toast', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
let visibility: IntersectionObserverCallback;
+let observe: ReturnType<typeof vi.fn>;
let pause: ReturnType<typeof vi.spyOn>;
const showModalDescriptor = Object.getOwnPropertyDescriptor(
HTMLDialogElement.prototype,
'showModal',
);
beforeEach(() => {
+ observe = vi.fn();
vi.stubGlobal(
'IntersectionObserver',
class {
constructor(callback: IntersectionObserverCallback) {
visibility = callback;
}
- observe() {}
+ observe = observe;
+ unobserve() {}
disconnect() {}
},
);
@@ -172,6 +175,36 @@ it('pauses video when its message leaves view', () => {
);
expect(pause).toHaveBeenCalledOnce();
});
+// Tier 1 regression (PR #7264): exiting fullscreen must pause an offscreen
+// message even if its only hidden notification arrived during fullscreen.
+// The previous test sent a second transition manually, hiding this gap. Model
+// observe's fresh initial notification, including a now-visible inline player
+// so stale fullscreen bounds cannot spuriously pause playback.
+it.each([false, true])('rechecks visibility after fullscreen exits (visible: %s)', (visible) => {
+ const view = render(<ChatVideoView {...props} />, { wrapper: Tooltip.Provider });
+ const video = view.container.querySelector('video')!;
+ Object.defineProperty(document, 'fullscreenElement', {
+ configurable: true,
+ get: () => video,
+ });
+ fireEvent(document, new Event('fullscreenchange'));
+ visibility(
+ [{ isIntersecting: false }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ expect(pause).not.toHaveBeenCalled();
+ // No new intersection transition occurs on exit. Only a fresh subscription
+ // delivers the browser's initial visibility sample again.
+ observe.mockImplementation(() => {
+ visibility(
+ [{ isIntersecting: visible }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ });
+ vi.spyOn(document, 'fullscreenElement', 'get').mockReturnValue(null);
+ fireEvent(document, new Event('fullscreenchange'));
+ expect(pause).toHaveBeenCalledTimes(visible ? 0 : 1);
+});
// Tier 1: the old lightbox joined the real audio/video bus; inline playback must
// preserve that behavior, including the fresh element mounted after retry.
it('coordinates inline videos and audio through playback and retry', () => {