Skip to content

Commit e5fa783

Browse files
Merge pull request #205 from EtienneLescot/fix/issue-197-windows-paths
Fix Windows cursor telemetry path resolution
2 parents 5e8bb99 + e72fb82 commit e5fa783

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/components/video-editor/VideoEditor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,17 @@ export default function VideoEditor() {
419419
let mounted = true;
420420

421421
async function loadCursorTelemetry() {
422-
if (!videoPath) {
422+
const sourcePath = videoSourcePath ?? (videoPath ? fromFileUrl(videoPath) : null);
423+
424+
if (!sourcePath) {
423425
if (mounted) {
424426
setCursorTelemetry([]);
425427
}
426428
return;
427429
}
428430

429431
try {
430-
const result = await window.electronAPI.getCursorTelemetry(fromFileUrl(videoPath));
432+
const result = await window.electronAPI.getCursorTelemetry(sourcePath);
431433
if (mounted) {
432434
setCursorTelemetry(result.success ? result.samples : []);
433435
}
@@ -444,7 +446,7 @@ export default function VideoEditor() {
444446
return () => {
445447
mounted = false;
446448
};
447-
}, [videoPath]);
449+
}, [videoPath, videoSourcePath]);
448450

449451
function togglePlayPause() {
450452
const playback = videoPlaybackRef.current;

src/components/video-editor/projectPersistence.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ function clamp(value: number, min: number, max: number) {
6161
export function toFileUrl(filePath: string): string {
6262
const normalized = filePath.replace(/\\/g, "/");
6363
if (normalized.match(/^[a-zA-Z]:/)) {
64-
return `file:///${normalized}`;
64+
return `file:///${encodeURI(normalized)}`;
6565
}
66-
return `file://${normalized}`;
66+
return `file://${encodeURI(normalized)}`;
6767
}
6868

6969
export function fromFileUrl(fileUrl: string): string {
@@ -73,9 +73,20 @@ export function fromFileUrl(fileUrl: string): string {
7373

7474
try {
7575
const url = new URL(fileUrl);
76-
return decodeURIComponent(url.pathname);
76+
const pathname = decodeURIComponent(url.pathname);
77+
78+
if (url.host && url.host !== "localhost") {
79+
return `//${url.host}${pathname}`;
80+
}
81+
82+
if (/^\/[a-zA-Z]:/.test(pathname)) {
83+
return pathname.slice(1);
84+
}
85+
86+
return pathname;
7787
} catch {
78-
return fileUrl.replace(/^file:\/\//, "");
88+
const fallbackPath = decodeURIComponent(fileUrl.replace(/^file:\/\//, ""));
89+
return fallbackPath.replace(/^\/([a-zA-Z]:)/, "$1");
7990
}
8091
}
8192

0 commit comments

Comments
 (0)