Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
- Failed and stopped Ask AI answers save their final status before notifying clients, so reloading an ended stream cannot leave the answer busy.
- Audio pipeline progress keeps updating after temporary network failures, and interrupted Ask AI answers reconnect without duplicating text.
- Transcript searches refresh after re-transcription, and browser transcription progress and notifications follow the interface language.

- Recordings with multiple transcript sources show every source in the transcript switcher, with the preferred source first. The detail API includes all transcripts while keeping the singular `transcription` field for existing clients.
- Library text search matches every transcript source available for a recording, including older sources, without duplicate results.

- The Dashboard marks Plaud setup as skipped in local-only mode instead of incorrectly showing it as completed.
- Saved playback, date/time and sync-on-return preferences take effect immediately without navigating away from Settings.
- Auto-play next starts the next recording in the current library order and stops at the end. Recording dates now follow the selected relative, absolute or ISO format across library rows, detail and player views.
- Returning to the app tab syncs a connected Plaud account when enabled, with a one-minute throttle to avoid repeated syncs during rapid tab switches.
- A failure to open or lock the Mac app's instance-lock file now shows a startup error instead of silently exiting as if another copy were running.
- Launch at Login keeps its tray check mark in sync after an interface-language change rebuilds the menu.
- Changing the Mac app's locale through desktop preferences no longer hangs while rebuilding the tray menu.
Expand Down
224 changes: 224 additions & 0 deletions contract-tests/tests/settings-behavior-ui.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import { type APIRequestContext, type Browser, expect, type Page, type Route, test } from "@playwright/test";
import { baseURL, clientHeaders, newUserContext, uploadRecording } from "../helpers/api";

test.use({ viewport: { width: 1280, height: 800 } });

async function account(browser: Browser, patch: Record<string, unknown> = {}) {
const api = await newUserContext("settings-behavior");
expect((await api.put("/api/settings/user", { data: {
onboardingCompleted: true, autoSyncEnabled: false, syncOnMount: false,
syncOnVisibilityChange: false, ...patch,
} })).ok()).toBeTruthy();
const context = await browser.newContext({ baseURL, locale: "en-US", extraHTTPHeaders: clientHeaders(), storageState: await api.storageState() });
await context.addInitScript(() => {
const original = window.fetch.bind(window);
(window as unknown as { syncRequests: number }).syncRequests = 0;
window.fetch = (input, init) => {
if (String(input).endsWith("/api/plaud/sync") && init?.method === "POST") {
(window as unknown as { syncRequests: number }).syncRequests++;
}
return original(input, init);
};
});
const page = await context.newPage();
return { api, page, close: async () => { await context.close(); await api.dispose(); } };
}

async function recording(api: APIRequestContext, title: string): Promise<string> {
const id = await uploadRecording(api);
expect((await api.patch(`/api/recordings/${id}`, { data: { filename: title } })).ok()).toBeTruthy();
return id;
}

async function visibility(page: Page, state: "hidden" | "visible"): Promise<number> {
return page.evaluate((value) => {
Object.defineProperty(document, "visibilityState", { configurable: true, value });
document.dispatchEvent(new Event("visibilitychange"));
return (window as unknown as { syncRequests: number }).syncRequests;
}, state);
}

const syncResult = { success: true, newRecordings: 0, updatedRecordings: 0, errors: [], needsReconnect: false };

test("auto-play follows filtered name order, plays next, and stops at the last or excluded recording", async ({ browser }) => {
const user = await account(browser, { autoPlayNext: true, recordingListSortOrder: "name" });
const { page, api } = user;
try {
const bravo = await recording(api, "Queue Bravo");
const alpha = await recording(api, "Queue Alpha");
await recording(api, "Excluded");
await page.goto("/recordings?q=Queue");
const rows = page.getByTestId("recording-row");
await expect(rows).toHaveCount(2);
await expect(rows.first()).toContainText("Queue Alpha");
await rows.first().locator("button").first().click();
await expect(page.getByTestId("player-play")).toBeEnabled();
await page.getByTestId("player-play").click();
await expect.poll(() => page.locator("audio").evaluate((el: HTMLAudioElement) => el.paused)).toBe(false);
await page.locator("audio").evaluate((el: HTMLAudioElement) => { el.pause(); el.dispatchEvent(new Event("ended")); });
await expect(page.locator("audio")).toHaveAttribute("src", `/api/recordings/${bravo}/audio`);
await expect(rows.filter({ hasText: "Queue Bravo" }).locator("button").first()).toHaveAttribute("aria-current", "true");
await expect.poll(() => page.locator("audio").evaluate((el: HTMLAudioElement) => el.paused)).toBe(false);
const last = await page.locator("audio").evaluate((el: HTMLAudioElement) => {
el.pause(); el.dispatchEvent(new Event("ended")); return el.getAttribute("src");
});
expect(last).toBe(`/api/recordings/${bravo}/audio`);
await rows.filter({ hasText: "Queue Alpha" }).locator("button").first().click();
await page.getByTestId("player-play").click();
await page.locator("audio").evaluate((el: HTMLAudioElement) => el.pause());
await page.getByTestId("recording-search").fill("Queue Bravo");
await expect(rows).toHaveCount(1);
const excluded = await page.locator("audio").evaluate((el: HTMLAudioElement) => { el.dispatchEvent(new Event("ended")); return el.getAttribute("src"); });
expect(excluded).toBe(`/api/recordings/${alpha}/audio`);
} finally { await user.close(); }
});

