refactor(web): dependency management (#2386)
This commit is contained in:
@@ -1,19 +1,15 @@
|
||||
import { WebApplication } from '@/Application/WebApplication'
|
||||
import { getBase64FromBlob } from '@/Utils'
|
||||
import { parseFileName } from '@standardnotes/filepicker'
|
||||
import { Platform } from '@standardnotes/snjs'
|
||||
import { MobileDeviceInterface } from '@standardnotes/snjs'
|
||||
import { addToast, ToastType, dismissToast } from '@standardnotes/toast'
|
||||
import { sanitizeFileName } from '@standardnotes/ui-services'
|
||||
|
||||
export const downloadBlobOnAndroid = async (
|
||||
application: WebApplication,
|
||||
mobileDevice: MobileDeviceInterface,
|
||||
blob: Blob,
|
||||
filename: string,
|
||||
showToast = true,
|
||||
) => {
|
||||
if (!application.isNativeMobileWeb() || application.platform !== Platform.Android) {
|
||||
throw new Error('Download function being used on non-android platform')
|
||||
}
|
||||
let loadingToastId: string | undefined
|
||||
if (showToast) {
|
||||
loadingToastId = addToast({
|
||||
@@ -25,7 +21,7 @@ export const downloadBlobOnAndroid = async (
|
||||
const { name, ext } = parseFileName(filename)
|
||||
const sanitizedName = sanitizeFileName(name)
|
||||
filename = `${sanitizedName}.${ext}`
|
||||
const downloaded = await application.mobileDevice().downloadBase64AsFile(base64, filename)
|
||||
const downloaded = await mobileDevice.downloadBase64AsFile(base64, filename)
|
||||
if (loadingToastId) {
|
||||
dismissToast(loadingToastId)
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ export const downloadSelectedNotesOnAndroid = async (application: WebApplication
|
||||
const blob = getNoteBlob(application, note)
|
||||
const { name, ext } = parseFileName(getNoteFileName(application, note))
|
||||
const filename = `${sanitizeFileName(name)}.${ext}`
|
||||
await downloadBlobOnAndroid(application, blob, filename)
|
||||
await downloadBlobOnAndroid(application.mobileDevice, blob, filename)
|
||||
return
|
||||
}
|
||||
if (notes.length > 1) {
|
||||
const zippedDataBlob = await application.getArchiveService().zipData(
|
||||
const zippedDataBlob = await application.archiveService.zipData(
|
||||
notes.map((note) => {
|
||||
return {
|
||||
name: getNoteFileName(application, note),
|
||||
@@ -26,7 +26,7 @@ export const downloadSelectedNotesOnAndroid = async (application: WebApplication
|
||||
}
|
||||
}),
|
||||
)
|
||||
const filename = `Standard Notes Export - ${application.getArchiveService().formattedDateForExports()}.zip`
|
||||
await downloadBlobOnAndroid(application, zippedDataBlob, filename)
|
||||
const filename = `Standard Notes Export - ${application.archiveService.formattedDateForExports()}.zip`
|
||||
await downloadBlobOnAndroid(application.mobileDevice, zippedDataBlob, filename)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { WebApplication } from '@/Application/WebApplication'
|
||||
import { getBase64FromBlob } from '@/Utils'
|
||||
import { MobileDeviceInterface } from '@standardnotes/snjs'
|
||||
|
||||
export const shareBlobOnMobile = async (application: WebApplication, blob: Blob, filename: string) => {
|
||||
if (!application.isNativeMobileWeb()) {
|
||||
export const shareBlobOnMobile = async (
|
||||
mobileDevice: MobileDeviceInterface,
|
||||
isNativeMobileWeb: boolean,
|
||||
blob: Blob,
|
||||
filename: string,
|
||||
) => {
|
||||
if (!isNativeMobileWeb) {
|
||||
throw new Error('Share function being used outside mobile webview')
|
||||
}
|
||||
const base64 = await getBase64FromBlob(blob)
|
||||
void application.mobileDevice().shareBase64AsFile(base64, filename)
|
||||
void mobileDevice.shareBase64AsFile(base64, filename)
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ export const shareSelectedNotes = async (application: WebApplication, notes: SNN
|
||||
const blob = getNoteBlob(application, note)
|
||||
const { name, ext } = parseFileName(getNoteFileName(application, note))
|
||||
const filename = `${sanitizeFileName(name)}.${ext}`
|
||||
void shareBlobOnMobile(application, blob, filename)
|
||||
void shareBlobOnMobile(application.mobileDevice, application.isNativeMobileWeb(), blob, filename)
|
||||
return
|
||||
}
|
||||
if (notes.length > 1) {
|
||||
const zippedDataBlob = await application.getArchiveService().zipData(
|
||||
const zippedDataBlob = await application.archiveService.zipData(
|
||||
notes.map((note) => {
|
||||
return {
|
||||
name: getNoteFileName(application, note),
|
||||
@@ -27,9 +27,10 @@ export const shareSelectedNotes = async (application: WebApplication, notes: SNN
|
||||
}),
|
||||
)
|
||||
void shareBlobOnMobile(
|
||||
application,
|
||||
application.mobileDevice,
|
||||
application.isNativeMobileWeb(),
|
||||
zippedDataBlob,
|
||||
`Standard Notes Export - ${application.getArchiveService().formattedDateForExports()}.zip`,
|
||||
`Standard Notes Export - ${application.archiveService.formattedDateForExports()}.zip`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ const AndroidBackHandlerProvider = ({ application, children }: ProviderProps) =>
|
||||
application.setAndroidBackHandlerFallbackListener(() => {
|
||||
const shouldConfirm = (application.getValue(AndroidConfirmBeforeExitKey) as boolean) ?? true
|
||||
|
||||
application.mobileDevice().exitApp(shouldConfirm)
|
||||
application.mobileDevice.exitApp(shouldConfirm)
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user