Fix Windows cursor telemetry path resolution

This commit is contained in:
Etienne Lescot
2026-03-14 11:22:45 +01:00
parent 5e8bb99e96
commit e72fb8252c
2 changed files with 20 additions and 7 deletions
+5 -3
View File
@@ -419,7 +419,9 @@ export default function VideoEditor() {
let mounted = true;
async function loadCursorTelemetry() {
if (!videoPath) {
const sourcePath = videoSourcePath ?? (videoPath ? fromFileUrl(videoPath) : null);
if (!sourcePath) {
if (mounted) {
setCursorTelemetry([]);
}
@@ -427,7 +429,7 @@ export default function VideoEditor() {
}
try {
const result = await window.electronAPI.getCursorTelemetry(fromFileUrl(videoPath));
const result = await window.electronAPI.getCursorTelemetry(sourcePath);
if (mounted) {
setCursorTelemetry(result.success ? result.samples : []);
}
@@ -444,7 +446,7 @@ export default function VideoEditor() {
return () => {
mounted = false;
};
}, [videoPath]);
}, [videoPath, videoSourcePath]);
function togglePlayPause() {
const playback = videoPlaybackRef.current;
@@ -61,9 +61,9 @@ function clamp(value: number, min: number, max: number) {
export function toFileUrl(filePath: string): string {
const normalized = filePath.replace(/\\/g, "/");
if (normalized.match(/^[a-zA-Z]:/)) {
return `file:///${normalized}`;
return `file:///${encodeURI(normalized)}`;
}
return `file://${normalized}`;
return `file://${encodeURI(normalized)}`;
}
export function fromFileUrl(fileUrl: string): string {
@@ -73,9 +73,20 @@ export function fromFileUrl(fileUrl: string): string {
try {
const url = new URL(fileUrl);
return decodeURIComponent(url.pathname);
const pathname = decodeURIComponent(url.pathname);
if (url.host && url.host !== "localhost") {
return `//${url.host}${pathname}`;
}
if (/^\/[a-zA-Z]:/.test(pathname)) {
return pathname.slice(1);
}
return pathname;
} catch {
return fileUrl.replace(/^file:\/\//, "");
const fallbackPath = decodeURIComponent(fileUrl.replace(/^file:\/\//, ""));
return fallbackPath.replace(/^\/([a-zA-Z]:)/, "$1");
}
}