issueAndArchive keeps an issued invoice even when rendering or archiving fails (Issued - not archived, with a Render & archive action). The export menu offers a searchable PDF or a 300 DPI image-only PDF whose metadata is the invoice number alone; flatten failures offer Retry or searchable export and never silently lower the resolution. History re-exports the original as issued by default and warns when a re-render's layout fingerprint differs. The render client gains a FIFO assemble lane that previews cannot supersede. A Diagnostics panel runs fixtures in the real worker and compares against goldens generated from Node.
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { save } from "@tauri-apps/plugin-dialog";
|
|
import { api } from "./api";
|
|
import { flattenInBrowser } from "./browserFlatten";
|
|
import type { ExportDeps } from "./exportFlow";
|
|
import { renderInvoicePdf } from "./pdf";
|
|
import { getRenderClient, nextRenderJobId } from "./renderClient";
|
|
import type { BankAccount, Settings } from "./types";
|
|
|
|
/** The real collaborators of the export flow: Tauri commands, the render client, pdf.js and the save dialog. */
|
|
export function createExportDeps(ctx: { settings: Settings; bank: BankAccount | null }): ExportDeps {
|
|
return {
|
|
issueInvoice: (input, renderPrefs) => api.issueInvoice(input, renderPrefs),
|
|
render: async (invoice) => {
|
|
const { bytes, fingerprint } = await renderInvoicePdf(invoice, ctx.settings, ctx.bank);
|
|
return { bytes, fingerprint };
|
|
},
|
|
archivePdf: api.archivePdf,
|
|
readArchive: api.readArchive,
|
|
flatten: (bytes, opts) => flattenInBrowser(bytes, opts),
|
|
assemble: async (pages, title) => (await getRenderClient().assemble({ id: nextRenderJobId(), pages, title })).bytes,
|
|
getLastExportDir: api.getLastExportDir,
|
|
save: ({ defaultPath }) => save({ defaultPath, filters: [{ name: "PDF document", extensions: ["pdf"] }] }),
|
|
writeExportFile: api.writeExportFile,
|
|
};
|
|
}
|