From aedf2e2ee4243ab5e5cad56319cf35e066389480 Mon Sep 17 00:00:00 2001 From: Louis Beaumont Date: Tue, 17 Sep 2024 18:19:38 -0700 Subject: [PATCH] fix: windows slashes video render #319 --- screenpipe-app-tauri/components/video.tsx | 33 ++++++++--------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/screenpipe-app-tauri/components/video.tsx b/screenpipe-app-tauri/components/video.tsx index bdfac0ea..8816c609 100644 --- a/screenpipe-app-tauri/components/video.tsx +++ b/screenpipe-app-tauri/components/video.tsx @@ -1,5 +1,6 @@ import { memo, useCallback, useEffect, useState } from "react"; import { readFile, open } from "@tauri-apps/plugin-fs"; +import { platform } from "@tauri-apps/plugin-os"; export const VideoComponent = memo(function VideoComponent({ filePath, @@ -11,30 +12,18 @@ export const VideoComponent = memo(function VideoComponent({ const [isAudio, setIsAudio] = useState(false); const sanitizeFilePath = useCallback((path: string): string => { - return path - .replace(/^["']|["']$/g, "") - .trim() - .replace(/\\/g, "/"); + const isWindows = platform() === "windows"; + return ( + path + .replace(/^["']|["']$/g, "") + .trim() + // only replace forward slashes with backslashes on Windows + .replace(/\//g, isWindows ? "\\" : "/") + ); }, []); - const openFileLocation = useCallback(async () => { - try { - await open(sanitizeFilePath(filePath)); - } catch (error) { - console.error("Failed to open file location:", error); - } - }, [filePath, sanitizeFilePath]); const renderFileLink = () => ( - // - // just a link + // TODO button open link

{filePath}

); @@ -60,7 +49,7 @@ export const VideoComponent = memo(function VideoComponent({ async function loadMedia() { try { console.log("Loading media:", filePath); - const sanitizedPath = sanitizeFilePath(filePath); + const sanitizedPath = await sanitizeFilePath(filePath); console.log("Sanitized path:", sanitizedPath); if (!sanitizedPath) { throw new Error("Invalid file path");