fix: files download in mobile webview (#1726)
This commit is contained in:
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user