feat: save project as (support for firefox and safari)

This commit is contained in:
Judicael 2022-08-29 16:32:19 +03:00
parent a22124b3a7
commit facd5fe4c7

View file

@ -1,4 +1,4 @@
import { fileOpen, fileSave } from 'browser-fs-access' import { fileOpen, fileSave, supported } from 'browser-fs-access'
import type { FileSystemHandle } from 'browser-fs-access' import type { FileSystemHandle } from 'browser-fs-access'
import { get as getFromIdb, set as setToIdb } from 'idb-keyval' import { get as getFromIdb, set as setToIdb } from 'idb-keyval'
import { IMAGE_EXTENSIONS, VIDEO_EXTENSIONS } from '~constants' import { IMAGE_EXTENSIONS, VIDEO_EXTENSIONS } from '~constants'
@ -48,12 +48,15 @@ export async function saveToFileSystem(
const hasPermissions = await checkPermissions(fileHandle) const hasPermissions = await checkPermissions(fileHandle)
if (!hasPermissions) return null if (!hasPermissions) return null
} }
let filename = ''
if (!supported) {
filename = prompt('Enter the desired file name!') ?? `${file.name}`
}
// Save to file system // Save to file system
const newFileHandle = await fileSave( const newFileHandle = await fileSave(
blob, blob,
{ {
fileName: `${file.name}.tldr`, fileName: `${filename}.tldr`,
description: 'Tldraw File', description: 'Tldraw File',
extensions: [`.tldr`], extensions: [`.tldr`],
}, },