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.

feat(desktop): float Voice Mode and Recording windows in their own window

xiaoke1234567837d56e58ce0e
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index c44add0a..fdd14e25 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -312,6 +312,20 @@ Gateway and runs Agents. The daemon exits with the app.
redacted `error` bounded to 500 chars with query/hash stripped). A resume
whose saved BYOK gateway did not come back still succeeds and logs
`local_server.byok_gateway_unavailable` (`code`, `message`).
+- `src/main/voice-window.ts`: the floating voice window. Electron cannot open
+ Document Picture-in-Picture windows, so the SPA opens a small native window
+ with `window.open("")` under the target `linger-voice-window-<n>`
+ (`voiceWindowRequest` in `navigation.ts` allows only that, from the server's
+ page; every other `window.open` is still denied) and renders its Voice Mode
+ or Recording window into it, so the call and its state stay in the main
+ page. The window is always on top (on every macOS Space), has no
+ parent so it stays up when the main window is minimized or closed to the
+ tray, and closes with the page (reload, crash, main window closed). While it
+ is open the page is not background-throttled. Only a window the main page
+ itself opened is kept; one from a frame in it is destroyed. Its native close button ends
+ Voice Mode; `lingerDesktop.voiceWindow.showMainWindow()` (its presence is
+ how the SPA knows the app supports this) brings the main window forward and
+ keeps the call. An app without `voiceWindow` keeps the in-page windows.
- `src/shell/*.html`: app-owned pages (title bar, offline/setup page). They
have no network access and talk to the main process via `src/preload/shell.ts`.
- `src/preload/index.ts`: the only SPA API, `window.lingerDesktop`. Its
diff --git a/apps/desktop/src/main/desktop-ipc.ts b/apps/desktop/src/main/desktop-ipc.ts
index c7b8d917..d01440e0 100644
--- a/apps/desktop/src/main/desktop-ipc.ts
+++ b/apps/desktop/src/main/desktop-ipc.ts
@@ -195,6 +195,7 @@ export class DesktopIpcModule implements Module {
}
});
+ handle(IPC.voiceWindowShowMain, () => windows.show());
handle(IPC.updateState, () => updateView(updater.state()));
handle(IPC.updateInstall, () => updater.install());
handle(IPC.updateCheck, () => updater.check());
diff --git a/apps/desktop/src/main/navigation.test.ts b/apps/desktop/src/main/navigation.test.ts
index 588483f9..4d5fe576 100644
--- a/apps/desktop/src/main/navigation.test.ts
+++ b/apps/desktop/src/main/navigation.test.ts
@@ -8,6 +8,7 @@ import {
permissionAllowed,
serverSwitch,
windowLoadDecision,
+ voiceWindowRequest,
} from "./navigation.js";
const server = "https://linger.example.com";
@@ -319,3 +320,33 @@ describe("windowLoadDecision", () => {
).toEqual({ action: "noop", reason: "server_changed" });
});
});
+
+describe("voiceWindowRequest", () => {
+ const page = `${server}/t/1/rooms/2/chat`;
+ const open = { url: "about:blank", frameName: "linger-voice-window-3" };
+
+ it("allows the server's page to open its empty voice window", () => {
+ expect(voiceWindowRequest(open, server, page)).toBe(true);
+ });
+
+ it("denies any other window the page opens", () => {
+ expect(
+ voiceWindowRequest({ ...open, frameName: "popup" }, server, page),
+ ).toBe(false);
+ expect(
+ voiceWindowRequest(
+ { url: "https://evil.example.com/", frameName: open.frameName },
+ server,
+ page,
+ ),
+ ).toBe(false);
+ });
+
+ it("denies a page that is not the server's", () => {
+ expect(voiceWindowRequest(open, server, "app://offline/")).toBe(false);
+ expect(voiceWindowRequest(open, server, "https://evil.example.com/")).toBe(
+ false,
+ );
+ expect(voiceWindowRequest(open, undefined, page)).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/main/navigation.ts b/apps/desktop/src/main/navigation.ts
index 191e321b..91b36de5 100644
--- a/apps/desktop/src/main/navigation.ts
+++ b/apps/desktop/src/main/navigation.ts
@@ -105,6 +105,21 @@ export function windowLoadDecision(
return { action: "load", targetUrl: targetOrigin, reason };
}
+// The page names the floating voice window it opens with this `window.open`
+// target prefix (a suffix keeps a closing window from being reused).
+export const VOICE_WINDOW_TARGET = "linger-voice-window";
+
+// Whether a `window.open` is the voice window: an empty page the server's own
+// page fills in itself. Anything else the page opens is denied.
+export const voiceWindowRequest = (
+ details: { url: string; frameName: string },
+ serverUrl: string | undefined,
+ fromUrl: string,
+): boolean =>
+ details.url === "about:blank" &&
+ details.frameName.startsWith(VOICE_WINDOW_TARGET) &&
+ serverUrl !== undefined &&
+ sameOrigin(fromUrl, serverUrl);
export type NavigationDecision = "allow" | "external" | "deny";
diff --git a/apps/desktop/src/main/voice-window.test.ts b/apps/desktop/src/main/voice-window.test.ts
new file mode 100644
index 00000000..fa7de6c9
--- /dev/null
+++ b/apps/desktop/src/main/voice-window.test.ts
@@ -0,0 +1,158 @@
+import { EventEmitter } from "node:events";
+import { describe, expect, it, vi } from "vitest";
+
+import { acceptVoiceWindow, adoptVoiceWindow } from "./voice-window.js";
+
+// Electron stand-ins: only what the module touches.
+function fakes() {
+ const childContents = Object.assign(new EventEmitter(), {
+ setWindowOpenHandler: vi.fn(),
+ opener: undefined as unknown,
+ });
+ const child = Object.assign(new EventEmitter(), {
+ webContents: childContents,
+ setAlwaysOnTop: vi.fn(),
+ setVisibleOnAllWorkspaces: vi.fn(),
+ setMenuBarVisibility: vi.fn(),
+ isDestroyed: vi.fn(() => false),
+ close: vi.fn(() => child.emit("closed")),
+ destroy: vi.fn(),
+ });
+ const mainFrame = {};
+ const opener = Object.assign(new EventEmitter(), {
+ mainFrame,
+ isDestroyed: vi.fn(() => false),
+ setBackgroundThrottling: vi.fn(),
+ });
+ return { child, childContents, opener };
+}
+
+const adopt = (
+ { child, opener }: ReturnType<typeof fakes>,
+ platform: NodeJS.Platform = "linux",
+) => adoptVoiceWindow(child as never, opener as never, platform);
+
+describe("adoptVoiceWindow", () => {
+ it("floats the window over other apps and keeps the page running", () => {
+ const f = fakes();
+ adopt(f);
+ expect(f.child.setAlwaysOnTop).toHaveBeenCalledWith(true, "floating");
+ expect(f.opener.setBackgroundThrottling).toHaveBeenLastCalledWith(false);
+ expect(f.child.setVisibleOnAllWorkspaces).not.toHaveBeenCalled();
+ });
+
+ it("follows the person across Spaces on macOS", () => {
+ const f = fakes();
+ adopt(f, "darwin");
+ expect(f.child.setVisibleOnAllWorkspaces).toHaveBeenCalledWith(true, {
+ visibleOnFullScreen: true,
+ skipTransformProcessType: true,
+ });
+ });
+
+ it("lets the page throttle again once the window closes", () => {
+ const f = fakes();
+ adopt(f);
+ f.child.emit("closed");
+ expect(f.opener.setBackgroundThrottling).toHaveBeenLastCalledWith(true);
+ expect(f.opener.listenerCount("did-start-navigation")).toBe(0);
+ });
+
+ it("keeps the page running when one window replaces another", () => {
+ const first = fakes();
+ adopt(first);
+ const second = fakes();
+ adoptVoiceWindow(second.child as never, first.opener as never, "linux");
+ // The old window's close can land after the new one was adopted.
+ first.child.emit("closed");
+ expect(first.opener.setBackgroundThrottling).toHaveBeenLastCalledWith(
+ false,
+ );
+ second.child.emit("closed");
+ expect(first.opener.setBackgroundThrottling).toHaveBeenLastCalledWith(true);
+ });
+
+ it("closes when the page navigates to another document or crashes", () => {
+ const sameDocument = fakes();
+ adopt(sameDocument);
+ sameDocument.opener.emit("did-start-navigation", {
+ isMainFrame: true,
+ isSameDocument: true,
+ });
+ sameDocument.opener.emit("did-start-navigation", {
+ isMainFrame: false,
+ isSameDocument: false,
+ });
+ expect(sameDocument.child.close).not.toHaveBeenCalled();
+ sameDocument.opener.emit("did-start-navigation", {
+ isMainFrame: true,
+ isSameDocument: false,
+ });
+ expect(sameDocument.child.close).toHaveBeenCalledOnce();
+
+ const crashed = fakes();
+ adopt(crashed);
+ crashed.opener.emit("render-process-gone");
+ expect(crashed.child.close).toHaveBeenCalledOnce();
+ });
+
+ it("returns a close function that is safe after the window is gone", () => {
+ const f = fakes();
+ const close = adopt(f);
+ f.child.isDestroyed.mockReturnValue(true);
+ close();
+ expect(f.child.close).not.toHaveBeenCalled();
+ });
+
+ it("keeps the window on its empty page", () => {
+ const f = fakes();
+ adopt(f);
+ const handler = f.childContents.setWindowOpenHandler.mock.calls[0]![0] as (
+ details: unknown,
+ ) => unknown;
+ expect(handler({})).toEqual({ action: "deny" });
+ const event = { preventDefault: vi.fn() };
+ f.childContents.emit("will-navigate", event);
+ f.child.emit("page-title-updated", event);
+ expect(event.preventDefault).toHaveBeenCalledTimes(2);
+ });
+});
+
+describe("acceptVoiceWindow", () => {
+ const accept = (f: ReturnType<typeof fakes>, previous?: () => void) =>
+ acceptVoiceWindow(f.child as never, f.opener as never, previous, "linux");
+
+ it("adopts a window the page's main frame opened", () => {
+ const f = fakes();
+ f.childContents.opener = f.opener.mainFrame;
+ expect(accept(f)).toBeTypeOf("function");
+ expect(f.child.destroy).not.toHaveBeenCalled();
+ expect(f.child.setAlwaysOnTop).toHaveBeenCalled();
+ });
+
+ it("destroys a window a frame of the page opened", () => {
+ const f = fakes();
+ f.childContents.opener = {};
+ const previous = vi.fn();
+ expect(accept(f, previous)).toBeUndefined();
+ expect(f.child.destroy).toHaveBeenCalledOnce();
+ expect(f.child.setAlwaysOnTop).not.toHaveBeenCalled();
+ // The voice window already open stays.
+ expect(previous).not.toHaveBeenCalled();
+ });
+
+ it("destroys a window with no known opener", () => {
+ const f = fakes();
+ f.childContents.opener = null;
+ expect(accept(f)).toBeUndefined();
+ expect(f.child.destroy).toHaveBeenCalledOnce();
+ });
+
+ it("closes the previous window when a second one opens", () => {
+ const f = fakes();
+ f.childContents.opener = f.opener.mainFrame;
+ const previous = vi.fn();
+ expect(accept(f, previous)).toBeTypeOf("function");
+ expect(previous).toHaveBeenCalledOnce();
+ });
+});
diff --git a/apps/desktop/src/main/voice-window.ts b/apps/desktop/src/main/voice-window.ts
new file mode 100644
index 00000000..ea28b7b0
--- /dev/null
+++ b/apps/desktop/src/main/voice-window.ts
@@ -0,0 +1,83 @@
+// The floating voice window. The page opens it with `window.open("")` and
+// fills it with the Voice Mode or Recording window, so the call and its state
+// stay in the main page; this file only makes that window float, keeps it from
+// outliving the page it belongs to, and keeps the page running while the main
+// window is hidden. Electron types only, so a test can pass fakes.
+
+import type { BrowserWindow, WebContents } from "electron";
+
+export type VoiceWindowPlatform = NodeJS.Platform;
+
+// Hiding or minimizing the main window would otherwise throttle the page's
+// timers, which keep the call and the recording going. A window is counted
+// from when it is adopted to when it closes, so a closing window cannot lift
+// the hold its replacement took.
+const holds = new WeakMap<WebContents, number>();
+const hold = (opener: WebContents, delta: 1 | -1): void => {
+ const count = (holds.get(opener) ?? 0) + delta;
+ holds.set(opener, count);
+ if (!opener.isDestroyed()) opener.setBackgroundThrottling(count <= 0);
+};
+
+// What the page's `window.open` produced. The open handler cannot tell which
+// frame asked, so a window opened by a frame of the page, such as a site in
+// the link preview, is destroyed instead of getting a window of this app. One
+// voice window at a time: the newest request replaces `previous`. Returns the
+// function that closes the adopted window, or undefined when it was refused.
+export function acceptVoiceWindow(
+ child: BrowserWindow,
+ opener: WebContents,
+ previous: (() => void) | undefined,
+ platform: VoiceWindowPlatform,
+): (() => void) | undefined {
+ if (child.webContents.opener !== opener.mainFrame) {
+ child.destroy();
+ return undefined;
+ }
+ previous?.();
+ return adoptVoiceWindow(child, opener, platform);
+}
+
+// Floats `child` over other apps and ties it to `opener`. Returns a function
+// that closes it.
+export function adoptVoiceWindow(
+ child: BrowserWindow,
+ opener: WebContents,
+ platform: VoiceWindowPlatform,
+): () => void {
+ child.setAlwaysOnTop(true, "floating");
+ if (platform === "darwin")
+ child.setVisibleOnAllWorkspaces(true, {
+ visibleOnFullScreen: true,
+ skipTransformProcessType: true,
+ });
+ child.setMenuBarVisibility(false);
+ // The page sets no title; the window keeps its own.
+ child.on("page-title-updated", (event) => event.preventDefault());
+
+ const contents = child.webContents;
+ contents.setWindowOpenHandler(() => ({ action: "deny" }));
+ contents.on("will-navigate", (event) => event.preventDefault());
+ contents.on("will-attach-webview", (event) => event.preventDefault());
+
+ hold(opener, 1);
+ const close = (): void => {
+ if (!child.isDestroyed()) child.close();
+ };
+ // The window belongs to the page that filled it: a reload or a crash leaves
+ // nothing to drive it.
+ const onNavigate = (details: {
+ isMainFrame: boolean;
+ isSameDocument: boolean;
+ }): void => {
+ if (details.isMainFrame && !details.isSameDocument) close();
+ };
+ opener.on("did-start-navigation", onNavigate);
+ opener.on("render-process-gone", close);
+ child.on("closed", () => {
+ opener.off("did-start-navigation", onNavigate);
+ opener.off("render-process-gone", close);
+ hold(opener, -1);
+ });
+ return close;
+}
diff --git a/apps/desktop/src/main/window-manager.ts b/apps/desktop/src/main/window-manager.ts
index e1c7f704..bcae22fe 100644
--- a/apps/desktop/src/main/window-manager.ts
+++ b/apps/desktop/src/main/window-manager.ts
@@ -40,7 +40,9 @@ import {
sameOrigin,
serverSwitch,
windowLoadDecision,
+ voiceWindowRequest,
} from "./navigation.js";
+import { acceptVoiceWindow } from "./voice-window.js";
// Must run before app "ready".
export const registerAppScheme = (): void => {
@@ -149,6 +151,8 @@ export class WindowManagerModule implements Module {
#lastLoadReason: WindowLoadReason | undefined;
#pendingShow = false;
#revealTimer: NodeJS.Timeout | undefined;
+ // Closes the floating voice window, when there is one.
+ #closeVoiceWindow: (() => void) | undefined;
readonly #unsubscribe: (() => void)[] = [];
constructor(options: WindowManagerOptions) {
@@ -350,6 +354,7 @@ export class WindowManagerModule implements Module {
window.hide();
});
window.on("closed", () => {
+ this.#closeVoiceWindow?.();
titlebar?.webContents.close();
content.webContents.close();
if (this.#window === window) {
@@ -612,11 +617,41 @@ export class WindowManagerModule implements Module {
contents.on("will-redirect", (event) => {
if (event.isMainFrame) this.#guard(event, event.url, contents.getURL());
});
- contents.setWindowOpenHandler(({ url }) => {
- if (navigationDecision(url, this.#serverUrl()) !== "deny")
- this.#openExternal(url);
+ // The one window the page may open: the floating voice window, which it
+ // fills itself so the call stays in this page.
+ contents.setWindowOpenHandler((details) => {
+ if (voiceWindowRequest(details, this.#serverUrl(), contents.getURL()))
+ return {
+ action: "allow",
+ overrideBrowserWindowOptions: {
+ title: "Linger",
+ // The page asks for the size of its content, as in a browser.
+ useContentSize: true,
+ minimizable: false,
+ maximizable: false,
+ fullscreenable: false,
+ autoHideMenuBar: true,
+ backgroundColor: CANVAS,
+ },
+ };
+ if (navigationDecision(details.url, this.#serverUrl()) !== "deny")
+ this.#openExternal(details.url);
return { action: "deny" };
});
+ contents.on("did-create-window", (child) => {
+ const close = acceptVoiceWindow(
+ child,
+ contents,
+ this.#closeVoiceWindow,
+ process.platform,
+ );
+ if (!close) return;
+ this.#closeVoiceWindow = close;
+ child.on("closed", () => {
+ if (this.#closeVoiceWindow === close)
+ this.#closeVoiceWindow = undefined;
+ });
+ });
contents.on("will-attach-webview", (event) => event.preventDefault());
contents.on("did-fail-load", (_event, code, description, url, isMain) => {
// -3 is an aborted load, usually a navigation replacing another.
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index 5ffe4dda..271d1693 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -69,6 +69,9 @@ const api: LingerDesktopApi = {
return () => ipcRenderer.off(IPC.previewFrameRefused, listener);
},
},
+ voiceWindow: {
+ showMainWindow: () => ipcRenderer.invoke(IPC.voiceWindowShowMain),
+ },
...(process.platform === "darwin"
? {
permissions: {
diff --git a/apps/desktop/src/shared/api.ts b/apps/desktop/src/shared/api.ts
index 934d640e..aab2176e 100644
--- a/apps/desktop/src/shared/api.ts
+++ b/apps/desktop/src/shared/api.ts
@@ -113,6 +113,13 @@ export interface LingerDesktopApi {
callback: (frameName: string, url: string) => void,
): () => void;
};
+ // The page floats its Voice Mode and Recording windows in a window of their
+ // own opened with `window.open("")`; present only when this app allows that,
+ // so an older app keeps them in the page.
+ readonly voiceWindow: {
+ // Brings the main window to the front, from the floating window.
+ showMainWindow(): Promise<void>;
+ };
// macOS only.
readonly permissions?: {
act(step: DesktopPermissionStep): Promise<void>;
@@ -139,4 +146,5 @@ export const IPC = {
connectorOAuthPrepare: "connector-oauth.prepare",
connectorOAuthReturn: "connector-oauth.return",
previewFrameRefused: "preview.frame-refused",
+ voiceWindowShowMain: "voice-window.show-main",
} as const;
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index bd54b4ce..c74e45ef 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -94,8 +94,13 @@ build:assets` to check the initial JS budget.
earlier one is saving. Both in-page voice windows retain a visible, draggable
title bar: dark in browsers, the window's own surface colour in the desktop
app. Picture-in-picture keeps the browser title bar. The desktop app cannot
- open picture-in-picture, so there voice windows stay in the page, offer no
- float button, and on macOS stay out of the window drag strip.
+ open Document Picture-in-Picture; when its preload offers
+ `lingerDesktop.voiceWindow`, `voice-pip.ts` opens the floating window with
+ `window.open("")` instead (the desktop main process allows only that call),
+ renders the same voice UI into it, and shows a Show Linger window button that
+ brings the main window forward while the call keeps running. A desktop app
+ without `voiceWindow` keeps the voice windows in the page, with no float
+ button, and on macOS out of the window drag strip.
- The compact primary rail reveals labels on hover and keyboard focus without
moving link hit areas or neighbouring links. A stationary pointer at an edge
must not trigger repeated hover enter/leave; sidebar expansion and Chat list
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 b96e35c0..c7d70591 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
@@ -376,6 +376,57 @@ describe("Voice Mode mini window", () => {
}
});
+ it("floats in the desktop app's own window and brings its main window back", async () => {
+ const fake = installFakeVoicePip();
+ const showMainWindow = vi.fn(async () => {});
+ const desktop = window as { lingerDesktop?: unknown };
+ desktop.lingerDesktop = { voiceWindow: { showMainWindow } };
+ const open = vi
+ .spyOn(window, "open")
+ .mockReturnValue(fake.pipWindow as unknown as Window);
+ try {
+ renderWindow();
+ // In the page, one click floats the call into the desktop's window.
+ await act(async () => {
+ fireEvent.click(
+ screen.getByRole("button", { name: "Float Voice Mode window" }),
+ );
+ await Promise.resolve();
+ });
+ const floating = within(fake.document.body);
+ await floating.findByRole("region", { name: "Voice Mode window" });
+ expect(fake.requestWindow).not.toHaveBeenCalled();
+ expect(open).toHaveBeenCalledOnce();
+ expect(screen.getByTestId("location")).toHaveTextContent(
+ "/t/tenant-northstar/rooms/room-other/chat",
+ );
+
+ // The way back opens the conversation and shows the main window; the
+ // floating window and the call stay.
+ fireEvent.click(
+ floating.getByRole("button", { name: "Show Linger window" }),
+ );
+ expect(showMainWindow).toHaveBeenCalledOnce();
+ expect(screen.getByTestId("location")).toHaveTextContent(
+ "/t/tenant-northstar/rooms/room-voice/chat",
+ );
+ expect(voice.exit).not.toHaveBeenCalled();
+ expect(
+ floating.getByRole("region", { name: "Voice Mode window" }),
+ ).toBeInTheDocument();
+
+ // Closing the floating window ends Voice Mode.
+ act(() => fake.pipWindow.close());
+ await waitFor(() => expect(voice.exit).toHaveBeenCalledOnce());
+ } finally {
+ open.mockRestore();
+ delete desktop.lingerDesktop;
+ 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 2562eaa2..403ddf67 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
@@ -39,9 +39,11 @@ import { voiceModeStatusLabel } from "./voice-mode-presentation";
import styles from "./voice-mode.module.css";
import { registerVoiceWindow, type VoiceWindowAction } from "./voice-ui-bridge";
import {
+ canShowDesktopMainWindow,
onVoicePipClosedByHuman,
openVoicePip,
returnedToOpener,
+ showDesktopMainWindow,
useVoicePip,
voicePipSupported,
} from "./voice-pip";
@@ -343,6 +345,22 @@ function MiniWindow({
)}
{/* Back in the page, one click floats the call again; the browser
opens that window only from a click in the page. */}
+ {/* The desktop app's floating window has no back to tab button; this
+ brings its main window forward and the call goes on. */}
+ {pip && canShowDesktopMainWindow() ? (
+ <Button
+ aria-label="Show Linger window"
+ onClick={() => {
+ void navigate(`/t/${tenantId}/rooms/${roomId}/chat`);
+ showDesktopMainWindow();
+ }}
+ size="compactIcon"
+ title="Show the Linger window; the call continues"
+ tone="ghost"
+ >
+ <Icon icon={Maximize01Icon} size={14} />
+ </Button>
+ ) : null}
{pip || !voicePipSupported() ? null : (
<Button
aria-label="Float Voice Mode window"
diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts
index 2ceee02c..764ec38c 100644
--- a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts
+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts
@@ -3,11 +3,13 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { defineGlobalProperty } from "@/test/global-properties";
import {
+ canShowDesktopMainWindow,
closeVoicePip,
onVoicePipClosedByHuman,
openVoicePip,
resetVoicePipForTest,
returnedToOpener,
+ showDesktopMainWindow,
voicePipSupported,
} from "./voice-pip";
@@ -52,7 +54,7 @@ describe("Voice Mode picture-in-picture window", () => {
await expect(openVoicePip("voice-mode")).resolves.toBeUndefined();
});
- it("stays in the page inside the desktop app", async () => {
+ it("stays in the page inside a desktop app that cannot float it", async () => {
const fake = installFakeVoicePip();
const desktop = window as { lingerDesktop?: unknown };
desktop.lingerDesktop = {};
@@ -65,6 +67,56 @@ describe("Voice Mode picture-in-picture window", () => {
}
});
+ it("opens the desktop app's own window when its preload offers one", async () => {
+ // Electron exposes the browser API too but cannot open its window.
+ const fake = installFakeVoicePip();
+ const showMainWindow = vi.fn(async () => {});
+ const desktop = window as { lingerDesktop?: unknown };
+ desktop.lingerDesktop = { voiceWindow: { showMainWindow } };
+ const open = vi
+ .spyOn(window, "open")
+ .mockReturnValue(fake.pipWindow as unknown as Window);
+ try {
+ expect(voicePipSupported()).toBe(true);
+ expect(canShowDesktopMainWindow()).toBe(true);
+ await expect(openVoicePip("recording")).resolves.toBe(fake.pipWindow);
+ expect(fake.requestWindow).not.toHaveBeenCalled();
+ expect(open).toHaveBeenCalledWith(
+ "",
+ expect.stringMatching(/^linger-voice-window-\d+$/),
+ "popup=yes,width=420,height=720",
+ );
+ showDesktopMainWindow();
+ expect(showMainWindow).toHaveBeenCalledOnce();
+
+ const closed = vi.fn();
+ onVoicePipClosedByHuman("recording", closed);
+ fake.pipWindow.close();
+ expect(closed).toHaveBeenCalledOnce();
+ } finally {
+ open.mockRestore();
+ delete desktop.lingerDesktop;
+ }
+ });
+
+ it("stays in the page when the desktop app refuses the window", async () => {
+ const desktop = window as { lingerDesktop?: unknown };
+ desktop.lingerDesktop = {
+ voiceWindow: { showMainWindow: vi.fn(async () => {}) },
+ };
+ const open = vi.spyOn(window, "open").mockReturnValue(null);
+ try {
+ await expect(openVoicePip("voice-mode")).resolves.toBeUndefined();
+ } finally {
+ open.mockRestore();
+ delete desktop.lingerDesktop;
+ }
+ });
+
+ it("offers no way back to the main window outside the desktop app", () => {
+ expect(canShowDesktopMainWindow()).toBe(false);
+ });
+
it("carries the page's styles and theme, including later ones", async () => {
const early = document.createElement("style");
early.dataset.testStyle = "";
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 be3cc36f..996f8f1c 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
@@ -32,10 +32,59 @@ function noteShown() {
if (document.visibilityState === "visible") shownAt = performance.now();
}
+/**
+ * The window name the desktop app recognizes; it floats the window opened
+ * under it. The suffix keeps a window that is still closing from being reused.
+ */
+const desktopWindowTarget = "linger-voice-window";
+let desktopWindowCount = 0;
+
+/** The desktop app's own window, standing in for the missing picture-in-picture. */
+const desktopVoiceWindow: DocumentPictureInPicture = {
+ async requestWindow({ height, width } = {}) {
+ const opened = window.open(
+ "",
+ `${desktopWindowTarget}-${++desktopWindowCount}`,
+ `popup=yes,width=${width ?? 320},height=${height ?? 240}`,
+ );
+ if (!opened) throw new Error("The desktop app refused the voice window.");
+ return opened;
+ },
+};
+
+/** Set when the desktop app can open the floating window and bring the main one back. */
+interface DesktopVoiceWindow {
+ showMainWindow(): Promise<void>;
+}
+
+function desktopBridge(): DesktopVoiceWindow | undefined {
+ return (
+ window as Window & {
+ lingerDesktop?: { voiceWindow?: DesktopVoiceWindow };
+ }
+ ).lingerDesktop?.voiceWindow;
+}
+
+/**
+ * Whether the floating window is the desktop app's, whose main window can be
+ * brought back from it. The browser's window has its own back to tab button.
+ */
+export function canShowDesktopMainWindow() {
+ return desktopBridge() !== undefined;
+}
+
+/** Brings the desktop app's main window to the front; the call keeps running. */
+export function showDesktopMainWindow() {
+ void desktopBridge()
+ ?.showMainWindow()
+ .catch(() => undefined);
+}
+
function api(): DocumentPictureInPicture | undefined {
- // Electron exposes the API but cannot open its window, so voice windows in
- // the desktop app stay in the page and offer no float button.
- if (isDesktopShell()) return undefined;
+ // The desktop app cannot open Document Picture-in-Picture windows, so it
+ // opens its own when its preload says it can; an older app without that
+ // keeps the voice windows in the page.
+ if (isDesktopShell()) return desktopBridge() ? desktopVoiceWindow : undefined;
return (
window as Window & { documentPictureInPicture?: DocumentPictureInPicture }
).documentPictureInPicture;
diff --git a/apps/web/src/features/rooms/voice-control/recording-window.test.tsx b/apps/web/src/features/rooms/voice-control/recording-window.test.tsx
index 75ff0da8..573268b6 100644
--- a/apps/web/src/features/rooms/voice-control/recording-window.test.tsx
+++ b/apps/web/src/features/rooms/voice-control/recording-window.test.tsx
@@ -617,6 +617,38 @@ describe("Recording window", () => {
expect(voice.leavePage).not.toHaveBeenCalled();
});
+ it("brings the desktop app's main window back from its floating window", async () => {
+ const { frame, pipWindow, requestWindow } = stubPictureInPicture();
+ const showMainWindow = vi.fn(async () => {});
+ const desktop = window as { lingerDesktop?: unknown };
+ desktop.lingerDesktop = { voiceWindow: { showMainWindow } };
+ const open = vi
+ .spyOn(window, "open")
+ .mockReturnValue(pipWindow as unknown as Window);
+ try {
+ renderWindow(voiceValue());
+ // In the page the main window is already in front.
+ expect(
+ screen.queryByRole("button", { name: "Show Linger window" }),
+ ).toBeNull();
+ await act(() => openVoicePip("recording"));
+ expect(requestWindow).not.toHaveBeenCalled();
+ const floating = within(frame.contentDocument!.body);
+ fireEvent.click(
+ floating.getByRole("button", { name: "Show Linger window" }),
+ );
+ expect(showMainWindow).toHaveBeenCalledOnce();
+ // The recording is untouched and its window stays.
+ expect(
+ floating.getByRole("button", { name: "Stop recording" }),
+ ).toBeTruthy();
+ expect(screen.getByTestId("window-state")).toHaveTextContent("open");
+ } finally {
+ open.mockRestore();
+ delete desktop.lingerDesktop;
+ }
+ });
+
it("opens a new Meeting at full size after stopping a minimized recording", async () => {
const { frame, pipWindow, requestWindow } = stubPictureInPicture();
const firstVoice = voiceValue();
diff --git a/apps/web/src/features/rooms/voice-control/recording-window.tsx b/apps/web/src/features/rooms/voice-control/recording-window.tsx
index 9bd16d8e..1574ff8c 100644
--- a/apps/web/src/features/rooms/voice-control/recording-window.tsx
+++ b/apps/web/src/features/rooms/voice-control/recording-window.tsx
@@ -8,10 +8,12 @@ import {
import { createPortal } from "react-dom";
import {
+ canShowDesktopMainWindow,
closeVoicePip,
onVoicePipClosedByHuman,
openVoicePip,
returnedToOpener,
+ showDesktopMainWindow,
useVoicePip,
voicePipSupported,
} from "../chat/voice-mode/voice-pip";
@@ -255,6 +257,9 @@ export default function RecordingWindow() {
: undefined
}
onMoveStart={startMove}
+ onShowMain={
+ pip && canShowDesktopMainWindow() ? showDesktopMainWindow : undefined
+ }
onViewChange={changeView}
view={view}
/>
@@ -329,6 +334,7 @@ function RecordingPanel({
floating,
onFloat,
onMoveStart,
+ onShowMain,
onViewChange,
view,
}: {
@@ -336,6 +342,7 @@ function RecordingPanel({
floating: "page" | "pip";
onFloat?: () => void;
onMoveStart: (event: PointerEvent<HTMLDivElement>) => void;
+ onShowMain?: () => void;
onViewChange: (view: RecordingView | undefined) => void;
view?: RecordingView;
}) {
@@ -355,6 +362,7 @@ function RecordingPanel({
floating={floating}
onFloat={onFloat}
onMoveStart={onMoveStart}
+ onShowMain={onShowMain}
onExit={() => {
// Saving finishes in the background; the sidebar's Recording tool
// shows its progress and reopens this window on request.
diff --git a/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsx b/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsx
index 5f2b674a..658d850d 100644
--- a/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsx
+++ b/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsx
@@ -4,6 +4,7 @@ import {
ArrowUp01Icon,
Cancel01Icon,
Loading03Icon,
+ Maximize01Icon,
Mic01Icon,
PauseIcon,
PictureInPictureOnIcon,
@@ -52,6 +53,7 @@ export function VoiceFocusSurface({
onExit,
onFloat,
onMoveStart,
+ onShowMain,
onViewChange,
panels,
view,
@@ -64,6 +66,8 @@ export function VoiceFocusSurface({
onFloat?: () => void;
/** Starts moving the in-page window from its title bar. */
onMoveStart?: (event: PointerEvent<HTMLDivElement>) => void;
+ /** Brings the main window back, from a floating window of the desktop app. */
+ onShowMain?: () => void;
onViewChange?: (view: RecordingView | undefined) => void;
/** Present once a recording runs; before that only the transcript shows. */
panels?: RecordingPanels;
@@ -271,6 +275,17 @@ export function VoiceFocusSurface({
<Icon icon={PictureInPictureOnIcon} />
</button>
) : null}
+ {onShowMain ? (
+ <button
+ aria-label="Show Linger window"
+ className={styles.windowButton}
+ onClick={onShowMain}
+ title="Show the Linger window; recording continues"
+ type="button"
+ >
+ <Icon icon={Maximize01Icon} />
+ </button>
+ ) : null}
</div>
);
return (