Ver Fonte

Null file handle doesn’t need to be passed (#1752)

* Bump browser-nativefs version to v0.2.0

In reply to https://github.com/tomayac/browser-nativefs/issues/2.

* Update package-lock.json

* Null file handle doesn’t need to be passed
Thomas Steiner há 4 anos atrás
pai
commit
3cee0768cc
1 ficheiros alterados com 10 adições e 19 exclusões
  1. 10 19
      src/data/json.ts

+ 10 - 19
src/data/json.ts

@@ -30,25 +30,16 @@ export const saveAsJSON = async (
   const blob = new Blob([serialized], {
     type: "application/json",
   });
-  // Either "Save as" or non-supporting browser
-  if (!fileHandle) {
-    const name = `${appState.name}.excalidraw`;
-    const handle = await fileSave(
-      blob,
-      {
-        fileName: name,
-        description: "Excalidraw file",
-        extensions: ["excalidraw"],
-      },
-      fileHandle,
-    );
-    (window as any).handle = handle;
-    return;
-  }
-  // "Save"
-  const writable = await fileHandle.createWritable();
-  await writable.write(blob);
-  await writable.close();
+  const name = `${appState.name}.excalidraw`;
+  (window as any).handle = await fileSave(
+    blob,
+    {
+      fileName: name,
+      description: "Excalidraw file",
+      extensions: ["excalidraw"],
+    },
+    fileHandle || null,
+  );
 };
 
 export const loadFromJSON = async () => {