feat(export): run data dictionary PDF exports in background

This commit is contained in:
ccq authored and GitHub committed 2026-09-26 00:04:52 +08:00
1 parent 4baec21fb7
commit 705ea7464d
18 files changed
+702 -104

No files matched your search

@@ -7,18 +7,21 @@ export class DictionaryFileExistsError extends Error {
}
}
export async function chooseDataDictionaryPath(suggestedName: string): Promise<string | null> {
if (!isTauriRuntime()) return suggestedName;
const { save } = await import("@tauri-apps/plugin-dialog");
return save({ defaultPath: suggestedName, filters: [{ name: "PDF", extensions: ["pdf"] }] });
}
/**
* Suggested name is only the save dialog's defaultPath. The write uses the path
* `save()` just returned. Tauri's dialog grant covers that exact path, not a
* typed path or a timestamp appended after the dialog closes.
*/
export async function saveDataDictionaryFile(suggestedName: string, content: Uint8Array, options: { overwrite: boolean }): Promise<string | null> {
export async function saveDataDictionaryFile(suggestedName: string, content: Uint8Array, options: { overwrite: boolean; grantedPath?: string }): Promise<string | null> {
if (isTauriRuntime()) {
const [{ save }, fs] = await Promise.all([import("@tauri-apps/plugin-dialog"), import("@tauri-apps/plugin-fs")]);
const granted = await save({
defaultPath: suggestedName,
filters: [{ name: "PDF", extensions: ["pdf"] }],
});
const fs = await import("@tauri-apps/plugin-fs");
const granted = options.grantedPath ?? (await chooseDataDictionaryPath(suggestedName));
if (!granted) return null;
if (!options.overwrite && (await fs.exists(granted))) throw new DictionaryFileExistsError();
await fs.writeFile(granted, content);