From dd2aae12dd15b6d832fd96db19e2e0550c4f9e91 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 21 Aug 2019 10:29:14 -0400 Subject: [PATCH] send download file message to safari app --- src/browser/browserApi.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index 509115ed04..08f20f9c31 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -1,5 +1,7 @@ import { SafariApp } from './safariApp'; +import { Utils } from 'jslib/misc/utils'; + export class BrowserApi { static isWebExtensionsApi: boolean = (typeof browser !== 'undefined'); static isSafariApi: boolean = (window as any).safariAppExtension === true; @@ -178,7 +180,18 @@ export class BrowserApi { static downloadFile(win: Window, blobData: any, blobOptions: any, fileName: string) { if (BrowserApi.isSafariApi) { - // TODO + const type = blobOptions != null ? blobOptions.type : null; + let data: string = null; + if (type === 'text/plain' && typeof (blobData) === 'string') { + data = blobData; + } else { + data = Utils.fromBufferToB64(blobData); + } + SafariApp.sendMessageToApp('downloadFile', { + data: data, + type: type, + fileName: fileName, + }, true); } else { const blob = new Blob([blobData], blobOptions); if (navigator.msSaveOrOpenBlob) {