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): size, place and return from the floating voice window

Kilyn1259e0887460
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 5cc78fa8..623426a6 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -334,10 +334,14 @@ Gateway and runs Agents. The daemon exits with the app.
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.
+ itself opened is kept; one from a frame in it is destroyed. It opens at the
+ bottom right of the main window's screen and resizes down to 240x96. Its
+ native close button ends the call or the recording;
+ `lingerDesktop.voiceWindow.showMainWindow()` (its presence is how the SPA
+ knows the app supports this) restores and focuses the main window, on macOS
+ bringing the app in front of the active one, and the SPA then closes the
+ floating window and keeps the session in the page. 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.test.ts b/apps/desktop/src/main/desktop-ipc.test.ts
index 96d4bb8d..b58c28b4 100644
--- a/apps/desktop/src/main/desktop-ipc.test.ts
+++ b/apps/desktop/src/main/desktop-ipc.test.ts
@@ -6,7 +6,9 @@ import type { UpdateState } from "./updater.js";
const handlers = vi.hoisted(
() => new Map<string, (event: unknown, ...args: unknown[]) => unknown>(),
);
+const focusApp = vi.hoisted(() => vi.fn());
vi.mock("electron", () => ({
+ app: { focus: focusApp },
ipcMain: {
handle: (
channel: string,
@@ -45,6 +47,7 @@ const fixture = async (
const windows = {
...stubModule("WindowManager"),
webContents: () => ({ send }),
+ show: vi.fn(),
};
const bus = new EventBus();
const host = testHost(
@@ -68,7 +71,7 @@ const fixture = async (
updateState = state;
bus.emit("update.changed", state.kind);
};
- return { host, local, updater, send, setUpdate, invoke };
+ return { host, local, updater, send, setUpdate, invoke, windows };
};
afterEach(() => handlers.clear());
@@ -120,6 +123,23 @@ describe("DesktopIpcModule local account", () => {
});
});
+describe("DesktopIpcModule voice window", () => {
+ it("shows the main window for the server's page only", async () => {
+ const f = await fixture();
+ await f.invoke(IPC.voiceWindowShowMain);
+ expect(f.windows.show).toHaveBeenCalledOnce();
+ // macOS raises a window only inside the active app.
+ expect(focusApp).toHaveBeenCalledTimes(
+ process.platform === "darwin" ? 1 : 0,
+ );
+ expect(() =>
+ f.invoke(IPC.voiceWindowShowMain, "https://evil.example.com"),
+ ).toThrow("Not allowed");
+ expect(f.windows.show).toHaveBeenCalledOnce();
+ await f.host.stop("quit");
+ });
+});
+
describe("DesktopIpcModule updates", () => {
it("gives the page the update state without its release page URL", async () => {
const f = await fixture();
diff --git a/apps/desktop/src/main/desktop-ipc.ts b/apps/desktop/src/main/desktop-ipc.ts
index d01440e0..7fbd0a23 100644
--- a/apps/desktop/src/main/desktop-ipc.ts
+++ b/apps/desktop/src/main/desktop-ipc.ts
@@ -195,7 +195,14 @@ export class DesktopIpcModule implements Module {
}
});
- handle(IPC.voiceWindowShowMain, () => windows.show());
+ // The way back from the floating voice window, which stays up while the
+ // main window is minimized, hidden to the tray or behind another app.
+ // macOS brings a window forward only within the app, so the app comes
+ // forward too.
+ handle(IPC.voiceWindowShowMain, () => {
+ windows.show();
+ if (process.platform === "darwin") app.focus({ steal: true });
+ });
handle(IPC.updateState, () => updateView(updater.state()));
handle(IPC.updateInstall, () => updater.install());
handle(IPC.updateCheck, () => updater.check());
diff --git a/apps/desktop/src/main/voice-window.test.ts b/apps/desktop/src/main/voice-window.test.ts
index fa7de6c9..5a883ff4 100644
--- a/apps/desktop/src/main/voice-window.test.ts
+++ b/apps/desktop/src/main/voice-window.test.ts
@@ -1,7 +1,11 @@
import { EventEmitter } from "node:events";
import { describe, expect, it, vi } from "vitest";
-import { acceptVoiceWindow, adoptVoiceWindow } from "./voice-window.js";
+import {
+ acceptVoiceWindow,
+ adoptVoiceWindow,
+ voiceWindowPosition,
+} from "./voice-window.js";
// Electron stand-ins: only what the module touches.
function fakes() {
@@ -156,3 +160,29 @@ describe("acceptVoiceWindow", () => {
expect(previous).toHaveBeenCalledOnce();
});
});
+
+describe("voiceWindowPosition", () => {
+ const workArea = { x: 0, y: 25, width: 1470, height: 931 };
+
+ it("opens at the bottom right of the screen", () => {
+ expect(voiceWindowPosition({ width: 320, height: 240 }, workArea)).toEqual({
+ x: 1126,
+ y: 692,
+ });
+ });
+
+ it("keeps a window larger than the screen at its top left", () => {
+ expect(
+ voiceWindowPosition({ width: 2000, height: 1200 }, workArea),
+ ).toEqual({ x: 0, y: 25 });
+ });
+
+ it("follows a screen left of the main one", () => {
+ expect(
+ voiceWindowPosition(
+ { width: 320, height: 240 },
+ { x: -2560, y: -400, width: 2560, height: 1415 },
+ ),
+ ).toEqual({ x: -344, y: 751 });
+ });
+});
diff --git a/apps/desktop/src/main/voice-window.ts b/apps/desktop/src/main/voice-window.ts
index ea28b7b0..52a95a52 100644
--- a/apps/desktop/src/main/voice-window.ts
+++ b/apps/desktop/src/main/voice-window.ts
@@ -8,6 +8,38 @@ import type { BrowserWindow, WebContents } from "electron";
export type VoiceWindowPlatform = NodeJS.Platform;
+export interface VoiceWindowSize {
+ readonly width: number;
+ readonly height: number;
+}
+
+interface Area extends VoiceWindowSize {
+ readonly x: number;
+ readonly y: number;
+}
+
+// The smallest the window gets: the one-row minimized state still fits.
+export const VOICE_WINDOW_MIN: VoiceWindowSize = { width: 240, height: 96 };
+// The gap the window keeps from the screen's edges when it opens.
+const VOICE_WINDOW_MARGIN = 24;
+
+// Where the window opens: the bottom right of the main window's screen, as a
+// browser places its picture-in-picture window. A window larger than the
+// screen keeps its title bar on the screen.
+export const voiceWindowPosition = (
+ window: VoiceWindowSize,
+ workArea: Area,
+): { readonly x: number; readonly y: number } => ({
+ x: Math.max(
+ workArea.x,
+ workArea.x + workArea.width - window.width - VOICE_WINDOW_MARGIN,
+ ),
+ y: Math.max(
+ workArea.y,
+ workArea.y + workArea.height - window.height - VOICE_WINDOW_MARGIN,
+ ),
+});
+
// 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
diff --git a/apps/desktop/src/main/window-manager.ts b/apps/desktop/src/main/window-manager.ts
index bcae22fe..654b1cec 100644
--- a/apps/desktop/src/main/window-manager.ts
+++ b/apps/desktop/src/main/window-manager.ts
@@ -5,6 +5,7 @@ import {
nativeImage,
net,
protocol,
+ screen,
session,
shell,
type BaseWindowConstructorOptions,
@@ -42,7 +43,11 @@ import {
windowLoadDecision,
voiceWindowRequest,
} from "./navigation.js";
-import { acceptVoiceWindow } from "./voice-window.js";
+import {
+ VOICE_WINDOW_MIN,
+ acceptVoiceWindow,
+ voiceWindowPosition,
+} from "./voice-window.js";
// Must run before app "ready".
export const registerAppScheme = (): void => {
@@ -627,6 +632,8 @@ export class WindowManagerModule implements Module {
title: "Linger",
// The page asks for the size of its content, as in a browser.
useContentSize: true,
+ minWidth: VOICE_WINDOW_MIN.width,
+ minHeight: VOICE_WINDOW_MIN.height,
minimizable: false,
maximizable: false,
fullscreenable: false,
@@ -647,6 +654,12 @@ export class WindowManagerModule implements Module {
);
if (!close) return;
this.#closeVoiceWindow = close;
+ const main = this.#window;
+ if (main && !main.isDestroyed()) {
+ const { workArea } = screen.getDisplayMatching(main.getBounds());
+ const { x, y } = voiceWindowPosition(child.getBounds(), workArea);
+ child.setPosition(x, y);
+ }
child.on("closed", () => {
if (this.#closeVoiceWindow === close)
this.#closeVoiceWindow = undefined;