Create polished demo videos without editing skills. Mac/Windows/Linux
edit: LaunchWindow, RecordingControls for seperations of concern fix: SourceSelection performances add: seperator.tsx for "divider" component, instead of a non-generic component. can be reused elsewhere!
Alan Trebugeais7f85bd0e70f1
diff --git a/.kilo/plans/1778084832635-happy-otter.md b/.kilo/plans/1778084832635-happy-otter.mdnew file mode 100644index 00000000..03437fb3--- /dev/null+++ b/.kilo/plans/1778084832635-happy-otter.md@@ -0,0 +1,214 @@+# LaunchWindow Refactoring Plan++## Overview+Refactor the monolithic LaunchWindow.tsx (1627 lines) into smaller, focused components with improved performance, better separation of concerns, and enhanced UI responsiveness.++## Current Problems Identified++1. **Monolithic Component** - Single file with 1627 lines handling everything+2. **Performance Issues** - Multiple useEffects, frequent re-renders, no memoization+3. **UI Lag** - Complex drag handlers, frequent electron API calls on every render+4. **Poor Separation** - Mixes UI, business logic, and electron API interactions+5. **State Management** - 20+ useState calls scattered throughout+6. **No Code Splitting** - All logic in one component++## Refactoring Strategy++### Phase 1: Component Decomposition++#### Core Components to Extract:++1. **RecordingControls** (lines 972-1037)+ - Handles recording state UI (recording, paused, idle)+ - Extract to: `src/components/launch/RecordingControls.tsx`++2. **SourceSelector** (lines 1041-1061, 1185-1256)+ - Screen/window source selection dropdown+ - Extract to: `src/components/launch/SourceSelector.tsx`++3. **MicrophoneSelector** (lines 1260-1324)+ - Microphone device selection with audio level meter+ - Extract to: `src/components/launch/MicrophoneSelector.tsx`++4. **WebcamSelector** (lines 1326-1417)+ - Webcam device selection and preview+ - Extract to: `src/components/launch/WebcamSelector.tsx`++5. **CountdownSelector** (lines 1419-1438)+ - Countdown delay options+ - Extract to: `src/components/launch/CountdownSelector.tsx`++6. **MoreOptionsMenu** (lines 1440-1528)+ - Additional settings (HUD capture, folder, language, etc.)+ - Extract to: `src/components/launch/MoreOptionsMenu.tsx`++7. **WebcamPreview** (lines 1601-1622)+ - Floating webcam preview with drag functionality+ - Extract to: `src/components/launch/WebcamPreview.tsx`++8. **HUDBar** (lines 1539-1599)+ - Main HUD bar with drag handle and state display+ - Extract to: `src/components/launch/HUDBar.tsx`++9. **ProjectBrowser** (lines 1172-1184)+ - Project library browser dialog+ - Already exists as separate component, just needs better integration++### Phase 2: Custom Hooks++Extract logic into reusable hooks:++1. **useRecordingState**+ - Manages recording, paused, finalizing states+ - Handles timer logic and elapsed time calculation++2. **useDeviceSelection**+ - Manages microphone and webcam device selection+ - Handles audio/video device enumeration++3. **useHUDPosition**+ - Manages HUD and webcam preview positioning+ - Handles drag state and boundary clamping++4. **useSourceSelection**+ - Manages screen/window source selection+ - Handles source fetching and caching++5. **useHUDVisibility**+ - Manages HUD capture protection and visibility+ - Handles electron API interactions for HUD state++6. **useElectronAPI** (wrapper)+ - Centralizes all electron API calls+ - Adds caching and debouncing for frequently called APIs++### Phase 3: Performance Optimizations++1. **Memoization**+ - Use `useCallback` for all event handlers+ - Use `useMemo` for derived state and expensive calculations+ - Memoize component props to prevent unnecessary re-renders++2. **State Consolidation**+ - Group related state using `useReducer` for complex state logic+ - Separate UI state from business logic state++3. **Effect Optimization**+ - Combine related useEffects+ - Add proper dependency arrays+ - Use cleanup functions to prevent memory leaks++4. **Debounced API Calls**+ - Debounce frequent electron API calls (e.g., HUD position updates)+ - Cache API results where appropriate++5. **Lazy Loading**+ - Lazy load heavy components (ProjectBrowser, settings panels)+ - Use React.lazy() for non-critical components++### Phase 4: UI/UX Improvements++1. **Responsive Design**+ - Add proper breakpoints for different screen sizes+ - Improve touch/pointer event handling++2. **Smooth Animations**+ - Optimize Framer Motion usage+ - Reduce layout thrashing+ - Use `transform` and `opacity` for animations++3. **Better Drag Handling**+ - Use requestAnimationFrame for smooth dragging+ - Implement velocity-based snapping+ - Add visual feedback during drag operations++4. **Accessibility**+ - Add ARIA labels and roles+ - Improve keyboard navigation+ - Focus management for dropdowns++### Phase 5: Code Quality++1. **Type Safety**+ - Extract interfaces to separate types file+ - Add proper JSDoc comments+ - Use discriminated unions for state management++2. **Error Boundaries**+ - Add error boundaries for critical components+ - Graceful degradation for failed operations++3. **Testing**+ - Add unit tests for hooks+ - Component tests for UI interactions+ - Integration tests for electron API interactions++## Implementation Priority++### High Priority (Fix Performance Issues)+1. Extract WebcamPreview component - Reduces main component complexity+2. Extract RecordingControls - Isolates recording state logic+3. Implement useRecordingState hook - Centralizes timer logic+4. Add memoization to prevent re-renders++### Medium Priority (Improve Code Organization)+5. Extract all selector components (Source, Microphone, Webcam, Countdown)+6. Extract HUDBar and MoreOptionsMenu+7. Implement custom hooks for device selection and HUD position++### Low Priority (Enhancements)+8. Add responsive design improvements+9. Optimize animations and drag handling+10. Add comprehensive testing++## File Structure After Refactoring++```+src/components/launch/+├── LaunchWindow.tsx # Main component (reduced to ~200 lines)+├── RecordingControls.tsx # Recording state UI+├── SourceSelector.tsx # Screen/window selection+├── MicrophoneSelector.tsx # Microphone device selection+├── WebcamSelector.tsx # Webcam device selection+├── CountdownSelector.tsx # Countdown delay options+├── MoreOptionsMenu.tsx # Additional settings+├── WebcamPreview.tsx # Floating webcam preview+├── HUDBar.tsx # Main HUD bar+├── ProjectBrowser.tsx # Project browser dialog+└── types.ts # Type definitions++src/hooks/launch/+├── useRecordingState.ts # Recording state management+├── useDeviceSelection.ts # Device selection logic+├── useHUDPosition.ts # HUD positioning logic+├── useSourceSelection.ts # Source selection logic+├── useHUDVisibility.ts # HUD visibility management+└── useElectronAPI.ts # Electron API wrapper++src/types/launch/+└── index.ts # All type definitions+```++## Expected Benefits++1. **Performance**: 60%+ reduction in re-renders, smoother animations+2. **Maintainability**: Easier to understand and modify individual components+3. **Testability**: Isolated components are easier to test+4. **Reusability**: Custom hooks can be used in other parts of the app+5. **Developer Experience**: Clear separation of concerns, better documentation++## Migration Strategy++1. Create new component files alongside existing code+2. Gradually extract functionality, testing each component+3. Keep LaunchWindow.tsx functional during migration+4. Replace sections incrementally+5. Remove old code only after new implementation is verified++## Success Metrics++- Main component reduced to <300 lines+- All custom hooks properly tested+- No performance regressions (verified with React DevTools)+- All existing functionality preserved+- Improved code coverage (>80% for new components)diff --git a/electron/ipc/register/sources.ts b/electron/ipc/register/sources.tsindex a5e6d601..d023ede1 100644--- a/electron/ipc/register/sources.ts+++ b/electron/ipc/register/sources.ts@@ -133,7 +133,6 @@ export function registerSourceHandlers({if (process.platform !== "darwin" || !includeWindows) {const windowSources = electronSources.filter((source) => source.id.startsWith("window:"))- .filter((source) => hasUsableSourceThumbnail(source.thumbnail)).filter((source) => {const normalizedName = normalizeDesktopSourceName(source.name);if (!normalizedName) {diff --git a/electron/native/bin/win32-x64/cursor-monitor.exe b/electron/native/bin/win32-x64/cursor-monitor.exeindex cd3e7611..4a088baf 100644Binary files a/electron/native/bin/win32-x64/cursor-monitor.exe and b/electron/native/bin/win32-x64/cursor-monitor.exe differdiff --git a/electron/native/bin/win32-x64/helpers-manifest.json b/electron/native/bin/win32-x64/helpers-manifest.jsonindex 0ae7bb77..526ad5dd 100644--- a/electron/native/bin/win32-x64/helpers-manifest.json+++ b/electron/native/bin/win32-x64/helpers-manifest.json@@ -5,17 +5,17 @@"helpers": {"wgc-capture": {"binaryName": "wgc-capture.exe",- "binarySha256": "bb4c2aa4141e81e1a05b54bd49dbb114eb3a5ff4a666bf7d26525a9da585128b",+ "binarySha256": "5db12103dfc73d691094c1e4fe5bbbd5b3ea0aa1f0d20e1c733e259572f20095","sourceDir": "electron/native/wgc-capture",- "sourceFingerprint": "5bb02a69049a02909d38188cae1dfdfb94fd49465b51ed6ab78a98092b7520cc",- "updatedAt": "2026-04-25T09:17:16.237Z"+ "sourceFingerprint": "6622b210852e25715a9206d1f183f0f4fc3c9ee637d6533ebec83d96f73a0186",+ "updatedAt": "2026-05-06T16:35:59.499Z"},"cursor-monitor": {"binaryName": "cursor-monitor.exe",- "binarySha256": "b0732abc06998a40c3e95078465ad750a6169901944571c39cfd7996effe39c0",+ "binarySha256": "2970e82c6e151816b5b79f43903f5166a114142c5777c92932bf89820e94c10a","sourceDir": "electron/native/cursor-monitor",- "sourceFingerprint": "6ad1b8b50bb336f2a48937b06f5ec56d90b6ab4a3e56a4bca278cf67a5d3e52e",- "updatedAt": "2026-03-29T02:15:38.286Z"+ "sourceFingerprint": "45bb72e4039e061a354af87317d7c42ec3d2118369b3f4379046ff497b701e72",+ "updatedAt": "2026-05-06T16:36:04.853Z"}}}diff --git a/electron/native/bin/win32-x64/wgc-capture.exe b/electron/native/bin/win32-x64/wgc-capture.exeindex d16a0724..3a0428fc 100644Binary files a/electron/native/bin/win32-x64/wgc-capture.exe and b/electron/native/bin/win32-x64/wgc-capture.exe differdiff --git a/package-lock.json b/package-lock.jsonindex 6c7e1afd..6cca35da 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "recordly",- "version": "1.2.0-beta.2",+ "version": "1.2.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "recordly",- "version": "1.2.0-beta.2",+ "version": "1.2.0","hasInstallScript": true,"dependencies": {"@phosphor-icons/react": "^2.1.10",diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsxindex 9c300475..22741b22 100644--- a/src/components/launch/LaunchWindow.tsx+++ b/src/components/launch/LaunchWindow.tsx@@ -10,10 +10,6 @@ import {Minus,Monitor,DotsThreeVertical as MoreVertical,- Pause,- Play,- ArrowClockwise as RefreshCw,- Stop as Square,Timer,VideoCamera as Video,VideoCamera as VideoIcon,@@ -21,6 +17,7 @@ import {SpeakerHigh as Volume2,SpeakerX as VolumeX,X,+ ArrowClockwise as RefreshCw,} from "@phosphor-icons/react";import { AnimatePresence, motion } from "motion/react";import type { ReactNode } from "react";@@ -48,6 +45,7 @@ import {shouldRestoreHudMousePassthroughAfterDrag,} from "./hudMousePassthrough";import styles from "./LaunchWindow.module.css";+import { RecordingControls } from "./RecordingControls";interface DesktopSource {id: string;@@ -77,7 +75,7 @@ const DEFAULT_WEBCAM_PREVIEW_OFFSET = { x: 0, y: 0 };const DEFAULT_RECORDING_HUD_OFFSET = { x: 0, y: 0 };const SHOW_DEV_UPDATE_PREVIEW = import.meta.env.DEV;-function IconButton({+export function IconButton({onClick,title,className = "",@@ -103,7 +101,7 @@ function IconButton({);}-function DropdownItem({+export function DropdownItem({onClick,selected,icon,@@ -129,7 +127,7 @@ function DropdownItem({);}-function Separator({ dropdown = false }: { dropdown?: boolean }) {+export function Separator({ dropdown = false }: { dropdown?: boolean }) {return <div className={dropdown ? styles.ddSep : styles.sep} />;}@@ -970,70 +968,17 @@ export function LaunchWindow() {};const recordingControls = (- <>- <div className="flex items-center gap-[5px]">- <div- className={`w-[7px] h-[7px] rounded-full ${paused ? "bg-[#fbbf24]" : `bg-[#f43f5e] ${styles.recDotBlink}`}`}- />- <span- className={`text-[10px] font-bold tracking-[0.06em] ${paused ? "text-[#fbbf24]" : "text-[#f43f5e]"}`}- >- {paused ? t("recording.paused") : t("recording.rec")}- </span>- </div>-- <span- className={`font-mono text-xs font-semibold min-w-[52px] text-center tracking-[0.02em] ${paused ? "text-[#fbbf24]" : "text-[#eeeef2]"}`}- >- {formatTime(elapsed)}- </span>-- <Separator />-- <IconButton- title={- microphoneEnabled- ? t("recording.disableMicrophone")- : t("recording.enableMicrophone")- }- className={microphoneEnabled ? styles.ibActive : ""}- >- {microphoneEnabled ? <Mic size={18} /> : <MicOff size={18} />}- </IconButton>-- <Separator />-- <IconButton- onClick={paused ? resumeRecording : pauseRecording}- title={paused ? t("recording.resume") : t("recording.pause")}- className={paused ? styles.ibGreen : ""}- >- {paused ? (- <Play size={18} fill="currentColor" strokeWidth={0} />- ) : (- <Pause size={18} />- )}- </IconButton>-- <IconButton- onClick={toggleRecording}- title={t("recording.stop")}- className={styles.ibRed}- >- <Square size={16} fill="currentColor" strokeWidth={0} />- </IconButton>-- <IconButton- onClick={() => window.electronAPI?.hudOverlayHide?.()}- title={t("recording.hideHud")}- >- <Minus size={16} />- </IconButton>-- <IconButton onClick={cancelRecording} title={t("recording.cancel")}>- <X size={18} />- </IconButton>- </>+ <RecordingControls+ paused={paused}+ microphoneEnabled={microphoneEnabled}+ elapsed={elapsed}+ onToggleMicrophone={() => setMicrophoneEnabled(!microphoneEnabled)}+ onPauseResume={paused ? resumeRecording : pauseRecording}+ onStopRecording={toggleRecording}+ onHideHud={() => window.electronAPI?.hudOverlayHide?.()}+ onCancelRecording={cancelRecording}+ formatTime={formatTime}+ />);const idleControls = (diff --git a/src/components/launch/RecordingControls.tsx b/src/components/launch/RecordingControls.tsxnew file mode 100644index 00000000..05fc3d7f--- /dev/null+++ b/src/components/launch/RecordingControls.tsx@@ -0,0 +1,121 @@+import { Microphone as Mic, MicrophoneSlash as MicOff, Minus, Pause, Play, Stop as Square, X } from "@phosphor-icons/react";+import { useMemo } from "react";+import { useScopedT } from "@/contexts/I18nContext";+import { IconButton } from "./LaunchWindow";+import { Separator } from "./LaunchWindow";+import styles from "./LaunchWindow.module.css";++interface RecordingControlsProps {+ paused: boolean;+ microphoneEnabled: boolean;+ elapsed: number;+ onToggleMicrophone: () => void;+ onPauseResume: () => void;+ onStopRecording: () => void;+ onHideHud: () => void;+ onCancelRecording: () => void;+ formatTime: (seconds: number) => string;+}++export const RecordingControls = ({+ paused,+ microphoneEnabled,+ elapsed,+ onToggleMicrophone,+ onPauseResume,+ onStopRecording,+ onHideHud,+ onCancelRecording,+ formatTime,+}: RecordingControlsProps) => {+ const t = useScopedT("launch");++ const memoizedControls = useMemo(() => {+ return (+ <>+ <div className="flex items-center gap-[5px]">+ <div+ className={`w-[7px] h-[7px] rounded-full ${+ paused ? "bg-[#fbbf24]" : `bg-[#f43f5e] ${styles.recDotBlink}`+ }`}+ />+ <span+ className={`text-[10px] font-bold tracking-[0.06em] ${+ paused ? "text-[#fbbf24]" : "text-[#f43f5e]"+ }`}+ >+ {paused ? t("recording.paused") : t("recording.rec")}+ </span>+ </div>++ <span+ className={`font-mono text-xs font-semibold min-w-[52px] text-center tracking-[0.02em] ${+ paused ? "text-[#fbbf24]" : "text-[#eeeef2]"+ }`}+ >+ {formatTime(elapsed)}+ </span>++ <Separator />++ <IconButton+ title={+ microphoneEnabled+ ? t("recording.disableMicrophone")+ : t("recording.enableMicrophone")+ }+ className={microphoneEnabled ? styles.ibActive : ""}+ onClick={onToggleMicrophone}+ >+ {microphoneEnabled ? <Mic size={18} /> : <MicOff size={18} />}+ </IconButton>++ <Separator />++ <IconButton+ onClick={onPauseResume}+ title={paused ? t("recording.resume") : t("recording.pause")}+ className={paused ? styles.ibGreen : ""}+ >+ {paused ? (+ <Play size={18} fill="currentColor" strokeWidth={0} />+ ) : (+ <Pause size={18} />+ )}+ </IconButton>++ <IconButton+ onClick={onStopRecording}+ title={t("recording.stop")}+ className={styles.ibRed}+ >+ <Square size={16} fill="currentColor" strokeWidth={0} />+ </IconButton>++ <IconButton+ onClick={onHideHud}+ title={t("recording.hideHud")}+ >+ <Minus size={16} />+ </IconButton>++ <IconButton onClick={onCancelRecording} title={t("recording.cancel")}>+ <X size={18} />+ </IconButton>+ </>+ );+ }, [+ paused,+ microphoneEnabled,+ elapsed,+ onToggleMicrophone,+ onPauseResume,+ onStopRecording,+ onHideHud,+ onCancelRecording,+ formatTime,+ t,+ ]);++ return memoizedControls;+};diff --git a/src/components/launch/SourceSelector.tsx b/src/components/launch/SourceSelector.tsxindex fec7af9b..291a85a9 100644--- a/src/components/launch/SourceSelector.tsx+++ b/src/components/launch/SourceSelector.tsx@@ -58,38 +58,61 @@ export function SourceSelector() {const [loading, setLoading] = useState(true);useEffect(() => {+ let isMounted = true;async function fetchSources() {setLoading(true);try {- const rawSources = await window.electronAPI.getSources({+ // Step 1: Fetch metadata quickly without thumbnails+ const metadataSources = await window.electronAPI.getSources({types: ["screen", "window"],- thumbnailSize: { width: 320, height: 180 },+ thumbnailSize: { width: 160, height: 90 },fetchWindowIcons: true,});- setSources(- rawSources.map((source) => {- const metadata = parseSourceMetadata(source);- return {- id: source.id,- name: metadata.displayName,- thumbnail: source.thumbnail,- display_id: source.display_id,- appIcon: source.appIcon,- originalName: source.name,- sourceType: metadata.sourceType,- appName: metadata.appName,- windowTitle: metadata.windowTitle,- };+ if (!isMounted) return;++ const initialSources = metadataSources.map((source) => {+ const metadata = parseSourceMetadata(source);+ return {+ id: source.id,+ name: metadata.displayName,+ thumbnail: null,+ display_id: source.display_id,+ appIcon: source.appIcon,+ originalName: source.name,+ sourceType: metadata.sourceType,+ appName: metadata.appName,+ windowTitle: metadata.windowTitle,+ };+ });++ setSources(initialSources);+ setLoading(false);++ // Step 2: Fetch actual thumbnails in the background+ const fullSources = await window.electronAPI.getSources({+ types: ["screen", "window"],+ thumbnailSize: { width: 240, height: 135 },+ fetchWindowIcons: true,+ });++ if (!isMounted) return;++ setSources((prev) =>+ prev.map((s) => {+ const full = fullSources.find((f) => f.id === s.id);+ return full ? { ...s, thumbnail: full.thumbnail } : s;}),);} catch (error) {console.error("Error loading sources:", error);- } finally {- setLoading(false);+ if (isMounted) setLoading(false);}}fetchSources();+ return () => {+ isMounted = false;+ };}, []);const screenSources = sources.filter((s) => s.id.startsWith("screen:"));diff --git a/src/components/ui/separator.tsx b/src/components/ui/separator.tsxnew file mode 100644index 00000000..0640473a--- /dev/null+++ b/src/components/ui/separator.tsx@@ -0,0 +1,27 @@+import { cn } from "@/lib/utils";++interface SeparatorProps {+ /** Orientation of the separator */+ orientation?: "horizontal" | "vertical";+ /** Additional CSS classes */+ className?: string;+}++/**+ * A reusable separator component that can be used as a horizontal or vertical divider.+ * Replaces the inline div separators used throughout the application.+ */+export function Separator({+ orientation = "horizontal",+ className,+}: SeparatorProps) {+ return (+ <div+ className={cn(+ "bg-separator",+ orientation === "horizontal" ? "h-px w-full" : "w-px h-full",+ className,+ )}+ />+ );+}