This commit is contained in:
pj committed 2026-06-20 23:46:10 -04:00
1 parent c86d5a7d5c
commit 0e0d334f6a
33 files changed
+401 -101

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import type { Book } from "../model/book";
import { exportEpub, exportPdf } from "./exporters";
import { useBook } from "../store/useBook";
import { isDesktop } from "../ipc";
const DESKTOP_ONLY =
'Export runs in the desktop app only — open the window from "pnpm tauri dev" (you are viewing the browser preview).';
const FORMATS: Record<string, { label: string; run: (book: Book) => Promise<void> }> = {
pdf: { label: "PDF", run: exportPdf },
epub: { label: "EPUB", run: exportEpub },
};
function nextPaint(): Promise<void> {
return new Promise((resolve) =>
requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
);
}
export async function runExport(format: "pdf" | "epub"): Promise<void> {
const { book, setExporting, setNotice } = useBook.getState();
const { label, run } = FORMATS[format];
if (!isDesktop) {
setNotice(DESKTOP_ONLY);
return;
}
if (!book) return;
setExporting(label);
await nextPaint();
try {
await run(book);
} catch (e) {
setNotice(`${label} export failed: ${e}`);
} finally {
setExporting(null);
}
}