Manav Rathi пре 1 година
родитељ
комит
0c4da8c86a
1 измењених фајлова са 19 додато и 1 уклоњено
  1. 19 1
      desktop/src/preload.ts

+ 19 - 1
desktop/src/preload.ts

@@ -217,7 +217,25 @@ const watchReset = async () => {
 
 // - Upload
 
-const pathForFile = (file: File) => webUtils.getPathForFile(file);
+const pathForFile = (file: File) => {
+    const path = webUtils.getPathForFile(file);
+    // The path that we get back from `webUtils.getPathForFile` on Windows uses
+    // "/" as the path separator. Convert them to POSIX separators.
+    //
+    // Note that we do not have access to the path or the os module in the
+    // preload script, thus this hand rolled transformation.
+
+    // However that makes TypeScript fidgety since we it cannot find navigator,
+    // as we haven't included "lib": ["dom"] in our tsconfig to avoid making DOM
+    // APIs available to our main Node.js code. We could create a separate
+    // tsconfig just for the preload script, but for now let's go with a cast.
+    //
+    // @ts-expect-error navigator is not defined.
+    const platform = (navigator as { platform: string }).platform;
+    return platform.toLowerCase().includes("win")
+        ? path.split("\\").join("/")
+        : path;
+};
 
 const listZipItems = (zipPath: string) =>
     ipcRenderer.invoke("listZipItems", zipPath);