diff options
Diffstat (limited to 'client-web/source/sw/download_stream.ts')
-rw-r--r-- | client-web/source/sw/download_stream.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/client-web/source/sw/download_stream.ts b/client-web/source/sw/download_stream.ts index 1a2fec8..0ba6289 100644 --- a/client-web/source/sw/download_stream.ts +++ b/client-web/source/sw/download_stream.ts @@ -26,7 +26,12 @@ function FallbackStreamDownload(size: number, filename?: string, progress?: (pos } } -export function StreamDownload(size: number, filename?: string, progress?: (position: number) => void) { +export function StreamDownload({ size, filename, cancel, progress }: { + size: number, + filename: string, + cancel: () => void, + progress: (position: number) => void +}) { if (!SW) FallbackStreamDownload(size, filename, progress) let position = 0 @@ -41,6 +46,13 @@ export function StreamDownload(size: number, filename?: string, progress?: (posi a.target = "_blank" a.click() + port1.onmessage = ev => { + if (ev.data.abort) { + cancel() + port1.close() + } + } + return { close() { port1.postMessage("end") |