Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): add timeline slider to crop modal for frame-accurate cropping

Oladipupo Ayoolaa1d2ac01d747
diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx
index a88ad1378..43b46b5a2 100644
--- a/apps/desktop/src/App.tsx
+++ b/apps/desktop/src/App.tsx
@@ -23,29 +23,55 @@ const MainPage = lazy(() => import("./routes/(window-chrome)/(main)"));
const NewMainPage = lazy(() => import("./routes/(window-chrome)/new-main"));
const SetupPage = lazy(() => import("./routes/(window-chrome)/setup"));
const SettingsLayout = lazy(() => import("./routes/(window-chrome)/settings"));
-const SettingsGeneralPage = lazy(() => import("./routes/(window-chrome)/settings/general"));
-const SettingsRecordingsPage = lazy(() => import("./routes/(window-chrome)/settings/recordings"));
-const SettingsScreenshotsPage = lazy(() => import("./routes/(window-chrome)/settings/screenshots"));
-const SettingsHotkeysPage = lazy(() => import("./routes/(window-chrome)/settings/hotkeys"));
-const SettingsChangelogPage = lazy(() => import("./routes/(window-chrome)/settings/changelog"));
-const SettingsFeedbackPage = lazy(() => import("./routes/(window-chrome)/settings/feedback"));
-const SettingsExperimentalPage = lazy(() => import("./routes/(window-chrome)/settings/experimental"));
-const SettingsLicensePage = lazy(() => import("./routes/(window-chrome)/settings/license"));
-const SettingsIntegrationsPage = lazy(() => import("./routes/(window-chrome)/settings/integrations"));
-const SettingsS3ConfigPage = lazy(() => import("./routes/(window-chrome)/settings/integrations/s3-config"));
+const SettingsGeneralPage = lazy(
+ () => import("./routes/(window-chrome)/settings/general"),
+);
+const SettingsRecordingsPage = lazy(
+ () => import("./routes/(window-chrome)/settings/recordings"),
+);
+const SettingsScreenshotsPage = lazy(
+ () => import("./routes/(window-chrome)/settings/screenshots"),
+);
+const SettingsHotkeysPage = lazy(
+ () => import("./routes/(window-chrome)/settings/hotkeys"),
+);
+const SettingsChangelogPage = lazy(
+ () => import("./routes/(window-chrome)/settings/changelog"),
+);
+const SettingsFeedbackPage = lazy(
+ () => import("./routes/(window-chrome)/settings/feedback"),
+);
+const SettingsExperimentalPage = lazy(
+ () => import("./routes/(window-chrome)/settings/experimental"),
+);
+const SettingsLicensePage = lazy(
+ () => import("./routes/(window-chrome)/settings/license"),
+);
+const SettingsIntegrationsPage = lazy(
+ () => import("./routes/(window-chrome)/settings/integrations"),
+);
+const SettingsS3ConfigPage = lazy(
+ () => import("./routes/(window-chrome)/settings/integrations/s3-config"),
+);
const UpgradePage = lazy(() => import("./routes/(window-chrome)/upgrade"));
const UpdatePage = lazy(() => import("./routes/(window-chrome)/update"));
const CameraPage = lazy(() => import("./routes/camera"));
const CaptureAreaPage = lazy(() => import("./routes/capture-area"));
const DebugPage = lazy(() => import("./routes/debug"));
const EditorPage = lazy(() => import("./routes/editor"));
-const InProgressRecordingPage = lazy(() => import("./routes/in-progress-recording"));
+const InProgressRecordingPage = lazy(
+ () => import("./routes/in-progress-recording"),
+);
const ModeSelectPage = lazy(() => import("./routes/mode-select"));
const NotificationsPage = lazy(() => import("./routes/notifications"));
const RecordingsOverlayPage = lazy(() => import("./routes/recordings-overlay"));
const ScreenshotEditorPage = lazy(() => import("./routes/screenshot-editor"));
-const TargetSelectOverlayPage = lazy(() => import("./routes/target-select-overlay"));
-const WindowCaptureOccluderPage = lazy(() => import("./routes/window-capture-occluder"));
+const TargetSelectOverlayPage = lazy(
+ () => import("./routes/target-select-overlay"),
+);
+const WindowCaptureOccluderPage = lazy(
+ () => import("./routes/window-capture-occluder"),
+);
const queryClient = new QueryClient({
defaultOptions: {
@@ -64,7 +90,18 @@ const queryClient = new QueryClient({
export default function App() {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'App.tsx:App',message:'App component rendering',data:{pathname:location.pathname},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'C'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "App.tsx:App",
+ message: "App component rendering",
+ data: { pathname: location.pathname },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "C",
+ }),
+ }).catch(() => {});
// #endregion
return (
<QueryClientProvider client={queryClient}>
@@ -77,14 +114,36 @@ export default function App() {
function Inner() {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'App.tsx:Inner',message:'Inner component rendering',data:{pathname:location.pathname},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'C'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "App.tsx:Inner",
+ message: "Inner component rendering",
+ data: { pathname: location.pathname },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "C",
+ }),
+ }).catch(() => {});
// #endregion
const currentWindow = getCurrentWebviewWindow();
createThemeListener(currentWindow);
onMount(() => {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'App.tsx:Inner:onMount',message:'Inner onMount',data:{pathname:location.pathname},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'C'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "App.tsx:Inner:onMount",
+ message: "Inner onMount",
+ data: { pathname: location.pathname },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "C",
+ }),
+ }).catch(() => {});
// #endregion
initAnonymousUser();
});
@@ -116,7 +175,27 @@ function Inner() {
onMount(() => {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'App.tsx:Router:root:onMount',message:'Router root onMount',data:{pathname:location.pathname,matchCount:matches().length,autoShowFlags:matches().map(m=>m.route.info?.AUTO_SHOW_WINDOW)},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'C,D'})}).catch(()=>{});
+ fetch(
+ "http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23",
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "App.tsx:Router:root:onMount",
+ message: "Router root onMount",
+ data: {
+ pathname: location.pathname,
+ matchCount: matches().length,
+ autoShowFlags: matches().map(
+ (m) => m.route.info?.AUTO_SHOW_WINDOW,
+ ),
+ },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "C,D",
+ }),
+ },
+ ).catch(() => {});
// #endregion
for (const match of matches()) {
if (match.route.info?.AUTO_SHOW_WINDOW === false) return;
@@ -150,10 +229,19 @@ function Inner() {
<Route path="/hotkeys" component={SettingsHotkeysPage} />
<Route path="/changelog" component={SettingsChangelogPage} />
<Route path="/feedback" component={SettingsFeedbackPage} />
- <Route path="/experimental" component={SettingsExperimentalPage} />
+ <Route
+ path="/experimental"
+ component={SettingsExperimentalPage}
+ />
<Route path="/license" component={SettingsLicensePage} />
- <Route path="/integrations" component={SettingsIntegrationsPage} />
- <Route path="/integrations/s3-config" component={SettingsS3ConfigPage} />
+ <Route
+ path="/integrations"
+ component={SettingsIntegrationsPage}
+ />
+ <Route
+ path="/integrations/s3-config"
+ component={SettingsS3ConfigPage}
+ />
</Route>
<Route path="/upgrade" component={UpgradePage} />
<Route path="/update" component={UpdatePage} />
@@ -162,13 +250,22 @@ function Inner() {
<Route path="/capture-area" component={CaptureAreaPage} />
<Route path="/debug" component={DebugPage} />
<Route path="/editor" component={EditorPage} />
- <Route path="/in-progress-recording" component={InProgressRecordingPage} />
+ <Route
+ path="/in-progress-recording"
+ component={InProgressRecordingPage}
+ />
<Route path="/mode-select" component={ModeSelectPage} />
<Route path="/notifications" component={NotificationsPage} />
<Route path="/recordings-overlay" component={RecordingsOverlayPage} />
<Route path="/screenshot-editor" component={ScreenshotEditorPage} />
- <Route path="/target-select-overlay" component={TargetSelectOverlayPage} />
- <Route path="/window-capture-occluder" component={WindowCaptureOccluderPage} />
+ <Route
+ path="/target-select-overlay"
+ component={TargetSelectOverlayPage}
+ />
+ <Route
+ path="/window-capture-occluder"
+ component={WindowCaptureOccluderPage}
+ />
</Router>
</CapErrorBoundary>
</>
diff --git a/apps/desktop/src/routes/(window-chrome).tsx b/apps/desktop/src/routes/(window-chrome).tsx
index 02ddaac32..88ad075eb 100644
--- a/apps/desktop/src/routes/(window-chrome).tsx
+++ b/apps/desktop/src/routes/(window-chrome).tsx
@@ -17,12 +17,34 @@ export default function (props: RouteSectionProps) {
let unlistenResize: UnlistenFn | undefined;
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'(window-chrome).tsx:render',message:'WindowChrome component rendering',data:{pathname:location.pathname},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'C'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "(window-chrome).tsx:render",
+ message: "WindowChrome component rendering",
+ data: { pathname: location.pathname },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "C",
+ }),
+ }).catch(() => {});
// #endregion
onMount(async () => {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'(window-chrome).tsx:onMount',message:'WindowChrome onMount',data:{pathname:location.pathname},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'C'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "(window-chrome).tsx:onMount",
+ message: "WindowChrome onMount",
+ data: { pathname: location.pathname },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "C",
+ }),
+ }).catch(() => {});
// #endregion
console.log("window chrome mounted");
unlistenResize = await initializeTitlebar();
@@ -94,11 +116,33 @@ function Header() {
function Inner(props: ParentProps) {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'(window-chrome).tsx:Inner:render',message:'Inner component rendering',data:{pathname:location.pathname},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'C'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "(window-chrome).tsx:Inner:render",
+ message: "Inner component rendering",
+ data: { pathname: location.pathname },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "C",
+ }),
+ }).catch(() => {});
// #endregion
onMount(() => {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'(window-chrome).tsx:Inner:onMount',message:'Inner onMount, about to show window',data:{pathname:location.pathname},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'B,C'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "(window-chrome).tsx:Inner:onMount",
+ message: "Inner onMount, about to show window",
+ data: { pathname: location.pathname },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "B,C",
+ }),
+ }).catch(() => {});
// #endregion
if (location.pathname !== "/") getCurrentWindow().show();
});
diff --git a/apps/desktop/src/routes/(window-chrome)/setup.tsx b/apps/desktop/src/routes/(window-chrome)/setup.tsx
index 86c05e049..5adb3ed3e 100644
--- a/apps/desktop/src/routes/(window-chrome)/setup.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/setup.tsx
@@ -95,18 +95,60 @@ export default function () {
const handleContinue = () => {
// #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'setup.tsx:handleContinue',message:'handleContinue called',data:{},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'A'})}).catch(()=>{});
+ fetch("http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "setup.tsx:handleContinue",
+ message: "handleContinue called",
+ data: {},
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "A",
+ }),
+ }).catch(() => {});
// #endregion
- commands.showWindow({ Main: { init_target_mode: null } }).then(() => {
- // #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'setup.tsx:handleContinue:then',message:'showWindow resolved, closing setup',data:{},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'A,B'})}).catch(()=>{});
- // #endregion
- getCurrentWindow().close();
- }).catch((err) => {
- // #region agent log
- fetch('http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'setup.tsx:handleContinue:catch',message:'showWindow failed',data:{error:String(err)},timestamp:Date.now(),sessionId:'debug-session',hypothesisId:'A'})}).catch(()=>{});
- // #endregion
- });
+ commands
+ .showWindow({ Main: { init_target_mode: null } })
+ .then(() => {
+ // #region agent log
+ fetch(
+ "http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23",
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "setup.tsx:handleContinue:then",
+ message: "showWindow resolved, closing setup",
+ data: {},
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "A,B",
+ }),
+ },
+ ).catch(() => {});
+ // #endregion
+ getCurrentWindow().close();
+ })
+ .catch((err) => {
+ // #region agent log
+ fetch(
+ "http://127.0.0.1:7243/ingest/1cff95e2-fcb2-4b1f-a666-2aa2ac4f0e23",
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ location: "setup.tsx:handleContinue:catch",
+ message: "showWindow failed",
+ data: { error: String(err) },
+ timestamp: Date.now(),
+ sessionId: "debug-session",
+ hypothesisId: "A",
+ }),
+ },
+ ).catch(() => {});
+ // #endregion
+ });
};
return (
diff --git a/apps/desktop/src/routes/editor/Editor.tsx b/apps/desktop/src/routes/editor/Editor.tsx
index 4f9444228..72c51af4c 100644
--- a/apps/desktop/src/routes/editor/Editor.tsx
+++ b/apps/desktop/src/routes/editor/Editor.tsx
@@ -44,7 +44,15 @@ import { ExportDialog } from "./ExportDialog";
import { Header } from "./Header";
import { PlayerContent } from "./Player";
import { Timeline } from "./Timeline";
-import { Dialog, DialogContent, EditorButton, Input, Subfield } from "./ui";
+import {
+ Dialog,
+ DialogContent,
+ EditorButton,
+ Input,
+ Slider,
+ Subfield,
+} from "./ui";
+import { formatTime } from "./utils";
const DEFAULT_TIMELINE_HEIGHT = 260;
const MIN_PLAYER_CONTENT_HEIGHT = 320;
@@ -414,13 +422,51 @@ function Dialogs() {
})()}
>
{(dialog) => {
- const { setProject: setState, editorInstance } =
- useEditorContext();
+ const {
+ setProject: setState,
+ editorInstance,
+ editorState,
+ totalDuration,
+ project,
+ } = useEditorContext();
const display = editorInstance.recordings.segments[0].display;
let cropperRef: CropperRef | undefined;
+ let videoRef: HTMLVideoElement | undefined;
const [crop, setCrop] = createSignal(CROP_ZERO);
const [aspect, setAspect] = createSignal<Ratio | null>(null);
+ const [previewTime, setPreviewTime] = createSignal(
+ editorState.playbackTime,
+ );
+ const [videoLoaded, setVideoLoaded] = createSignal(false);
+
+ const currentSegment = createMemo(() => {
+ const time = previewTime();
+ let elapsed = 0;
+ for (const seg of project.timeline?.segments ?? []) {
+ const segDuration = (seg.end - seg.start) / seg.timescale;
+ if (time < elapsed + segDuration) {
+ return {
+ index: seg.recordingSegment ?? 0,
+ localTime: seg.start + (time - elapsed) * seg.timescale,
+ };
+ }
+ elapsed += segDuration;
+ }
+ return { index: 0, localTime: 0 };
+ });
+
+ const videoSrc = createMemo(() =>
+ convertFileSrc(
+ `${editorInstance.path}/content/segments/segment-${currentSegment().index}/display.mp4`,
+ ),
+ );
+
+ createEffect(() => {
+ if (videoRef && videoLoaded()) {
+ videoRef.currentTime = currentSegment().localTime;
+ }
+ });
const initialBounds = {
x: dialog().position.x,
@@ -582,16 +628,60 @@ function Dialogs() {
allowLightMode={true}
onContextMenu={(e) => showCropOptionsMenu(e, true)}
>
- <img
- class="shadow pointer-events-none max-h-[70vh]"
- alt="screenshot"
- src={convertFileSrc(
- `${editorInstance.path}/screenshots/display.jpg`,
- )}
- />
+ <div class="relative">
+ <img
+ class="shadow pointer-events-none max-h-[70vh]"
+ alt="screenshot"
+ src={convertFileSrc(
+ `${editorInstance.path}/screenshots/display.jpg`,
+ )}
+ style={{
+ opacity: videoLoaded() ? 0 : 1,
+ transition: "opacity 150ms ease-out",
+ }}
+ />
+ <video
+ ref={videoRef}
+ src={videoSrc()}
+ class="absolute inset-0 w-full h-full object-contain shadow pointer-events-none"
+ preload="auto"
+ muted
+ onLoadedData={() => setVideoLoaded(true)}
+ onError={() => setVideoLoaded(false)}
+ style={{
+ opacity: videoLoaded() ? 1 : 0,
+ transition: "opacity 150ms ease-out",
+ }}
+ />
+ <Show when={!videoLoaded()}>
+ <div class="absolute bottom-2 right-2 flex items-center gap-1.5 bg-gray-500/80 rounded-full px-2 py-1">
+ <IconLucideLoaderCircle class="size-3 text-white animate-spin" />
+ <span class="text-[10px] text-white font-medium">
+ Loading
+ </span>
+ </div>
+ </Show>
+ </div>
</Cropper>
</div>
</div>
+ <div class="flex items-center gap-3 mt-4 px-2">
+ <span class="text-gray-11 text-sm tabular-nums min-w-[3rem]">
+ {formatTime(previewTime())}
+ </span>
+ <Slider
+ class="flex-1"
+ minValue={0}
+ maxValue={totalDuration()}
+ step={1 / FPS}
+ value={[previewTime()]}
+ onChange={([v]) => setPreviewTime(v)}
+ aria-label="Video timeline"
+ />
+ <span class="text-gray-11 text-sm tabular-nums min-w-[3rem] text-right">
+ {formatTime(totalDuration())}
+ </span>
+ </div>
</Dialog.Content>
<Dialog.Footer>
<Button
diff --git a/apps/desktop/src/routes/editor/Player.tsx b/apps/desktop/src/routes/editor/Player.tsx
index 315db42cc..f86b8b3f3 100644
--- a/apps/desktop/src/routes/editor/Player.tsx
+++ b/apps/desktop/src/routes/editor/Player.tsx
@@ -15,6 +15,7 @@ import {
serializeProjectConfiguration,
useEditorContext,
} from "./context";
+import { preloadCropVideoFull } from "./cropVideoPreloader";
import { MaskOverlay } from "./MaskOverlay";
import { TextOverlay } from "./TextOverlay";
import {
@@ -257,6 +258,8 @@ export function PlayerContent() {
<EditorButton
tooltipText="Crop Video"
onClick={cropDialogHandler}
+ onMouseEnter={preloadCropVideoFull}
+ onFocus={preloadCropVideoFull}
leftIcon={<IconCapCrop class="w-5 text-gray-12" />}
>
Crop
diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.ts
index 7ab29a7ab..bc1f622b7 100644
--- a/apps/desktop/src/routes/editor/context.ts
+++ b/apps/desktop/src/routes/editor/context.ts
@@ -39,6 +39,7 @@ import {
type TimelineConfiguration,
type XY,
} from "~/utils/tauri";
+import { preloadCropVideoMetadata } from "./cropVideoPreloader";
import type { MaskSegment } from "./masks";
import type { TextSegment } from "./text";
import { createProgressBar } from "./utils";
@@ -752,6 +753,10 @@ export const [EditorInstanceContextProvider, useEditorInstanceContext] =
const instance = await commands.createEditorInstance();
console.log("[Editor] Editor instance created, setting up WebSocket");
+ preloadCropVideoMetadata(
+ `${instance.path}/content/segments/segment-0/display.mp4`,
+ );
+
const requestFrame = () => {
events.renderFrameEvent.emit({
frame_number: 0,
diff --git a/apps/desktop/src/routes/editor/cropVideoPreloader.ts b/apps/desktop/src/routes/editor/cropVideoPreloader.ts
new file mode 100644
index 000000000..4f1ee17d0
--- /dev/null
+++ b/apps/desktop/src/routes/editor/cropVideoPreloader.ts
@@ -0,0 +1,47 @@
+import { convertFileSrc } from "@tauri-apps/api/core";
+
+let preloadedVideo: HTMLVideoElement | null = null;
+let preloadState: "idle" | "metadata" | "full" | "ready" = "idle";
+let currentVideoPath: string | null = null;
+
+export function preloadCropVideoMetadata(videoPath: string) {
+ if (preloadState !== "idle") return;
+
+ currentVideoPath = videoPath;
+ preloadedVideo = document.createElement("video");
+ preloadedVideo.preload = "metadata";
+ preloadedVideo.src = convertFileSrc(videoPath);
+ preloadedVideo.muted = true;
+ preloadedVideo.load();
+ preloadState = "metadata";
+}
+
+export function preloadCropVideoFull() {
+ if (!preloadedVideo || preloadState === "full" || preloadState === "ready")
+ return;
+
+ preloadedVideo.preload = "auto";
+ preloadedVideo.load();
+ preloadState = "full";
+
+ preloadedVideo.oncanplaythrough = () => {
+ preloadState = "ready";
+ };
+}
+
+export function getPreloadState() {
+ return preloadState;
+}
+
+export function getPreloadedVideoPath() {
+ return currentVideoPath;
+}
+
+export function cleanup() {
+ if (preloadedVideo) {
+ preloadedVideo.src = "";
+ preloadedVideo = null;
+ }
+ currentVideoPath = null;
+ preloadState = "idle";
+}
diff --git a/packages/ui-solid/src/auto-imports.d.ts b/packages/ui-solid/src/auto-imports.d.ts
index 9708f6b36..2e7c41dfb 100644
--- a/packages/ui-solid/src/auto-imports.d.ts
+++ b/packages/ui-solid/src/auto-imports.d.ts
@@ -82,6 +82,7 @@ declare global {
const IconLucideHardDrive: typeof import('~icons/lucide/hard-drive.jsx')['default']
const IconLucideImage: typeof import('~icons/lucide/image.jsx')['default']
const IconLucideLayout: typeof import('~icons/lucide/layout.jsx')['default']
+ const IconLucideLoader2: typeof import('~icons/lucide/loader2.jsx')['default']
const IconLucideLoaderCircle: typeof import('~icons/lucide/loader-circle.jsx')['default']
const IconLucideMaximize: typeof import('~icons/lucide/maximize.jsx')['default']
const IconLucideMessageSquarePlus: typeof import('~icons/lucide/message-square-plus.jsx')['default']