Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
Merge remote-tracking branch 'origin/main' into feature/undo-redo
FabLrc2ccead5fb93b
diff --cc src/components/video-editor/VideoEditor.tsxindex 49ac39862,769e88e24..dee59d37a--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@@ -10,6 -10,15 +10,14 @@@ import PlaybackControls from "./Playbacimport TimelineEditor from "./timeline/TimelineEditor";import { SettingsPanel } from "./SettingsPanel";import { ExportDialog } from "./ExportDialog";+ import {- WALLPAPER_PATHS,+ createProjectData,+ deriveNextId,+ fromFileUrl,+ normalizeProjectEditor,+ toFileUrl,+ validateProjectData,+ } from "./projectPersistence";import type { Span } from "dnd-timeline";import {@@@ -31,27 -42,15 +39,25 @@@type PlaybackSpeed,} from "./types";import { VideoExporter, GifExporter, type ExportProgress, type ExportQuality, type ExportSettings, type ExportFormat, type GifFrameRate, type GifSizePreset, GIF_SIZE_PRESETS, calculateOutputDimensions } from "@/lib/exporter";-import { type AspectRatio, getAspectRatioValue } from "@/utils/aspectRatioUtils";-import { getAssetPath } from "@/lib/assetPath";+import { getAspectRatioValue } from "@/utils/aspectRatioUtils";- import { getAssetPath } from "@/lib/assetPath";+import { useEditorHistory, INITIAL_EDITOR_STATE } from "@/hooks/useEditorHistory";import { useShortcuts } from "@/contexts/ShortcutsContext";import { matchesShortcut } from "@/lib/shortcuts";- const WALLPAPER_COUNT = 18;- const WALLPAPER_PATHS = Array.from({ length: WALLPAPER_COUNT }, (_, i) => `/wallpapers/wallpaper${i + 1}.jpg`);-export default function VideoEditor() {+ const { state: editorState, pushState, updateState, commitState, undo, redo } =+ useEditorHistory(INITIAL_EDITOR_STATE);++ const {+ zoomRegions, trimRegions, speedRegions, annotationRegions,+ cropRegion, wallpaper, shadowIntensity, showBlur,+ motionBlurEnabled, borderRadius, padding, aspectRatio,+ } = editorState;++ // ── Non-undoable stateconst [videoPath, setVideoPath] = useState<string | null>(null);+ const [videoSourcePath, setVideoSourcePath] = useState<string | null>(null);+ const [currentProjectPath, setCurrentProjectPath] = useState<string | null>(null);const [loading, setLoading] = useState(true);const [error, setError] = useState<string | null>(null);const [isPlaying, setIsPlaying] = useState(false);@@@ -79,40 -91,149 +86,151 @@@const { shortcuts, isMac } = useShortcuts();const nextAnnotationIdRef = useRef(1);- const nextAnnotationZIndexRef = useRef(1); // Track z-index for stacking order+ const nextAnnotationZIndexRef = useRef(1);const exporterRef = useRef<VideoExporter | null>(null);- const toFileUrl = (filePath: string): string => {- const normalized = filePath.replace(/\\/g, '/');- return normalized.match(/^[a-zA-Z]:/) ? `file:///${normalized}` : `file://${normalized}`;- };-- const fromFileUrl = (fileUrl: string): string => {- if (!fileUrl.startsWith('file://')) {- return fileUrl;+ const applyLoadedProject = useCallback(async (candidate: unknown, path?: string | null) => {+ if (!validateProjectData(candidate)) {+ return false;}+ const project = candidate;+ const sourcePath = project.videoPath;+ const normalizedEditor = normalizeProjectEditor(project.editor);+try {- const url = new URL(fileUrl);- return decodeURIComponent(url.pathname);+ videoPlaybackRef.current?.pause();} catch {- return fileUrl.replace(/^file:\/\//, '');+ // no-op+ }+ setIsPlaying(false);+ setCurrentTime(0);+ setDuration(0);++ setError(null);+ setVideoSourcePath(sourcePath);+ setVideoPath(toFileUrl(sourcePath));+ setCurrentProjectPath(path ?? null);+- setWallpaper(normalizedEditor.wallpaper);- setShadowIntensity(normalizedEditor.shadowIntensity);- setShowBlur(normalizedEditor.showBlur);- setMotionBlurEnabled(normalizedEditor.motionBlurEnabled);- setBorderRadius(normalizedEditor.borderRadius);- setPadding(normalizedEditor.padding);- setCropRegion(normalizedEditor.cropRegion);- setZoomRegions(normalizedEditor.zoomRegions);- setTrimRegions(normalizedEditor.trimRegions);- setSpeedRegions(normalizedEditor.speedRegions);- setAnnotationRegions(normalizedEditor.annotationRegions);- setAspectRatio(normalizedEditor.aspectRatio);++ pushState({++ wallpaper: normalizedEditor.wallpaper,++ shadowIntensity: normalizedEditor.shadowIntensity,++ showBlur: normalizedEditor.showBlur,++ motionBlurEnabled: normalizedEditor.motionBlurEnabled,++ borderRadius: normalizedEditor.borderRadius,++ padding: normalizedEditor.padding,++ cropRegion: normalizedEditor.cropRegion,++ zoomRegions: normalizedEditor.zoomRegions,++ trimRegions: normalizedEditor.trimRegions,++ speedRegions: normalizedEditor.speedRegions,++ annotationRegions: normalizedEditor.annotationRegions,++ aspectRatio: normalizedEditor.aspectRatio,++ });+ setExportQuality(normalizedEditor.exportQuality);+ setExportFormat(normalizedEditor.exportFormat);+ setGifFrameRate(normalizedEditor.gifFrameRate);+ setGifLoop(normalizedEditor.gifLoop);+ setGifSizePreset(normalizedEditor.gifSizePreset);++ setSelectedZoomId(null);+ setSelectedTrimId(null);+ setSelectedSpeedId(null);+ setSelectedAnnotationId(null);++ nextZoomIdRef.current = deriveNextId("zoom", normalizedEditor.zoomRegions.map((region) => region.id));+ nextTrimIdRef.current = deriveNextId("trim", normalizedEditor.trimRegions.map((region) => region.id));+ nextSpeedIdRef.current = deriveNextId("speed", normalizedEditor.speedRegions.map((region) => region.id));+ nextAnnotationIdRef.current = deriveNextId(+ "annotation",+ normalizedEditor.annotationRegions.map((region) => region.id),+ );+ nextAnnotationZIndexRef.current =+ normalizedEditor.annotationRegions.reduce((max, region) => Math.max(max, region.zIndex), 0) + 1;++ setLastSavedSnapshot(JSON.stringify(createProjectData(sourcePath, normalizedEditor)));+ return true;- }, []);++ }, [pushState]);++ const currentProjectSnapshot = useMemo(() => {+ const sourcePath = videoSourcePath ?? (videoPath ? fromFileUrl(videoPath) : null);+ if (!sourcePath) {+ return null;}- };+ return JSON.stringify(+ createProjectData(sourcePath, {+ wallpaper,+ shadowIntensity,+ showBlur,+ motionBlurEnabled,+ borderRadius,+ padding,+ cropRegion,+ zoomRegions,+ trimRegions,+ speedRegions,+ annotationRegions,+ aspectRatio,+ exportQuality,+ exportFormat,+ gifFrameRate,+ gifLoop,+ gifSizePreset,+ }),+ );+ }, [+ videoPath,+ videoSourcePath,+ wallpaper,+ shadowIntensity,+ showBlur,+ motionBlurEnabled,+ borderRadius,+ padding,+ cropRegion,+ zoomRegions,+ trimRegions,+ speedRegions,+ annotationRegions,+ aspectRatio,+ exportQuality,+ exportFormat,+ gifFrameRate,+ gifLoop,+ gifSizePreset,+ ]);++ const hasUnsavedChanges = Boolean(+ currentProjectPath &&+ currentProjectSnapshot &&+ lastSavedSnapshot &&+ currentProjectSnapshot !== lastSavedSnapshot,+ );useEffect(() => {- async function loadVideo() {+ async function loadInitialData() {try {+ const currentProjectResult = await window.electronAPI.loadCurrentProjectFile();+ if (currentProjectResult.success && currentProjectResult.project) {+ const restored = await applyLoadedProject(+ currentProjectResult.project,+ currentProjectResult.path ?? null,+ );+ if (restored) {+ return;+ }+ }+const result = await window.electronAPI.getCurrentVideoPath();-if (result.success && result.path) {- const videoUrl = toFileUrl(result.path);- setVideoPath(videoUrl);+ setVideoSourcePath(result.path);+ setVideoPath(toFileUrl(result.path));+ setCurrentProjectPath(null);+ setLastSavedSnapshot(null);} else {- setError('No video to load. Please record or select a video.');+ setError("No video to load. Please record or select a video.");}} catch (err) {- setError('Error loading video: ' + String(err));+ setError("Error loading video: " + String(err));} finally {setLoading(false);}@@@ -151,15 -407,23 +404,6 @@@};}, [videoPath]);-- // Initialize default wallpaper with resolved asset path-- useEffect(() => {-- let mounted = true;- getAssetPath('wallpapers/wallpaper1.jpg')- .then((path) => { if (mounted) updateState({ wallpaper: path }); })- .catch((err) => console.warn('Failed to resolve default wallpaper path:', err));- return () => { mounted = false; };- }, [updateState]);- (async () => {- try {- const resolvedPath = await getAssetPath('wallpapers/wallpaper1.jpg');- if (mounted) {- setWallpaper(resolvedPath);- }- } catch (err) {- // If resolution fails, keep the fallback- console.warn('Failed to resolve default wallpaper path:', err);- }- })();- return () => { mounted = false };- }, []);--function togglePlayPause() {const playback = videoPlaybackRef.current;const video = playback?.video;