( projectPath: string, settings: ExportSettings, onProgress: (progress: FramesRendered) => void, )
| 14 | } |
| 15 | |
| 16 | export function createExportTask( |
| 17 | projectPath: string, |
| 18 | settings: ExportSettings, |
| 19 | onProgress: (progress: FramesRendered) => void, |
| 20 | ) { |
| 21 | const progress = new Channel<FramesRendered>((e) => { |
| 22 | onProgress(e); |
| 23 | }); |
| 24 | let closed = false; |
| 25 | const closeProgress = () => { |
| 26 | if (closed) return; |
| 27 | closed = true; |
| 28 | const internals = ( |
| 29 | globalThis as { |
| 30 | __TAURI_INTERNALS__?: { unregisterCallback?: (id: number) => void }; |
| 31 | } |
| 32 | ).__TAURI_INTERNALS__; |
| 33 | internals?.unregisterCallback?.(progress.id); |
| 34 | }; |
| 35 | const cancel = () => { |
| 36 | if (closed) return; |
| 37 | void cancelCurrentWindowExports(); |
| 38 | closeProgress(); |
| 39 | }; |
| 40 | const promise = commands |
| 41 | .exportVideo(projectPath, progress, settings) |
| 42 | .finally(closeProgress); |
| 43 | return { promise, cancel }; |
| 44 | } |
| 45 | |
| 46 | async function cancelCurrentWindowExports() { |
| 47 | await commands.cancelCurrentWindowExports().catch((error) => { |
no test coverage detected