fix: abstract and fix legacy fs (#4032)

This commit is contained in:
David Luzar 2021-10-07 13:19:40 +02:00 committed by GitHub
parent 75aeaa6c38
commit 54739cd2df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 179 additions and 50 deletions

View file

@ -1,4 +1,3 @@
import { fileSave, FileSystemHandle } from "browser-fs-access";
import {
copyBlobToClipboardAsPng,
copyTextToSystemClipboard,
@ -10,6 +9,7 @@ import { exportToCanvas, exportToSvg } from "../scene/export";
import { ExportType } from "../scene/types";
import { AppState } from "../types";
import { canvasToBlob } from "./blob";
import { fileSave, FileSystemHandle } from "./filesystem";
import { serializeAsJSON } from "./json";
export { loadFromBlob } from "./blob";
@ -49,10 +49,10 @@ export const exportCanvas = async (
return await fileSave(
new Blob([tempSvg.outerHTML], { type: "image/svg+xml" }),
{
fileName: `${name}.svg`,
extensions: [".svg"],
name,
extension: "svg",
fileHandle,
},
fileHandle,
);
} else if (type === "clipboard-svg") {
await copyTextToSystemClipboard(tempSvg.outerHTML);
@ -71,7 +71,6 @@ export const exportCanvas = async (
tempCanvas.remove();
if (type === "png") {
const fileName = `${name}.png`;
if (appState.exportEmbedScene) {
blob = await (
await import(/* webpackChunkName: "image" */ "./image")
@ -81,14 +80,11 @@ export const exportCanvas = async (
});
}
return await fileSave(
blob,
{
fileName,
extensions: [".png"],
},
return await fileSave(blob, {
name,
extension: "png",
fileHandle,
);
});
} else if (type === "clipboard") {
try {
await copyBlobToClipboardAsPng(blob);