Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Re-apply improvement and fix commits
Ilyac9885c67db0a
diff --git a/apps/desktop/src-tauri/src/app/commands.rs b/apps/desktop/src-tauri/src/app/commands.rsindex 9304b6723..ea9e16a49 100644--- a/apps/desktop/src-tauri/src/app/commands.rs+++ b/apps/desktop/src-tauri/src/app/commands.rs@@ -1,4 +1,4 @@-use tauri::Window;+use tauri::{Manager, Window};use tauri_plugin_oauth::start;macro_rules! generate_handler {@@ -93,3 +93,19 @@ pub fn reset_camera_permissions() {.spawn().expect("failed to reset camera permissions");}++#[tauri::command]+#[specta::specta]+pub fn close_webview(app_handle: tauri::AppHandle, label: String) -> bool {+ app_handle+ .get_window(&label)+ .is_some_and(|window| window.close().is_ok())+}++#[tauri::command]+#[specta::specta]+pub fn set_webview_shadow(app_handle: tauri::AppHandle, label: String, enable: bool) -> bool {+ app_handle+ .get_window(&label)+ .is_some_and(|window| window_shadows::set_shadow(window, enable).is_ok())+}diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rsindex cf7222109..ce0c6a860 100644--- a/apps/desktop/src-tauri/src/main.rs+++ b/apps/desktop/src-tauri/src/main.rs@@ -322,7 +322,9 @@ fn main() {has_screen_capture_access,reset_screen_permissions,reset_microphone_permissions,- reset_camera_permissions+ reset_camera_permissions,+ close_webview,+ set_webview_shadow]).plugin(tauri_plugin_context_menu::init())diff --git a/apps/desktop/src/app/camera/page.tsx b/apps/desktop/src/app/camera/page.tsxindex c13bcbc47..5dae5e6dc 100644--- a/apps/desktop/src/app/camera/page.tsx+++ b/apps/desktop/src/app/camera/page.tsx@@ -10,8 +10,8 @@ export default function CameraPage() {id="app"data-tauri-drag-regionstyle={{- borderRadius: "50%",- background: "none !important",+ border: "none",+ background: "none",outline: "none",boxShadow: "none",}}diff --git a/apps/desktop/src/app/page.tsx b/apps/desktop/src/app/page.tsxindex d8ac87c04..1d47dd939 100644--- a/apps/desktop/src/app/page.tsx+++ b/apps/desktop/src/app/page.tsx@@ -107,10 +107,12 @@ export default function CameraPage() {}, []);useEffect(() => {- if (isSignedIn && !cameraWindowOpen && permissions.confirmed === true) {- initializeCameraWindow();- setCameraWindowOpen(true);- }+ commands.closeWebview("camera").then(() => {+ if (isSignedIn && !cameraWindowOpen && permissions.confirmed === true) {+ initializeCameraWindow();+ setCameraWindowOpen(true);+ }+ });}, [isSignedIn, cameraWindowOpen, permissions.confirmed]);if (process.env.NEXT_PUBLIC_LOCAL_MODE === "true") {diff --git a/apps/desktop/src/components/icons/Expand.tsx b/apps/desktop/src/components/icons/Expand.tsxnew file mode 100644index 000000000..e4d122110--- /dev/null+++ b/apps/desktop/src/components/icons/Expand.tsx@@ -0,0 +1,19 @@+export const Expand = ({ className }: { className: string }) => {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ className={className}+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <path d="m21 21-6-6m6 6v-4.8m0 4.8h-4.8"/>+ <path d="M3 16.2V21m0 0h4.8M3 21l6-6"/>+ <path d="M21 7.8V3m0 0h-4.8M21 3l-6 6"/>+ <path d="M3 7.8V3m0 0h4.8M3 3l6 6"/>+ </svg>+ );+};\ No newline at end of filediff --git a/apps/desktop/src/components/icons/MicrophoneOff.tsx b/apps/desktop/src/components/icons/MicrophoneOff.tsxnew file mode 100644index 000000000..7706e84dd--- /dev/null+++ b/apps/desktop/src/components/icons/MicrophoneOff.tsx@@ -0,0 +1,21 @@+export const MicrophoneOff = ({ className }: { className: string }) => {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ className={className}+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <line x1="2" x2="22" y1="2" y2="22"/>+ <path d="M18.89 13.23A7.12 7.12 0 0 0 19 12v-2"/>+ <path d="M5 10v2a7 7 0 0 0 12 5"/>+ <path d="M15 9.34V5a3 3 0 0 0-5.68-1.33"/>+ <path d="M9 9v3a3 3 0 0 0 5.12 2.12"/>+ <line x1="12" x2="12" y1="19" y2="22"/>+ </svg>+ );+};diff --git a/apps/desktop/src/components/icons/Minimize.tsx b/apps/desktop/src/components/icons/Minimize.tsxnew file mode 100644index 000000000..1089a9457--- /dev/null+++ b/apps/desktop/src/components/icons/Minimize.tsx@@ -0,0 +1,19 @@+export const Minimize = ({ className }: { className: string }) => {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ className={className}+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <polyline points="4 14 10 14 10 20"/>+ <polyline points="20 10 14 10 14 4"/>+ <line x1="14" x2="21" y1="10" y2="3"/>+ <line x1="3" x2="10" y1="21" y2="14"/>+ </svg>+ );+};\ No newline at end of filediff --git a/apps/desktop/src/components/icons/Squircle.tsx b/apps/desktop/src/components/icons/Squircle.tsxnew file mode 100644index 000000000..5a96927c4--- /dev/null+++ b/apps/desktop/src/components/icons/Squircle.tsx@@ -0,0 +1,16 @@+export const Squircle = ({ className }: { className: string }) => {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className={className}+ >+ <path d="M12 3c7.2 0 9 1.8 9 9s-1.8 9-9 9-9-1.8-9-9 1.8-9 9-9" />+ </svg>+ );+};\ No newline at end of filediff --git a/apps/desktop/src/components/icons/VideoOff.tsx b/apps/desktop/src/components/icons/VideoOff.tsxnew file mode 100644index 000000000..0cb831928--- /dev/null+++ b/apps/desktop/src/components/icons/VideoOff.tsx@@ -0,0 +1,18 @@+export const VideoOff = ({ className }: { className: string }) => {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ className={className}+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <path d="M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196"/>+ <path d="M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2"/>+ <path d="m2 2 20 20"/>+ </svg>+ );+};\ No newline at end of filediff --git a/apps/desktop/src/components/windows/Camera.tsx b/apps/desktop/src/components/windows/Camera.tsxindex fd6cf7a26..d877b9de8 100644--- a/apps/desktop/src/components/windows/Camera.tsx+++ b/apps/desktop/src/components/windows/Camera.tsx@@ -1,15 +1,18 @@"use client";import React, { use, useEffect, useRef, useState } from "react";-import { useMediaDevices } from "@/utils/recording/MediaDeviceContext";+import { Device, useMediaDevices } from "@/utils/recording/MediaDeviceContext";import { CloseX } from "@/components/icons/CloseX";import { Flip } from "@/components/icons/Flip";import { emit } from "@tauri-apps/api/event";+import { Expand } from "../icons/Expand";+import { Minimize } from "../icons/Minimize";+import { Squircle } from "../icons/Squircle";export const Camera = () => {const videoRef = useRef<HTMLVideoElement>(null);const canvasRef = useRef<HTMLCanvasElement>(null);- const { selectedVideoDevice } = useMediaDevices();+ const { selectedVideoDevice, devices } = useMediaDevices();const [isLoading, setIsLoading] = useState(true);const tauriWindowImport = import("@tauri-apps/api/window");const [cameraMirrored, setCameraMirrored] = useState(@@ -17,6 +20,12 @@ export const Camera = () => {? localStorage.getItem("cameraMirrored") || "false": "false");+ const [overlaySize, setOverlaySize] = useState<"sm" | "lg">("sm");+ const [overlayShape, setOverlayShape] = useState<"round" | "square">(+ localStorage.getItem("cameraOverlayShape") as "round" | "square" || "round"+ );++ useEffect(() => localStorage.setItem("cameraOverlayShape", overlayShape), [overlayShape]);useEffect(() => {if (!videoRef.current || !selectedVideoDevice) return;@@ -69,8 +78,8 @@ export const Camera = () => {tauriWindowImport.then(({ currentMonitor, appWindow, LogicalSize, LogicalPosition }) => {currentMonitor().then((monitor) => {- const windowWidth = type === "sm" ? 230 : 400;- const windowHeight = type === "sm" ? 230 : 400;+ const windowWidth = type === "sm" ? 240 : 410;+ const windowHeight = type === "sm" ? 240 : 410;if (monitor && monitor.size) {const scalingFactor = monitor.scaleFactor;@@ -88,24 +97,23 @@ export const Camera = () => {appWindow.setSize(new LogicalSize(windowWidth, windowHeight));appWindow.setPosition(new LogicalPosition(x / scalingFactor, y));+ setOverlaySize(type);}});});};- const closeWindow = () => {+ const closeWindow = (emitSetDevice = true) => {if (typeof window === "undefined") return;tauriWindowImport.then(async ({ appWindow }) => {- await emit("change-device", {- type: "video",- device: {- label: "None",- index: -1,- kind: "video",- },- });+ if (emitSetDevice) {+ await emit("change-device", {+ type: "videoinput",+ device: null,+ });+ }appWindow.close();});};@@ -118,10 +126,60 @@ export const Camera = () => {}}, []);+ const getOverlayBorderRadius= () => {+ if (overlayShape === "round") return "9999px";+ if (overlaySize === "sm") return "3rem";+ else return "4rem";+ };++ const handleContextMenu = async () => {+ const { showMenu } = await import("tauri-plugin-context-menu");+ const videoDevices = devices.filter((device) => device.kind === "videoinput");++ const select = async (device: Device | null) => {+ emit("change-device", { type: "videoinput", device: device })+ .catch((error) => console.log("Failed to emit change-device event:", error));+ };++ const menuItems = [+ {+ label: "Select Video:",+ disabled: true,+ },+ ...videoDevices.map((device) => ({+ label: device.label,+ checked: selectedVideoDevice.index === device.index,+ event: async () => select(device),+ })),+ {+ is_separator: true,+ },+ {+ label: "Close Overlay",+ checked: selectedVideoDevice === null,+ event: async () => select(null),+ },+ ];++ await showMenu({+ items: [...menuItems],+ ...(videoDevices.length === 0 && {+ items: [+ { label: "Nothing found." },+ ],+ }),+ });+ }+return (<divdata-tauri-drag-region- className="cursor-move group w-full h-full bg-gray-200 rounded-full m-0 p-0 relative overflow-hidden flex items-center justify-center border-none outline-none focus:outline-none rounded-full"+ onContextMenu={(e) => {+ e.preventDefault();+ handleContextMenu();+ }}+ className="cursor-move group w-full h-full bg-gray-200 m-0 p-0 relative overflow-hidden flex items-center justify-center outline-none focus:outline-none border-2 border-sm border-gray-300"+ style={{ borderRadius: getOverlayBorderRadius() }}>{isLoading && (<div className="w-full h-full absolute top-0 left-0 bg-gray-200 z-10 flex items-center justify-center">@@ -152,7 +210,7 @@ export const Camera = () => {</svg></div>)}- <div className="opacity-0 group-hover:opacity-100 absolute top-3 left-1/2 transform -translate-x-1/2 bg-gray-800 rounded-xl z-20 grid grid-cols-4 overflow-hidden">+ <div className="opacity-0 group-hover:opacity-100 absolute top-5 left-1/2 transform -translate-x-1/2 bg-gray-800 bg-opacity-75 backdrop-blur-sm rounded-xl z-20 grid grid-cols-4 overflow-hidden transition-opacity"><divonClick={() => {closeWindow();@@ -165,19 +223,23 @@ export const Camera = () => {</div><divonClick={async () => {- await setWindowSize("sm");+ await setWindowSize(overlaySize === "sm" ? "lg" : "sm");}}className="h-full flex items-center justify-center p-2 hover:bg-gray-900">- <span className="w-1 h-1 m-0 p-0 bg-gray-200 rounded-full"></span>+ <div>+ {overlaySize === "sm" && <Expand className="w-5 h-5 stroke-gray-200" />}+ {overlaySize === "lg" && <Minimize className="w-5 h-5 stroke-gray-200" />}+ </div></div><div- onClick={async () => {- await setWindowSize("lg");+ onClick={() => {+ setOverlayShape(overlayShape === "round" ? "square" : "round");}}className="h-full flex items-center justify-center p-2 hover:bg-gray-900">- <span className="w-3 h-3 bg-gray-200 rounded-full"></span>+ {overlayShape === "round" && <div><Squircle className="w-5 h-5 stroke-gray-200" /></div>}+ {overlayShape === "square" && <span className="w-3 h-3 bg-gray-200 rounded-full"></span>}</div><divonClick={mirrorCamera}@@ -197,8 +259,9 @@ export const Camera = () => {autoPlayplaysInlinemuted- className="absolute top-0 left-0 w-full h-full object-cover pointer-events-none rounded-full"+ className={"absolute top-0 left-0 w-full h-full object-cover pointer-events-none"}+ style={{ borderRadius: getOverlayBorderRadius() }}/></div>);-};+};\ No newline at end of filediff --git a/apps/desktop/src/components/windows/inner/ActionSelect.tsx b/apps/desktop/src/components/windows/inner/ActionSelect.tsxnew file mode 100644index 000000000..52bb555f8--- /dev/null+++ b/apps/desktop/src/components/windows/inner/ActionSelect.tsx@@ -0,0 +1,66 @@+import React, { ReactNode, useRef, MouseEvent, useMemo, useState, useEffect } from "react";++export const ActionSelect = ({+ iconEnabled = null,+ iconDisabled = null,+ width = "auto",+ active = true,+ showStatus = false,+ status = "on",+ options = [],+ selectedValue = null,+ onSelect,+ onStatusClick,+}: {+ iconEnabled?: ReactNode;+ iconDisabled?: ReactNode;+ width?: "full" | "auto";+ active?: boolean;+ showStatus?: boolean;+ status: "on" | "off";+ options: { value: string | number; label: string; disabled?: boolean }[];+ selectedValue?: string | number;+ onSelect: (value: string | number) => void;+ onStatusClick?: (currentStatus: "on" | "off") => void;+}) => (+ <div className={`flex-grow ${width === "full" ? "w-full" : "w-auto"}`}>+ <div+ className={`+ ${active ? "bg-white hover:bg-gray-100" : "bg-gray-200 hover:bg-white"}+ border-gray-300 w-full h-[50px] py-2 px-4 text-[14px] border-2 flex items-center rounded-[15px] transition-all shadow-sm shadow-[0px 0px 180px rgba(255, 255, 255, 0.18)] cursor-pointer+ `}+ >+ <div className="flex items-center min-w-0 flex-grow h-full">+ <span className="flex-shrink-0 mr-2">{status === "off" && iconDisabled ? iconDisabled : iconEnabled}</span>+ <select+ className="bg-transparent border-none appearance-none w-full min-w-0 cursor-pointer h-full truncate"+ value={selectedValue || -1}+ onChange={(e) => onSelect(e.target.value)}+ >+ {options.map((option) => (+ <option key={option.value} value={option.value} disabled={option.disabled}>+ {option.label}+ </option>+ ))}+ </select>+ </div>+ {showStatus && (+ <div+ className={onStatusClick ? "transition-transform active:scale-95" : ""}+ onClick={(e) => {+ e.stopPropagation();+ onStatusClick?.(status);+ }}+ >+ <span+ className={`${+ status === "on" ? "bg-tertiary text-primary" : "bg-red-600 text-white"+ } h-5 w-8 font-medium text-xs rounded-full flex items-center justify-center`}+ >+ <span>{status === "on" ? "On" : "Off"}</span>+ </span>+ </div>+ )}+ </div>+ </div>+);\ No newline at end of filediff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsxindex bb76af7c7..e35620fc1 100644--- a/apps/desktop/src/components/windows/inner/Recorder.tsx+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx@@ -1,14 +1,18 @@"use client";import { useState, useEffect } from "react";-import { Device, useMediaDevices } from "@/utils/recording/MediaDeviceContext";+import { Device, DeviceKind, useMediaDevices } from "@/utils/recording/MediaDeviceContext";import { Video } from "@/components/icons/Video";import { Microphone } from "@/components/icons/Microphone";import { Screen } from "@/components/icons/Screen";import { Window } from "@/components/icons/Window";-import { ActionButton } from "@/components/windows/inner/ActionButton";+import { VideoOff } from "@/components/icons/VideoOff";+import { MicrophoneOff } from "@/components/icons/MicrophoneOff";+import { ActionButton } from "./ActionButton";+import { ActionSelect } from "./ActionSelect";import { Button } from "@cap/ui";import { Logo } from "@/components/icons/Logo";+import { emit, listen, UnlistenFn } from "@tauri-apps/api/event";import { invoke } from "@tauri-apps/api/tauri";import {@@ -49,64 +53,29 @@ export const Recorder = () => {const proCheckPromise = isUserPro();const [proCheck, setProCheck] = useState<boolean>(false);const [limitReached, setLimitReached] = useState(false);+ const [lastSelectedAudioDevice, setLastSelectedAudioDevice] = useState<Device | null>(null);+ const [lastSelectedVideoDevice, setLastSelectedVideoDevice] = useState<Device | null>(null);useEffect(() => {proCheckPromise.then((result) => setProCheck(Boolean(result)));}, [proCheckPromise]);- const handleContextClick = async (option: "video" | "audio") => {- const { showMenu } = await import("tauri-plugin-context-menu");- const deviceKind = option === "video" ? "videoinput" : "audioinput";- const isSelected = (device: Device | null) => {- if (device === null) {- return deviceKind === "videoinput"- ? selectedVideoDevice === null- : selectedAudioDevice === null;- }-- return deviceKind === "videoinput"- ? device.index === selectedVideoDevice?.index- : device.index === selectedAudioDevice?.index;- };- const select = async (device: Device | null) => {- // if (isSelected(device)) {- // return- // }- emit("change-device", { type: deviceKind, device: device }).catch(- (error) => {- console.log("Failed to emit change-device event:", error);- }- );- };-- const devicesOfKind = devices.filter(- (device) => device.kind === deviceKind- );-- const menuItems = [- {- label: "None",- checked: isSelected(null),- event: async () => select(null),- },- ...devicesOfKind.map((device) => ({- label: device.label,- checked: isSelected(device),- event: async () => select(device),- })),- ];-- await showMenu({- items: [...menuItems],- ...(devicesOfKind.length === 0 && {- items: [- {- label: "Nothing found.",- },- ],- }),- });- };+ const selectDevice = (kind: DeviceKind, device: Device | null) => emit(+ "change-device", { type: kind, device: device }+ ).catch((error) => console.log("Failed to emit change-device event:", error));++ const createDeviceMenuOptions = (kind: DeviceKind) => [+ { value: "_", label: `Select ${kind === "videoinput" ? "Video" : "Microphone"}`, disabled: true },+ { value: "none", label: `No ${kind === "videoinput" ? "Video" : "Audio"}` },+ ...devices.filter((device) => device.kind === kind).map(({ label }) => ({ value: label, label }))+ ]++ const handleSelectInputDevice = async (kind: DeviceKind, label: string) => {+ let device: Device | null = null;+ if (label !== "none")+ device = devices.find((device) => device.kind === kind && device.label === label) || null;+ selectDevice(kind, device);+ }const prepareVideoData = async () => {const session = JSON.parse(localStorage.getItem("session"));@@ -433,31 +402,31 @@ export const Recorder = () => {<div><label className="text-sm font-medium">Webcam / Video</label><div className="space-y-2">- <ActionButton- width="full"- handler={() => handleContextClick("video")}- icon={<Video className="w-5 h-5" />}- label={- devices.length === 0- ? "Video"- : selectedVideoDevice?.label || "None"- }- active={selectedVideoDevice !== null}- recordingOption={true}- optionName="Video"+ <ActionSelect+ options={createDeviceMenuOptions("videoinput")}+ onStatusClick={(status) => {+ setLastSelectedVideoDevice(selectedVideoDevice);+ selectDevice("videoinput", status === "on" ? null : lastSelectedVideoDevice);+ }}+ showStatus={true}+ status={selectedVideoDevice === null ? "off" : "on"}+ iconEnabled={<Video className="w-5 h-5" />}+ iconDisabled={<VideoOff className="w-5 h-5" />}+ selectedValue={selectedVideoDevice?.label}+ onSelect={(value) => handleSelectInputDevice("videoinput", value as string)}/>- <ActionButton- width="full"- handler={() => handleContextClick("audio")}- icon={<Microphone className="w-5 h-5" />}- label={- devices.length === 0- ? "Mic"- : selectedAudioDevice?.label || "None"- }- active={selectedAudioDevice !== null}- recordingOption={true}- optionName="Audio"+ <ActionSelect+ options={createDeviceMenuOptions("audioinput")}+ onStatusClick={(status) => {+ setLastSelectedAudioDevice(selectedAudioDevice);+ selectDevice("audioinput", status === "on" ? null : lastSelectedAudioDevice);+ }}+ showStatus={true}+ status={selectedAudioDevice === null ? "off" : "on"}+ iconEnabled={<Microphone className="w-5 h-5" />}+ iconDisabled={<MicrophoneOff className="w-5 h-5" />}+ selectedValue={selectedAudioDevice?.label}+ onSelect={(value) => handleSelectInputDevice("audioinput", value as string)}/></div></div>diff --git a/apps/desktop/src/utils/commands.ts b/apps/desktop/src/utils/commands.tsindex 8ef1f19a6..a1c64a93f 100644--- a/apps/desktop/src/utils/commands.ts+++ b/apps/desktop/src/utils/commands.ts@@ -54,4 +54,12 @@ export function resetCameraPermissions() {return invoke()<null>("reset_camera_permissions")}+export function closeWebview(label: string) {+ return invoke()<boolean>("close_webview", { label })+}++export function setWebviewShadow(label: string, enable: boolean) {+ return invoke()<boolean>("set_webview_shadow", { label,enable })+}+export type RecordingOptions = { user_id: string; video_id: string; screen_index: string; video_index: string; audio_name: string; aws_region: string; aws_bucket: string }diff --git a/apps/desktop/src/utils/recording/MediaDeviceContext.tsx b/apps/desktop/src/utils/recording/MediaDeviceContext.tsxindex ed9e70316..d4558fcba 100644--- a/apps/desktop/src/utils/recording/MediaDeviceContext.tsx+++ b/apps/desktop/src/utils/recording/MediaDeviceContext.tsx@@ -14,6 +14,7 @@ import {enumerateAndStoreDevices,initializeCameraWindow,} from "./utils";+import { closeWebview } from "../commands";export type DeviceKind = "videoinput" | "audioinput";export interface Device {@@ -87,16 +88,25 @@ export const MediaDeviceProvider: React.FC<React.PropsWithChildren<{}>> = ({// Automatically select the first available devices if not already selectedif (!selectedVideoDevice) {- const videoInput = formattedDevices.find(- (device) => device.kind === "videoinput"- );- setSelectedVideoDevice(videoInput || null);+ const storedVideoDevice = localStorage.getItem("selected-videoinput");+ let videoDevice: Device | null = null;+ if (storedVideoDevice && storedVideoDevice !== "none") {+ videoDevice = formattedDevices.find(+ (device) => device.kind === "videoinput" && device.label === storedVideoDevice+ );+ }+ setSelectedVideoDevice(videoDevice);}+if (!selectedAudioDevice) {- const audioInput = formattedDevices.find(- (device) => device.kind === "audioinput"- );- setSelectedAudioDevice(audioInput || null);+ const storedAudioDevice = localStorage.getItem("selected-audioinput");+ let audioDevice: Device | null = null;+ if (storedAudioDevice && storedAudioDevice !== "none") {+ audioDevice = formattedDevices.find(+ (device) => device.kind === "audioinput" && device.label === storedAudioDevice+ );+ }+ setSelectedAudioDevice(audioDevice);}} catch (error) {console.error("Failed to get media devices:", error);@@ -110,8 +120,8 @@ export const MediaDeviceProvider: React.FC<React.PropsWithChildren<{}>> = ({}}, []);- const updateSelectedDevice = (type: DeviceKind, device: Device | null) => {- if (!type) {+ const updateSelectedDevice = (kind: DeviceKind, device: Device | null) => {+ if (!kind) {return;}@@ -119,32 +129,26 @@ export const MediaDeviceProvider: React.FC<React.PropsWithChildren<{}>> = ({if (window.fathom !== undefined) {window.fathom.trackEvent(- `${type === "videoinput" ? "video" : "audio"}_device_change`+ `${kind === "videoinput" ? "video" : "audio"}_device_change`);}- if (type === "videoinput") {- tauriWindowImport.then(({ WebviewWindow }) => {- if (WebviewWindow.getByLabel("camera")) {- WebviewWindow.getByLabel("camera").close();- } else if (type === "videoinput" && device) {+ if (kind === "videoinput") {+ if (device?.label !== selectedVideoDevice?.label) {+ const previous = selectedVideoDevice;+ setSelectedVideoDevice(device);+ localStorage.setItem("selected-videoinput", device?.label || "none");+ if (!device) {+ closeWebview("camera");+ } else if (!previous && device) {initializeCameraWindow();}- });-- if (- (!device && selectedVideoDevice) ||- selectedVideoDevice?.index !== device?.index- ) {- setSelectedVideoDevice(device);}}- if (type === "audioinput") {- if (- (!device && selectedAudioDevice) ||- selectedAudioDevice?.index !== device?.index- ) {+ if (kind === "audioinput") {+ if (device?.label !== selectedAudioDevice?.label) {setSelectedAudioDevice(device);+ localStorage.setItem("selected-audioinput", device?.label || "none");}}};diff --git a/apps/desktop/src/utils/recording/utils.ts b/apps/desktop/src/utils/recording/utils.tsindex 2b42b2b75..ae33af061 100644--- a/apps/desktop/src/utils/recording/utils.ts+++ b/apps/desktop/src/utils/recording/utils.ts@@ -80,6 +80,8 @@ export const initializeCameraWindow = async () => {decorations: false,alwaysOnTop: true,center: false,+ }).once("tauri://created", () => {+ commands.setWebviewShadow("camera", false);});}}