test("disabled auto-play and an empty library never advance", async ({ browser }) => {
const user = await account(browser, { autoPlayNext: false, recordingListSortOrder: "name" });
const { api, page } = user;
try {
await page.goto("/recordings");
await expect(page.getByTestId("recording-row")).toHaveCount(0);
await page.locator("audio").evaluate((el: HTMLAudioElement) => el.dispatchEvent(new Event("ended")));
await expect(page.locator("audio")).not.toHaveAttribute("src");
const id = await recording(api, "First");
await recording(api, "Second");
await page.reload();
const row = page.getByTestId("recording-row").filter({ hasText: "First" });
await row.locator("button").first().click();
await expect(page.getByTestId("player-play")).toBeEnabled();
await page.getByTestId("player-play").click();
const src = await page.locator("audio").evaluate((el: HTMLAudioElement) => { el.pause(); el.dispatchEvent(new Event("ended")); return el.getAttribute("src"); });
expect(src).toBe(`/api/recordings/${id}/audio`);
} finally { await user.close(); }
});

for (const format of ["relative", "absolute", "iso"] as const) {
test(`${format} dates agree across library, detail and player`, async ({ browser }) => {
const user = await account(browser, { dateTimeFormat: format });
const { page, api } = user;
try {
const id = await recording(api, "Date preference");
const start = new Date(Date.now() - 5 * 60_000).toISOString();
await page.route("**/api/recordings", async (route) => {
const response = await route.fetch();
const body = await response.json();
body.recordings = body.recordings.map((r: Record<string, unknown>) => ({ ...r, startTime: start }));
await route.fulfill({ response, json: body });
});
await page.route(`**/api/recordings/${id}`, async (route) => {
const response = await route.fetch();
const body = await response.json();
body.recording.startTime = start;
await route.fulfill({ response, json: body });
});
await page.goto("/recordings");
const expected = format === "iso" ? start : format === "relative" ? "5 minutes ago" : await page.evaluate((value) => new Date(value).toLocaleString("en-US"), start);
const row = page.getByTestId("recording-row");
await expect(row).toContainText(expected);
await expect(row.locator("button").first()).toHaveAccessibleName(new RegExp(expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
await row.locator("button").first().click();
await expect(page.getByTestId("player").locator("time")).toContainText(expected);
await page.getByRole("tab", { name: "Details", exact: true }).click();
await expect(page.getByTestId("details-card")).toContainText(expected);
} finally { await user.close(); }
});
}

test("visibility sync observes saved toggles immediately, respects lock/throttle, and ignores a failed save", async ({ browser }) => {
const user = await account(browser);
const { page } = user;
let held: Route | undefined;
let hold = true;
let failSave = false;
try {
await page.clock.install();
await page.route("**/api/plaud/connection", (route) => route.fulfill({ json: { connected: true } }));
await page.route("**/api/plaud/sync", async (route) => {
if (hold) { held = route; return; }
await route.fulfill({ json: syncResult });
});
await page.route("**/api/settings/user", async (route) => {
if (failSave && route.request().method() === "PUT") {
failSave = false;
await route.fulfill({ status: 500, json: { error: "Save rejected" } });
} else await route.continue();
});
await page.goto("/settings/sync");
const toggle = page.getByRole("switch", { name: "Sync on tab visibility", exact: true });
await expect(toggle).not.toBeChecked();
expect(await visibility(page, "visible")).toBe(0);
await toggle.click();
await expect(toggle).toBeChecked();
await expect(toggle).toBeEnabled();
expect(await visibility(page, "hidden")).toBe(0);
expect(await visibility(page, "visible")).toBe(1);
await expect.poll(() => Boolean(held)).toBe(true);
await page.clock.fastForward(60_001);
expect(await visibility(page, "visible")).toBe(1);
await toggle.click();
await expect(toggle).not.toBeChecked();
await expect(toggle).toBeEnabled();
const finished = page.waitForResponse("**/api/plaud/sync");
await held!.fulfill({ json: syncResult });
await (await finished).finished();
hold = false;
expect(await visibility(page, "visible")).toBe(1);
await toggle.click();
await expect(toggle).toBeChecked();
await expect(toggle).toBeEnabled();
const synced = page.waitForResponse("**/api/plaud/sync");
expect(await visibility(page, "visible")).toBe(2);
await (await synced).finished();
expect(await visibility(page, "visible")).toBe(2);
failSave = true;
await toggle.click();
await expect(page.getByText("Failed to save settings. Changes reverted.", { exact: true })).toBeVisible();
await expect(toggle).toBeChecked();
await expect(toggle).toBeEnabled();
await page.clock.fastForward(60_001);
expect(await visibility(page, "visible")).toBe(3);
await expect(page).toHaveURL(/\/settings\/sync$/);
} finally { await user.close(); }
});

for (const gate of ["local-only", "disconnected"] as const) {
test(`visibility sync stays off when ${gate}`, async ({ browser }) => {
const user = await account(browser, { syncOnVisibilityChange: true, plaudEnabled: gate !== "local-only" });
try {
await user.page.route("**/api/plaud/connection", (route) => route.fulfill({ json: { connected: gate !== "disconnected" } }));
await user.page.goto("/dashboard");
await expect(user.page.getByRole("heading", { level: 1, name: "Dashboard" })).toBeVisible();
expect(await visibility(user.page, "visible")).toBe(0);
} finally { await user.close(); }
});
}

test("an in-flight shell settings response cannot revert a newer saved visibility preference", async ({ browser }) => {
const user = await account(browser);
const { page } = user;
let stale: { route: Route; body: string } | undefined;
try {
await page.route("**/api/plaud/connection", (route) => route.fulfill({ json: { connected: true } }));
await page.route("**/api/plaud/sync", (route) => route.fulfill({ json: syncResult }));
await page.goto("/settings/playback");
await expect(page.getByRole("switch", { name: "Auto-play next recording", exact: true })).toBeEnabled();
await page.route("**/api/settings/user", async (route) => {
if (route.request().method() === "GET") {
const response = await route.fetch();
stale = { route, body: await response.text() };
} else await route.continue();
});
await page.getByTestId("settings-nav").getByRole("link", { name: "Sync settings", exact: true }).click();
const toggle = page.getByRole("switch", { name: "Sync on tab visibility", exact: true });
await expect(toggle).toBeEnabled();
await expect.poll(() => Boolean(stale)).toBe(true);
await toggle.click();
await expect(toggle).toBeChecked();
await expect(toggle).toBeEnabled();
const response = page.waitForResponse("**/api/settings/user");
await stale!.route.fulfill({ contentType: "application/json", body: stale!.body });
await (await response).finished();
expect(await visibility(page, "visible")).toBe(1);
} finally { await user.close(); }
});
19 changes: 19 additions & 0 deletions contract-tests/tests/ui-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,25 @@ test.describe("shell: account menu", () => {
});

test.describe("dashboard", () => {
test("local-only mode marks Plaud setup as skipped rather than completed", async ({ browser }) => {
const { api, page, close } = await freshPage(browser);
try {
expect((await api.put("/api/settings/user", { data: { plaudEnabled: false } })).status()).toBe(200);
await page.goto("/dashboard");
const setup = page.getByRole("region", { name: "Set up" });
const skipped = setup.getByRole("status", { name: "Connect Plaud — skipped in local-only mode", exact: true });
await expect(skipped).toBeVisible();
await expect(skipped).toHaveText("Connect Plaud — skipped in local-only mode");
await expect(skipped.locator(".text-success")).toHaveCount(0);
await expect(skipped.getByText("Done", { exact: true })).toHaveCount(0);
await expect(setup.getByRole("link", { name: /Connect Plaud/ })).toHaveCount(0);
await expect(setup.getByRole("link", { name: "Add an AI provider" })).toBeVisible();
expect(await (await api.get("/api/plaud/connection")).json()).toMatchObject({ connected: false });
} finally {
await close();
}
});

test("a new account sees the empty state and the set up list", async ({ browser }) => {
const { page, close } = await freshPage(browser);
try {
Expand Down
3 changes: 2 additions & 1 deletion spec/plaud.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,11 @@ The web app's shell calls `POST /api/plaud/sync` while a page is open and the co
| sync on mount | on | One quiet sync when the app shell loads. Off when `syncOnMount` is `false`. |
| interval | 5 minutes | Sync at this interval. The settings offer 1, 2, 5, 10, 15 and 30 minutes. The value is never less than 1 minute. Ticks are skipped while the page is hidden. |
| enabled | on | Off when `autoSyncEnabled` is `false`. |
| sync on return | on | On `visibilitychange` to `visible`, sync quietly when `syncOnVisibilityChange` is not `false`, Plaud is enabled and connected without a reconnect requirement. At most one visibility-triggered sync per minute; events during an existing sync are skipped. This setting is independent of interval sync. |

Quiet syncs show no toast on success or failure. A sync is not started while another sync from the same page is running.

The interval and on/off are saved as user settings: `syncInterval` (milliseconds), `autoSyncEnabled`, `syncOnMount`, `syncOnVisibilityChange`, `syncNotifications`. The client does not act on `syncOnVisibilityChange`; it is stored only. Browser storage is not used for these settings.
The interval and on/off are saved as user settings: `syncInterval` (milliseconds), `autoSyncEnabled`, `syncOnMount`, `syncOnVisibilityChange`, `syncNotifications`. Browser storage is not used for these settings. The visibility listener is removed when the shell unmounts or the setting or connection no longer permits sync.

The worker skips users synced in the last 4 minutes, so a recent browser sync also keeps the worker from running for that user.

Expand Down
Loading
Loading