fix: files download in mobile webview (#1726)

This commit is contained in:
Aman Harwara
2022-09-30 22:31:49 +05:30
committed by GitHub
parent 86a0b61612
commit b15d80eb29
3 changed files with 31 additions and 9 deletions

View File

@@ -3,18 +3,31 @@ import { getBase64FromBlob } from '@/Utils'
import { Platform } from '@standardnotes/snjs'
import { addToast, ToastType, dismissToast } from '@standardnotes/toast'
export const downloadBlobOnAndroid = async (application: WebApplication, blob: Blob, filename: string) => {
export const downloadBlobOnAndroid = async (
application: WebApplication,
blob: Blob,
filename: string,
showToast = true,
) => {
if (!application.isNativeMobileWeb() || application.platform !== Platform.Android) {
throw new Error('Download function being used on non-android platform')
}
const loadingToastId = addToast({
type: ToastType.Loading,
message: `Downloading ${filename}..`,
})
let loadingToastId: string | undefined
if (showToast) {
loadingToastId = addToast({
type: ToastType.Loading,
message: `Downloading ${filename}..`,
})
}
const base64 = await getBase64FromBlob(blob)
const downloaded = await application.mobileDevice.downloadBase64AsFile(base64, filename)
if (downloaded) {
if (loadingToastId) {
dismissToast(loadingToastId)
}
if (!showToast) {
return
}
if (downloaded) {
addToast({
type: ToastType.Success,
message: `Downloaded ${filename}`,