Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): add camera format and microphone info Tauri commands
Richie McIlroy86629f2146c8
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex 8381ce3cc..697c3f65e 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -2657,6 +2657,8 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {recording::delete_recording,recording::take_screenshot,recording::list_cameras,+ recording::get_camera_formats,+ recording::get_microphone_info,recording::list_capture_windows,recording::list_capture_displays,recording::list_displays_with_thumbnails,diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rsindex 16793518b..c83923a7c 100644--- a/apps/desktop/src-tauri/src/recording.rs+++ b/apps/desktop/src-tauri/src/recording.rs@@ -291,6 +291,104 @@ pub fn list_cameras() -> Vec<cap_camera::CameraInfo> {cap_camera::list_cameras().collect()}+#[derive(Debug, Clone, serde::Serialize, specta::Type)]+#[serde(rename_all = "camelCase")]+pub struct CameraFormatInfo {+ pub width: u32,+ pub height: u32,+ pub frame_rate: f32,+}++#[derive(Debug, Clone, serde::Serialize, specta::Type)]+#[serde(rename_all = "camelCase")]+pub struct CameraWithFormats {+ pub device_id: String,+ pub display_name: String,+ pub model_id: Option<String>,+ pub formats: Vec<CameraFormatInfo>,+ pub best_format: Option<CameraFormatInfo>,+}++fn get_best_format(formats: &[CameraFormatInfo]) -> Option<CameraFormatInfo> {+ formats+ .iter()+ .filter(|f| f.frame_rate >= 24.0 && f.frame_rate <= 60.0)+ .max_by(|a, b| {+ let res_a = a.width * a.height;+ let res_b = b.width * b.height;+ res_a.cmp(&res_b)+ })+ .or_else(|| {+ formats.iter().max_by(|a, b| {+ let res_a = a.width * a.height;+ let res_b = b.width * b.height;+ res_a.cmp(&res_b)+ })+ })+ .cloned()+}++#[tauri::command(async)]+#[specta::specta]+pub fn get_camera_formats(device_id: String) -> Option<CameraWithFormats> {+ if !permissions::do_permissions_check(false).camera.permitted() {+ return None;+ }++ cap_camera::list_cameras()+ .find(|c| c.device_id() == device_id)+ .map(|camera| {+ let formats: Vec<CameraFormatInfo> = camera+ .formats()+ .unwrap_or_default()+ .into_iter()+ .map(|f| CameraFormatInfo {+ width: f.width(),+ height: f.height(),+ frame_rate: f.frame_rate(),+ })+ .collect();++ let best_format = get_best_format(&formats);++ CameraWithFormats {+ device_id: camera.device_id().to_string(),+ display_name: camera.display_name().to_string(),+ model_id: camera.model_id().map(|m| m.to_string()),+ formats,+ best_format,+ }+ })+}++#[derive(Debug, Clone, serde::Serialize, specta::Type)]+#[serde(rename_all = "camelCase")]+pub struct MicrophoneInfo {+ pub name: String,+ pub sample_rate: u32,+ pub channels: u16,+}++#[tauri::command(async)]+#[specta::specta]+pub fn get_microphone_info(name: String) -> Option<MicrophoneInfo> {+ if !permissions::do_permissions_check(false)+ .microphone+ .permitted()+ {+ return None;+ }++ microphone::MicrophoneFeed::list()+ .into_iter()+ .find(|(n, _)| *n == name)+ .map(|(name, (_device, config))| MicrophoneInfo {+ name,+ sample_rate: config.sample_rate().0,+ channels: config.channels(),+ })+}+#[tauri::command]#[specta::specta]#[instrument]diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex ed5c7d3c0..1fa78bfeb 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -47,6 +47,12 @@ async takeScreenshot(target: ScreenCaptureTarget) : Promise<string> {async listCameras() : Promise<CameraInfo[]> {return await TAURI_INVOKE("list_cameras");},+async getCameraFormats(deviceId: string) : Promise<CameraWithFormats | null> {+ return await TAURI_INVOKE("get_camera_formats", { deviceId });+},+async getMicrophoneInfo(name: string) : Promise<MicrophoneInfo | null> {+ return await TAURI_INVOKE("get_microphone_info", { name });+},async listCaptureWindows() : Promise<CaptureWindow[]> {return await TAURI_INVOKE("list_capture_windows");},@@ -408,11 +414,13 @@ export type BackgroundConfiguration = { source: BackgroundSource; blur: number;export type BackgroundSource = { type: "wallpaper"; path: string | null } | { type: "image"; path: string | null } | { type: "color"; value: [number, number, number]; alpha?: number } | { type: "gradient"; from: [number, number, number]; to: [number, number, number]; angle?: number }export type BorderConfiguration = { enabled: boolean; width: number; color: [number, number, number]; opacity: number }export type Camera = { hide: boolean; mirror: boolean; position: CameraPosition; size: number; zoomSize: number | null; rounding: number; shadow: number; advancedShadow: ShadowConfiguration | null; shape: CameraShape; roundingType: CornerStyle; scaleDuringZoom?: number }+export type CameraFormatInfo = { width: number; height: number; frameRate: number }export type CameraInfo = { device_id: string; model_id: ModelIDType | null; display_name: string }export type CameraPosition = { x: CameraXPosition; y: CameraYPosition }export type CameraPreviewShape = "round" | "square" | "full"export type CameraPreviewState = { size: number; shape: CameraPreviewShape; mirrored: boolean }export type CameraShape = "square" | "source"+export type CameraWithFormats = { deviceId: string; displayName: string; modelId: string | null; formats: CameraFormatInfo[]; bestFormat: CameraFormatInfo | null }export type CameraXPosition = "left" | "center" | "right"export type CameraYPosition = "top" | "bottom"export type CaptionData = { segments: CaptionSegment[]; settings: CaptionSettings | null }@@ -486,6 +494,7 @@ export type MaskScalarKeyframe = { time: number; value: number }export type MaskSegment = { start: number; end: number; enabled?: boolean; maskType: MaskKind; center: XY<number>; size: XY<number>; feather?: number; opacity?: number; pixelation?: number; darkness?: number; fadeDuration?: number; keyframes?: MaskKeyframes }export type MaskType = "blur" | "pixelate"export type MaskVectorKeyframe = { time: number; x: number; y: number }+export type MicrophoneInfo = { name: string; sampleRate: number; channels: number }export type ModelIDType = stringexport type Mp4ExportSettings = { fps: number; resolution_base: XY<number>; compression: ExportCompression; custom_bpp: number | null; force_ffmpeg_decoder?: boolean }export type MultipleSegment = { display: VideoMeta; camera?: VideoMeta | null; mic?: AudioMeta | null; system_audio?: AudioMeta | null; cursor?: string | null }