fix: downloading backups in mobile webview (#1703)

This commit is contained in:
Aman Harwara
2022-09-30 21:33:30 +05:30
committed by GitHub
parent 1c530ab534
commit 5f24e7285e
10 changed files with 138 additions and 100 deletions

View File

@@ -0,0 +1,28 @@
import { WebApplication } from '@/Application/Application'
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) => {
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}..`,
})
const base64 = await getBase64FromBlob(blob)
const downloaded = await application.mobileDevice.downloadBase64AsFile(base64, filename)
if (downloaded) {
dismissToast(loadingToastId)
addToast({
type: ToastType.Success,
message: `Downloaded ${filename}`,
})
} else {
addToast({
type: ToastType.Error,
message: `Could not download ${filename}`,
})
}
}