Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop): compile cap-desktop and recording diagnostics on Linux
Richie McIlroy42717ea9593b
diff --git a/apps/desktop/src-tauri/src/thumbnails/linux.rs b/apps/desktop/src-tauri/src/thumbnails/linux.rsnew file mode 100644index 000000000..df6136851--- /dev/null+++ b/apps/desktop/src-tauri/src/thumbnails/linux.rs@@ -0,0 +1,47 @@+use cap_recording::screenshot::capture_screenshot;+use cap_recording::sources::screen_capture::ScreenCaptureTarget;+use image::{ImageEncoder, codecs::png::PngEncoder};+use std::io::Cursor;++use super::*;++pub async fn capture_display_thumbnail(display: &scap_targets::Display) -> Option<String> {+ capture_target_thumbnail(ScreenCaptureTarget::Display { id: display.id() }).await+}++pub async fn capture_window_thumbnail(window: &scap_targets::Window) -> Option<String> {+ capture_target_thumbnail(ScreenCaptureTarget::Window { id: window.id() }).await+}++async fn capture_target_thumbnail(target: ScreenCaptureTarget) -> Option<String> {+ let image = match capture_screenshot(target).await {+ Ok(image) => image,+ Err(error) => {+ warn!(error = %error, "Failed to capture thumbnail on Linux");+ return None;+ }+ };++ let rgba = image.to_rgba8();+ if rgba.width() == 0 || rgba.height() == 0 {+ return None;+ }++ let thumbnail = normalize_thumbnail_dimensions(&rgba);+ let mut png_data = Cursor::new(Vec::new());+ let encoder = PngEncoder::new(&mut png_data);+ if let Err(error) = encoder.write_image(+ thumbnail.as_raw(),+ thumbnail.width(),+ thumbnail.height(),+ image::ColorType::Rgba8.into(),+ ) {+ warn!(error = %error, "Failed to encode Linux thumbnail as PNG");+ return None;+ }++ Some(base64::Engine::encode(+ &base64::engine::general_purpose::STANDARD,+ png_data.into_inner(),+ ))+}diff --git a/apps/desktop/src-tauri/src/thumbnails/mod.rs b/apps/desktop/src-tauri/src/thumbnails/mod.rsindex c40f67c23..085ed5e25 100644--- a/apps/desktop/src-tauri/src/thumbnails/mod.rs+++ b/apps/desktop/src-tauri/src/thumbnails/mod.rs@@ -13,6 +13,11 @@ mod mac;#[cfg(target_os = "macos")]pub use mac::*;+#[cfg(target_os = "linux")]+mod linux;+#[cfg(target_os = "linux")]+pub use linux::*;+const THUMBNAIL_WIDTH: u32 = 320;const THUMBNAIL_HEIGHT: u32 = 180;diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rsindex b5e74f07b..edb78ff3a 100644--- a/apps/desktop/src-tauri/src/windows.rs+++ b/apps/desktop/src-tauri/src/windows.rs@@ -87,6 +87,19 @@ fn is_system_dark_mode() -> bool {false}+#[cfg(target_os = "linux")]+fn is_system_dark_mode() -> bool {+ let output = std::process::Command::new("gsettings")+ .args(["get", "org.gnome.desktop.interface", "color-scheme"])+ .output();+ if let Ok(output) = output+ && output.status.success()+ {+ return String::from_utf8_lossy(&output.stdout).contains("dark");+ }+ false+}+pub fn hide_overlay(window: &WebviewWindow) {let _ = window.set_ignore_cursor_events(true);let _ = window.hide();@@ -2218,6 +2231,9 @@ impl ShowCapWindow {#[cfg(windows)]let position = display.raw_handle().physical_position().unwrap();+ #[cfg(target_os = "linux")]+ let position = display.raw_handle().physical_position().unwrap();+let bounds = display.physical_size().unwrap();let mut window_builder = self@@ -2355,6 +2371,25 @@ impl ShowCapWindow {)).build()?;+ #[cfg(target_os = "linux")]+ let window = self+ .window_builder(app, "/in-progress-recording")+ .maximized(false)+ .resizable(false)+ .fullscreen(false)+ .shadow(false)+ .always_on_top(true)+ .transparent(true)+ .visible_on_all_workspaces(true)+ .content_protected(should_protect)+ .inner_size(width, height)+ .skip_taskbar(false)+ .initialization_script(format!(+ "window.COUNTDOWN = {};",+ countdown.unwrap_or_default()+ ))+ .build()?;+lock_window_text_scale(&window);#[cfg(target_os = "windows")]@@ -2984,6 +3019,30 @@ impl MonitorExt for Display {.into_iter().any(|(x, y)| x >= left && x < right && y >= top && y < bottom)}++ #[cfg(target_os = "linux")]+ {+ let Some(bounds) = self.raw_handle().physical_bounds() else {+ return false;+ };++ let left = bounds.position().x() as i32;+ let right = left + bounds.size().width() as i32;+ let top = bounds.position().y() as i32;+ let bottom = top + bounds.size().height() as i32;++ [+ (position.x, position.y),+ (position.x + size.width as i32, position.y),+ (position.x, position.y + size.height as i32),+ (+ position.x + size.width as i32,+ position.y + size.height as i32,+ ),+ ]+ .into_iter()+ .any(|(x, y)| x >= left && x < right && y >= top && y < bottom)+ }}}diff --git a/crates/recording/src/diagnostics.rs b/crates/recording/src/diagnostics.rsindex 3e00114e0..c9b9c3a1d 100644--- a/crates/recording/src/diagnostics.rs+++ b/crates/recording/src/diagnostics.rs@@ -536,8 +536,91 @@ mod macos_impl {}}+#[cfg(target_os = "linux")]+mod linux_impl {+ use super::*;++ #[derive(Debug, Clone, Serialize, Type)]+ #[serde(rename_all = "camelCase")]+ pub struct SystemDiagnostics {+ pub kernel_version: Option<String>,+ pub available_encoders: Vec<String>,+ pub screen_capture_supported: bool,+ pub gpu_name: Option<String>,+ }++ pub fn collect_diagnostics() -> SystemDiagnostics {+ let kernel_version = get_kernel_version();+ let available_encoders = get_available_encoders();+ let gpu_name = get_gpu_name();++ tracing::info!("System Diagnostics:");+ if let Some(ref version) = kernel_version {+ tracing::info!(" Kernel: {}", version);+ }+ if let Some(ref gpu) = gpu_name {+ tracing::info!(" GPU: {}", gpu);+ }+ tracing::info!(" Encoders: {:?}", available_encoders);++ SystemDiagnostics {+ kernel_version,+ available_encoders,+ screen_capture_supported: true,+ gpu_name,+ }+ }++ fn get_kernel_version() -> Option<String> {+ std::fs::read_to_string("/proc/sys/kernel/osrelease")+ .ok()+ .map(|value| value.trim().to_string())+ .filter(|value| !value.is_empty())+ }++ fn get_gpu_name() -> Option<String> {+ let output = std::process::Command::new("glxinfo")+ .arg("-B")+ .output()+ .ok()?;+ if !output.status.success() {+ return None;+ }++ String::from_utf8_lossy(&output.stdout)+ .lines()+ .find_map(|line| {+ line.trim()+ .strip_prefix("OpenGL renderer string:")+ .map(|name| name.trim().to_string())+ })+ .filter(|name| !name.is_empty())+ }++ fn get_available_encoders() -> Vec<String> {+ let candidates = [+ "h264_nvenc",+ "h264_vaapi",+ "h264_qsv",+ "libx264",+ "hevc_nvenc",+ "hevc_vaapi",+ "libx265",+ ];++ candidates+ .iter()+ .filter(|name| ffmpeg::encoder::find_by_name(name).is_some())+ .map(|s| s.to_string())+ .collect()+ }+}+#[cfg(target_os = "windows")]pub use windows_impl::*;#[cfg(target_os = "macos")]pub use macos_impl::*;++#[cfg(target_os = "linux")]+pub use linux_impl::*;