Manav Rathi há 1 ano atrás
pai
commit
c76b2f0794
1 ficheiros alterados com 21 adições e 0 exclusões
  1. 21 0
      web/apps/photos/src/utils/native-stream.ts

+ 21 - 0
web/apps/photos/src/utils/native-stream.ts

@@ -166,3 +166,24 @@ export const readConvertToMP4Stream = async (
 
     return res.blob();
 };
+
+/**
+ * Sibling of {@link readConvertToMP4Stream} to let the native side know when we
+ * are done reading the response, and they can dispose any temporary resources
+ * it was using.
+ *
+ * @param token A token obtained from {@link writeConvertToMP4Stream}.
+ */
+export const readConvertToMP4Done = async (
+    _: Electron,
+    token: string,
+): Promise<void> => {
+    // The value for `done` is arbitrary, only its presence matters.
+    const params = new URLSearchParams({ token, done: "1" });
+    const url = new URL(`stream://convert-to-mp4?${params.toString()}`);
+
+    const req = new Request(url, { method: "GET" });
+    const res = await fetch(req);
+    if (!res.ok)
+        throw new Error(`Failed to close stream at ${url}: HTTP ${res.status}`);
+};