POSIX paths

This commit is contained in:
Manav Rathi 2024-05-02 21:38:02 +05:30
parent 6a99002064
commit 0c4da8c86a
No known key found for this signature in database

View file

@ -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);