Stop e2e runs polluting recent books and prune recents that no longer exist

This commit is contained in:
avi 2026-08-17 11:15:16 -05:00
commit 2545dede0b
2 changed files with 17 additions and 4 deletions

View file

@ -117,7 +117,9 @@ function notifyChange() {
async function openBookAt(p: string): Promise<BookResult | ErrResult> {
try {
const meta = loadBook(p);
if (process.env.FOLIO_SELF_TEST !== "1") {
addRecent({ path: p, title: meta.title, lastOpened: new Date().toISOString() });
}
bookPath = p;
mainWindow?.setTitle(`${meta.title} — Folio`);
refreshMenu();
@ -138,7 +140,9 @@ ipcMain.handle("folio:newBook", async () => {
if (hasBook(p)) return { error: "A Folio book already exists at this location." };
const title = path.basename(p) || "Untitled";
const meta = createBook(p, title);
if (process.env.FOLIO_SELF_TEST !== "1") {
addRecent({ path: p, title: meta.title, lastOpened: new Date().toISOString() });
}
bookPath = p;
mainWindow?.setTitle(`${meta.title} — Folio`);
refreshMenu();

View file

@ -1,6 +1,11 @@
import path from "path";
import { app } from "electron";
import { APP_ID, listRecents as _listRecents, addRecent as _addRecent } from "./project.js";
import {
APP_ID,
hasBook,
listRecents as _listRecents,
addRecent as _addRecent,
} from "./project.js";
import type { Recent } from "./project.js";
export type { Recent };
@ -10,7 +15,11 @@ export function recentsFilePath(): string {
}
export function listRecents(): Recent[] {
return _listRecents(recentsFilePath());
// Drop entries whose book no longer exists (e.g. e2e temp books).
const recents = _listRecents(recentsFilePath());
return recents.filter(
(r) => r && typeof r.path === "string" && hasBook(r.path)
);
}
export function addRecent(recent: Recent): Recent[] {