From 990b364ae1f2643f51b97f46ef09aebba42274d3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 21 Aug 2019 17:10:44 -0400 Subject: [PATCH] restore downloader script --- src/downloader/downloader.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/downloader/downloader.ts b/src/downloader/downloader.ts index 4c7473764e..ab02de7e03 100644 --- a/src/downloader/downloader.ts +++ b/src/downloader/downloader.ts @@ -1,3 +1,34 @@ document.addEventListener('DOMContentLoaded', () => { - // TODO + const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 && + navigator.userAgent.indexOf('Chrome') === -1; + + if (!isSafari) { + return; + } + + safari.self.addEventListener('message', (msgEvent: any) => { + // tslint:disable-next-line + console.log('GOT MESSAGE'); + // tslint:disable-next-line + console.log(msgEvent); + doDownload(JSON.parse(msgEvent.message.msg)); + }, false); + + function doDownload(msg: any) { + if (msg.command === 'downloaderPageData' && msg.data) { + const blob = new Blob([msg.data.blobData], msg.data.blobOptions); + if (navigator.msSaveOrOpenBlob) { + navigator.msSaveBlob(blob, msg.data.fileName); + } else { + const a = document.createElement('a'); + a.href = URL.createObjectURL(blob); + a.download = msg.data.fileName; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + } + } + + window.setTimeout(() => window.close(), 1500); + } });