diff --git a/src/main/index.ts b/src/main/index.ts index 1b3e612..8bb9e15 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -117,7 +117,9 @@ function notifyChange() { async function openBookAt(p: string): Promise { try { const meta = loadBook(p); - addRecent({ path: p, title: meta.title, lastOpened: new Date().toISOString() }); + 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); - addRecent({ path: p, title: meta.title, lastOpened: new Date().toISOString() }); + 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(); diff --git a/src/main/recents.ts b/src/main/recents.ts index fef6914..bebbfef 100644 --- a/src/main/recents.ts +++ b/src/main/recents.ts @@ -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[] {