| 1 | import { app } from "./bridge"; |
| 2 | export type ExportProgress = { exportId: string; title: string; phase: string; records: number; pages: number }; |
| 3 | let current: readonly ExportProgress[] = []; |
| 4 | const listeners = new Set<() => void>(); |
| 5 | export const cancelled = new Set<string>(); |
| 6 | export function publish(progress: ExportProgress) { |
| 7 | current = [...current.filter(item => item.exportId !== progress.exportId), progress]; |
| 8 | listeners.forEach(fn => fn()); |
| 9 | } |
| 10 | export function remove(id: string) { current = current.filter(item => item.exportId !== id); listeners.forEach(fn => fn()); } |
| 11 | export const sessionExportProgress = { getSnapshot: () => current, subscribe: (fn: () => void) => { listeners.add(fn); return () => { listeners.delete(fn); }; } }; |
| 12 | export async function cancelSessionExport(id: string) { cancelled.add(id); remove(id); await app.CancelSessionExport(id); } |
| 13 |