Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: Revamped settings menu + Camera flash fix
Richie McIlroyfa2776137f0b
diff --git a/.gitignore b/.gitignoreindex 12a925497..cfed069cb 100644--- a/.gitignore+++ b/.gitignore@@ -33,3 +33,4 @@ pnpm-lock.yaml.output.vinxinative-deps+apps/storybook/storybook-static\ No newline at end of filediff --git a/apps/desktop/src-tauri/src/general_settings.rs b/apps/desktop/src-tauri/src/general_settings.rsindex 9e482a966..fe04b3a47 100644--- a/apps/desktop/src-tauri/src/general_settings.rs+++ b/apps/desktop/src-tauri/src/general_settings.rs@@ -8,6 +8,7 @@ use tauri_plugin_store::{with_store, StoreCollection};#[derive(Serialize, Deserialize, Type, Default)]pub struct GeneralSettingsStore {pub upload_individual_files: bool,+ pub open_editor_after_recording: bool,}impl GeneralSettingsStore {diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex cb85eccc4..aa17dd78c 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -490,8 +490,20 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<serde_json::to_string_pretty(&json!(&config)).unwrap(),).unwrap();-AppSounds::StopRecording.play();+ if let Ok(Some(settings)) = GeneralSettingsStore::get(&app) {+ if settings.open_editor_after_recording {+ let recording_id = current_recording+ .recording_dir+ .file_name()+ .unwrap_or_default()+ .to_string_lossy()+ .to_string()+ .trim_end_matches(".cap")+ .to_string();+ open_editor(app.clone(), recording_id);+ }+ }CurrentRecordingChanged(JsonValue::new(&None)).emit(&app)@@ -1261,6 +1273,7 @@ fn show_previous_recordings_window(app: AppHandle) {#[tauri::command(async)]#[specta::specta]fn open_editor(app: AppHandle, id: String) {+ println!("Opening editor for recording: {}", id);let window = WebviewWindow::builder(&app,format!("editor-{id}"),@@ -2006,13 +2019,12 @@ fn get_recording_meta(app: AppHandle, id: String, file_type: String) -> RecordinRecordingMeta::load_for_project(&meta_path).unwrap()}-#[tauri::command]#[specta::specta]fn list_recordings(app: AppHandle) -> Result<Vec<(String, PathBuf, RecordingMeta)>, String> {let recordings_dir = recordings_path(&app);- let result = std::fs::read_dir(&recordings_dir)+ let mut result = std::fs::read_dir(&recordings_dir).map_err(|e| format!("Failed to read recordings directory: {}", e))?.filter_map(|entry| {let entry = entry.ok()?;@@ -2020,22 +2032,33 @@ fn list_recordings(app: AppHandle) -> Result<Vec<(String, PathBuf, RecordingMetaif path.is_dir() && path.extension().and_then(|s| s.to_str()) == Some("cap") {let id = path.file_stem()?.to_str()?.to_string();let meta = get_recording_meta(app.clone(), id.clone(), "recording".to_string());- Some((id, path, meta))+ Some((id, path.clone(), meta))} else {None}}).collect::<Vec<_>>();+ // Sort the result by creation date of the actual file, newest first+ result.sort_by(|a, b| {+ b.1.metadata()+ .and_then(|m| m.created())+ .unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH)+ .cmp(+ &a.1.metadata()+ .and_then(|m| m.created())+ .unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH),+ )+ });+Ok(result)}-#[tauri::command]#[specta::specta]fn list_screenshots(app: AppHandle) -> Result<Vec<(String, PathBuf, RecordingMeta)>, String> {let screenshots_dir = screenshots_path(&app);- let result = std::fs::read_dir(&screenshots_dir)+ let mut result = std::fs::read_dir(&screenshots_dir).map_err(|e| format!("Failed to read screenshots directory: {}", e))?.filter_map(|entry| {let entry = entry.ok()?;@@ -2058,6 +2081,18 @@ fn list_screenshots(app: AppHandle) -> Result<Vec<(String, PathBuf, RecordingMet}).collect::<Vec<_>>();+ // Sort the result by creation date of the actual file, newest first+ result.sort_by(|a, b| {+ b.1.metadata()+ .and_then(|m| m.created())+ .unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH)+ .cmp(+ &a.1.metadata()+ .and_then(|m| m.created())+ .unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH),+ )+ });+Ok(result)}diff --git a/apps/desktop/src/routes/(window-chrome)/settings.tsx b/apps/desktop/src/routes/(window-chrome)/settings.tsxindex 516e2c112..184d7d78f 100644--- a/apps/desktop/src/routes/(window-chrome)/settings.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings.tsx@@ -12,8 +12,8 @@ export default function (props: RouteSectionProps) {};return (- <div class="h-full flex flex-row divide-x divide-gray-200 text-[0.875rem] leading-[1.25rem]">- <div class="flex flex-col">+ <div class="h-[calc(100vh-3rem)] flex flex-row divide-x divide-gray-200 text-[0.875rem] leading-[1.25rem]">+ <div class="h-full flex flex-col"><ul class="min-w-[12rem] h-full p-[0.625rem] space-y-2"><Foreach={[diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsxindex a4252aba7..d58986482 100644--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx@@ -8,9 +8,14 @@ const settingsList = [key: "upload_individual_files",label: "Upload individual recording files when creating shareable link",description:- "Warning: this will cause shareable link uploads to become significantly slower, since multiple files will be uploaded.",+ 'Warning: this will cause shareable link uploads to become significantly slower, since all individual recording files will be uploaded. Shows "Download Assets" button in Share page.',+ },+ {+ key: "open_editor_after_recording",+ label: "Open editor automatically after recording stops",+ description:+ "The editor will be shown immediately after you finish recording.",},- // Add more settings here as needed];export default function GeneralSettings() {@@ -31,7 +36,10 @@ export default function GeneralSettings() {function Inner(props: { store: GeneralSettingsStore | null }) {const [settings, setSettings] = createStore<GeneralSettingsStore>(- props.store ?? { upload_individual_files: false }+ props.store ?? {+ upload_individual_files: false,+ open_editor_after_recording: false,+ });const handleChange = async (key: string, value: boolean) => {@@ -43,11 +51,11 @@ function Inner(props: { store: GeneralSettingsStore | null }) {};return (- <div class="flex flex-col w-full h-full divide-y divide-gray-200 pt-1 pb-12">- <div class="flex-1 p-4 space-y-4">+ <div class="flex flex-col w-full h-full divide-y divide-gray-200 pb-12">+ <div class="flex-1 p-4 space-y-2 divide-y divide-gray-200"><For each={settingsList}>{(setting) => (- <div class="space-y-2">+ <div class="space-y-2 py-3"><div class="flex items-center justify-between"><p>{setting.label}</p><buttondiff --git a/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsx b/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsxindex ca5d0e4c8..edaf8376d 100644--- a/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsx@@ -102,7 +102,7 @@ function ScreenshotItem(props: {onError={() => setImageExists(false)}/></Show>- <span>{props.screenshot.prettyName}</span>+ <span>{props.screenshot.prettyName.replace(".png", "")}</span></div><div class="flex items-center"><button@@ -113,7 +113,7 @@ function ScreenshotItem(props: {}}class="p-2 hover:bg-gray-200 rounded-full mr-2">- <IconLucideFolder class="size-6" />+ <IconLucideFolder class="size-5" /></button><buttontype="button"@@ -123,7 +123,7 @@ function ScreenshotItem(props: {}}class="p-2 hover:bg-gray-200 rounded-full">- <IconLucideEye class="size-6" />+ <IconLucideEye class="size-5" /></button></div></li>diff --git a/apps/desktop/src/routes/camera.tsx b/apps/desktop/src/routes/camera.tsxindex 48c3ada27..abb917882 100644--- a/apps/desktop/src/routes/camera.tsx+++ b/apps/desktop/src/routes/camera.tsx@@ -13,6 +13,7 @@ import {createResource,createSignal,on,+ onCleanup,} from "solid-js";import { createStore } from "solid-js/store";import { ToggleButton as KToggleButton } from "@kobalte/core/toggle-button";@@ -37,7 +38,9 @@ export default function () {const camera = createCameraForLabel(() => options.data?.cameraLabel ?? "");- const [cameraPreviewRef] = createCameraPreview(() => camera()?.deviceId);+ const [cameraPreviewRef, setCameraStream] = createCameraPreview(+ () => camera()?.deviceId+ );const [state, setState] = makePersisted(createStore<CameraWindow.State>({@@ -49,31 +52,44 @@ export default function () {createEffect(on(() => state.size, resizeWindow));+ const [isLoading, setIsLoading] = createSignal(true);++ createEffect(() => {+ if (setCameraStream()) {+ setIsLoading(false);+ }+ });+return (- <Suspense fallback={<div class="w-screen h-screen bg-red-400" />}>+ <Suspense fallback={<CameraLoadingState shape={state.shape} />}><Show when={options.data}>{(options) => (<divdata-tauri-drag-region- class="cursor-move group w-screen h-screen relative flex flex-col"+ class="cursor-move group w-screen h-screen relative flex flex-col bg-black"style={{ "border-radius": cameraBorderRadius(state) }}><div class="h-16" data-tauri-drag-region /><div class="flex flex-col flex-1 relative" data-tauri-drag-region>- <video- data-tauri-drag-region- autoplay- playsinline- muted- class={cx(- "w-full h-full object-cover pointer-events-none border-none shadow-lg",- state.shape === "round" ? "rounded-full" : "rounded-3xl"- )}- style={{- transform: state.mirrored ? "scaleX(1)" : "scaleX(-1)",- }}- ref={cameraPreviewRef}- />+ <Show+ when={!isLoading()}+ fallback={<CameraLoadingState shape={state.shape} />}+ >+ <video+ data-tauri-drag-region+ autoplay+ playsinline+ muted+ class={cx(+ "w-full h-full object-cover pointer-events-none border-none shadow-lg",+ state.shape === "round" ? "rounded-full" : "rounded-3xl"+ )}+ style={{+ transform: state.mirrored ? "scaleX(1)" : "scaleX(-1)",+ }}+ ref={cameraPreviewRef}+ />+ </Show><div class="flex flex-row items-center justify-center absolute -top-14 inset-x-0"><div class="flex flex-row gap-[0.25rem] p-[0.25rem] opacity-0 group-hover:opacity-100 translate-y-2 group-hover:translate-y-0 rounded-xl transition-[opacity,transform] bg-gray-500 border border-white-transparent-20 text-gray-400"><ControlButton@@ -120,6 +136,19 @@ export default function () {);}+function CameraLoadingState({ shape }: { shape: CameraWindow.Shape }) {+ return (+ <div+ class={cx(+ "w-full h-full bg-[#000000] flex items-center justify-center",+ shape === "round" ? "rounded-full" : "rounded-3xl"+ )}+ >+ <IconLucideLoaderCircle class="size-[4rem] animate-spin text-gray-300" />+ </div>+ );+}+function cameraBorderRadius(state: CameraWindow.State) {if (state.shape === "round") return "9999px";if (state.size === "sm") return "3rem";@@ -145,13 +174,31 @@ async function resizeWindow(size: CameraWindow.Size) {}function createCameraPreview(deviceId: () => string | undefined) {- const [cameraStream] = createResource(+ const [cameraStream, { refetch }] = createResource(deviceId,-- (cameraInputId) =>- navigator.mediaDevices.getUserMedia({- video: { deviceId: cameraInputId },- })+ async (cameraInputId) => {+ if (!cameraInputId) return null;+ try {+ const stream = await navigator.mediaDevices.getUserMedia({+ video: {+ deviceId: cameraInputId,+ width: { ideal: 1920 },+ height: { ideal: 1080 },+ frameRate: { ideal: 30 },+ },+ });++ // Get the actual settings of the stream+ const videoTrack = stream.getVideoTracks()[0];+ const settings = videoTrack.getSettings();+ console.log("Camera settings:", settings);++ return stream;+ } catch (error) {+ console.error("Error accessing camera:", error);+ return null;+ }+ });const [cameraRef, setCameraRef] = createSignal<HTMLVideoElement>();@@ -161,13 +208,22 @@ function createCameraPreview(deviceId: () => string | undefined) {const ref = cameraRef();if (ref && stream) {- if (ref.srcObject === stream) return;- ref.srcObject = stream;- ref.play();+ if (ref.srcObject !== stream) {+ ref.srcObject = stream;+ ref.play().catch(console.error);+ }+ }+ });++ // Cleanup effect+ onCleanup(() => {+ const stream = cameraStream();+ if (stream) {+ stream.getTracks().forEach((track) => track.stop());}});- return [setCameraRef] as const;+ return [setCameraRef, () => cameraStream()] as const;}// {diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex 33552d455..69510354c 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -362,7 +362,7 @@ export type CursorType = "pointer" | "circle"export type Display = { path: string }export type DisplaySource = { variant: "screen" } | { variant: "window"; bounds: Bounds }export type EditorStateChanged = { playhead_position: number }-export type GeneralSettingsStore = { upload_individual_files: boolean }+export type GeneralSettingsStore = { upload_individual_files: boolean; open_editor_after_recording: boolean }export type Hotkey = { code: string; meta: boolean; ctrl: boolean; alt: boolean; shift: boolean }export type HotkeyAction = "startRecording" | "stopRecording" | "restartRecording" | "takeScreenshot"export type HotkeysConfiguration = { show: boolean }