Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(web): keep the Live call when picture-in-picture returns to the tab

muterC84e58dd400af
diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.test.tsx b/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.test.tsx
index 0cb5219f..257d8e65 100644
--- a/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.test.tsx
+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.test.tsx
@@ -1,5 +1,12 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { act, fireEvent, render, screen, within } from "@testing-library/react";
+import {
+ act,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+ within,
+} from "@testing-library/react";
import { MemoryRouter, useLocation } from "react-router";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -290,8 +297,10 @@ describe("Voice Mode mini window", () => {
// The desktop's close button ends Voice Mode instead of leaving a
// second window behind in the page.
+ const focused = vi.spyOn(document, "hasFocus").mockReturnValue(false);
act(() => fake.pipWindow.close());
- expect(voice.exit).toHaveBeenCalledOnce();
+ await waitFor(() => expect(voice.exit).toHaveBeenCalledOnce());
+ focused.mockRestore();
} finally {
fake.frame.remove();
Reflect.deleteProperty(window, "documentPictureInPicture");
@@ -299,6 +308,31 @@ describe("Voice Mode mini window", () => {
}
});
+ it("keeps the call when the desktop's back to tab button returns to the page", async () => {
+ const fake = installFakeVoicePip();
+ const focused = vi.spyOn(document, "hasFocus").mockReturnValue(true);
+ try {
+ renderWindow();
+ await act(() => openVoicePip("voice-mode"));
+ act(() => fake.pipWindow.close());
+ // The call goes on in the window inside the page, on its conversation.
+ await waitFor(() =>
+ expect(screen.getByTestId("location")).toHaveTextContent(
+ "/t/tenant-northstar/rooms/room-voice/chat",
+ ),
+ );
+ expect(voice.exit).not.toHaveBeenCalled();
+ expect(
+ screen.getByRole("region", { name: "Voice Mode window" }),
+ ).toBeInTheDocument();
+ } finally {
+ focused.mockRestore();
+ fake.frame.remove();
+ Reflect.deleteProperty(window, "documentPictureInPicture");
+ resetVoicePipForTest();
+ }
+ });
+
it("drags from anywhere on the header, including the title", () => {
renderWindow();
const panel = screen.getByRole("region", { name: "Voice Mode window" });
diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.tsx b/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.tsx
index 217c8d44..40f75fdc 100644
--- a/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.tsx
+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-mode-mini-window.tsx
@@ -37,7 +37,11 @@ import { ActorAvatar } from "../../members/actor-avatar";
import { voiceModeStatusLabel } from "./voice-mode-presentation";
import styles from "./voice-mode.module.css";
import { registerVoiceWindow, type VoiceWindowAction } from "./voice-ui-bridge";
-import { onVoicePipClosedByHuman, useVoicePip } from "./voice-pip";
+import {
+ onVoicePipClosedByHuman,
+ returnedToOpener,
+ useVoicePip,
+} from "./voice-pip";
import { showVoiceNotice, useVoiceNotice } from "./voice-notice";
import {
useOptionalVoiceModeSession,
@@ -68,6 +72,7 @@ type WindowSize = keyof typeof windowSizes;
* tabs and apps. Closing it, from its own button or the desktop's, ends Voice
* Mode: the window leaves at once while the session drains its last
* words in the background, and the Room composer shows that finishing state.
+ * The desktop's back to tab button only returns to the conversation.
*/
export default function VoiceModeMiniWindow({
anotherMeActorId,
@@ -157,13 +162,23 @@ function MiniWindow({
);
const notice = useVoiceNotice();
const pip = useVoicePip("voice-mode");
- // One window: the desktop's close button on the floating one ends Voice Mode too.
+ // One window: the desktop's close button on the floating one ends Voice Mode
+ // too. Its back to tab button instead returns to this conversation and keeps
+ // the call, which goes on in the window inside the page.
const exitRef = useRef(onExit);
+ const openRoomRef = useRef(() => {});
useLayoutEffect(() => {
exitRef.current = onExit;
+ openRoomRef.current = () =>
+ void navigate(`/t/${tenantId}/rooms/${roomId}/chat`);
});
useEffect(
- () => onVoicePipClosedByHuman("voice-mode", () => exitRef.current()),
+ () =>
+ onVoicePipClosedByHuman("voice-mode", () => {
+ void returnedToOpener().then((returned) =>
+ returned ? openRoomRef.current() : exitRef.current(),
+ );
+ }),
[],
);
diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts
index 4704c798..cfcf686c 100644
--- a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts
+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts
@@ -68,6 +68,23 @@ export function closeVoicePip(owner: VoicePipOwner) {
current.close();
}
+/**
+ * Whether closing the window brought the Human back to this page. The
+ * window's "back to tab" button closes it and puts its tab in front, while its
+ * close button does not; the browser reports neither, so this looks at the
+ * page a moment later. A close while this page is already in front reads the
+ * same as back to tab.
+ */
+export function returnedToOpener(waitMs = 300): Promise<boolean> {
+ return new Promise((resolve) =>
+ setTimeout(
+ () =>
+ resolve(document.visibilityState === "visible" && document.hasFocus()),
+ waitMs,
+ ),
+ );
+}
+
/** Runs when the Human closes this owner's window with the desktop's button. */
export function onVoicePipClosedByHuman(
owner: VoicePipOwner,