fix: Fix downloads silently failing on Android

This commit is contained in:
Aman Harwara
2025-01-31 22:48:39 +05:30
parent 27aa7139cb
commit 42aedcdf84
2 changed files with 35 additions and 15 deletions

View File

@@ -21,17 +21,30 @@ export class StreamingFileSaver {
return window.showSaveFilePicker != undefined
}
/** This function must be called in response to a user interaction, otherwise, it will be rejected by the browser. */
async selectFileToSaveTo(handle?: FileSystemFileHandle): Promise<void> {
/**
* This function must be called in response to a user interaction, otherwise, it will be rejected by the browser.
* @returns Whether file was successfully selected or not.
*/
async selectFileToSaveTo(handle?: FileSystemFileHandle): Promise<boolean> {
this.log('Showing save file picker')
const downloadHandle = handle
? handle
: await window.showSaveFilePicker({
suggestedName: this.name,
})
try {
const downloadHandle = handle
? handle
: await window.showSaveFilePicker({
suggestedName: this.name,
})
this.writableStream = await downloadHandle.createWritable()
if (!downloadHandle) {
return false
}
this.writableStream = await downloadHandle.createWritable()
return true
} catch {
return false
}
}
async pushBytes(bytes: Uint8Array): Promise<void> {