Stop e2e runs polluting recent books and prune recents that no longer exist
This commit is contained in:
parent
17a895dffe
commit
2545dede0b
2 changed files with 17 additions and 4 deletions
|
|
@ -117,7 +117,9 @@ function notifyChange() {
|
|||
async function openBookAt(p: string): Promise<BookResult | ErrResult> {
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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[] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue