Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Improved thumbnail creation

Richie McIlroyaa00a1a3b1c4
diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock
index 785caaae0..9799f400a 100644
--- a/apps/desktop/src-tauri/Cargo.lock
+++ b/apps/desktop/src-tauri/Cargo.lock
@@ -500,6 +500,7 @@ dependencies = [
"dotenv_codegen",
"ffmpeg-sidecar",
"futures",
+ "image",
"regex",
"reqwest",
"serde",
@@ -1647,9 +1648,9 @@ dependencies = [
[[package]]
name = "gif"
-version = "0.12.0"
+version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045"
+checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2"
dependencies = [
"color_quant",
"weezl",
@@ -2055,9 +2056,9 @@ dependencies = [
[[package]]
name = "image"
-version = "0.24.8"
+version = "0.24.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "034bbe799d1909622a74d1193aa50147769440040ff36cb2baa947609b0a4e23"
+checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d"
dependencies = [
"bytemuck",
"byteorder",
diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml
index 7680278dc..f8d5942cf 100644
--- a/apps/desktop/src-tauri/Cargo.toml
+++ b/apps/desktop/src-tauri/Cargo.toml
@@ -35,6 +35,7 @@ byteorder = "1.4.3"
bytemuck = "1.14.3"
regex = "1"
capture = { path = "./src/capture" }
+image = "0.24.9"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
diff --git a/apps/desktop/src-tauri/src/media.rs b/apps/desktop/src-tauri/src/media.rs
index 6538514eb..bb9f1d90d 100644
--- a/apps/desktop/src-tauri/src/media.rs
+++ b/apps/desktop/src-tauri/src/media.rs
@@ -5,6 +5,9 @@ use byteorder::{ByteOrder, LittleEndian};
use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
use std::io::{ErrorKind::WouldBlock, Error};
use std::time::{Instant, Duration};
+use std::fs::File;
+use std::path::Path;
+use image::{ImageBuffer, Rgba};
use tokio::io::{AsyncWriteExt};
use tokio::process::{Command, Child, ChildStdin};
@@ -50,7 +53,7 @@ impl MediaRecorder {
}
}
- pub async fn start_media_recording(&mut self, options: RecordingOptions, audio_file_path: &str, video_file_path: &str, custom_device: Option<&str>) -> Result<(), String> {
+ pub async fn start_media_recording(&mut self, options: RecordingOptions, audio_file_path: &str, video_file_path: &str, screenshot_file_path: &str, custom_device: Option<&str>) -> Result<(), String> {
self.options = Some(options);
let host = cpal::default_host();
@@ -134,124 +137,129 @@ impl MediaRecorder {
eprintln!("an error occurred on stream: {}", err);
};
- println!("Building input stream...");
-
- let stream_result: Result<cpal::Stream, cpal::BuildStreamError> = match config.sample_format() {
- SampleFormat::I8 => device.build_input_stream(
- &config.into(),
- {
- let audio_start_time = Arc::clone(&audio_start_time);
- move |data: &[i8], _: &_| {
- let mut first_frame_time_guard = audio_start_time.try_lock();
-
- let bytes = data.iter().map(|&sample| sample as u8).collect::<Vec<u8>>();
- if let Some(sender) = &audio_channel_sender {
- if sender.try_send(bytes).is_err() {
- eprintln!("Channel send error. Dropping data.");
- }
- }
-
- if let Ok(ref mut start_time_option) = first_frame_time_guard {
- if start_time_option.is_none() {
- **start_time_option = Some(Instant::now());
+ if custom_device != Some("None") {
+ println!("Building input stream...");
+
+ let stream_result: Result<cpal::Stream, cpal::BuildStreamError> = match config.sample_format() {
+ SampleFormat::I8 => device.build_input_stream(
+ &config.into(),
+ {
+ let audio_start_time = Arc::clone(&audio_start_time);
+ move |data: &[i8], _: &_| {
+ let mut first_frame_time_guard = audio_start_time.try_lock();
+
+ let bytes = data.iter().map(|&sample| sample as u8).collect::<Vec<u8>>();
+ if let Some(sender) = &audio_channel_sender {
+ if sender.try_send(bytes).is_err() {
+ eprintln!("Channel send error. Dropping data.");
+ }
+ }
+
+ if let Ok(ref mut start_time_option) = first_frame_time_guard {
+ if start_time_option.is_none() {
+ **start_time_option = Some(Instant::now());
- println!("Audio start time captured");
+ println!("Audio start time captured");
+ }
}
}
- }
- },
- err_fn,
- None,
- ),
- SampleFormat::I16 => device.build_input_stream(
- &config.into(),
- {
- let audio_start_time = Arc::clone(&audio_start_time);
- move |data: &[i16], _: &_| {
- let mut first_frame_time_guard = audio_start_time.try_lock();
-
- let mut bytes = vec![0; data.len() * 2];
- LittleEndian::write_i16_into(data, &mut bytes);
- if let Some(sender) = &audio_channel_sender {
- if sender.try_send(bytes).is_err() {
- eprintln!("Channel send error. Dropping data.");
+ },
+ err_fn,
+ None,
+ ),
+ SampleFormat::I16 => device.build_input_stream(
+ &config.into(),
+ {
+ let audio_start_time = Arc::clone(&audio_start_time);
+ move |data: &[i16], _: &_| {
+ let mut first_frame_time_guard = audio_start_time.try_lock();
+
+ let mut bytes = vec![0; data.len() * 2];
+ LittleEndian::write_i16_into(data, &mut bytes);
+ if let Some(sender) = &audio_channel_sender {
+ if sender.try_send(bytes).is_err() {
+ eprintln!("Channel send error. Dropping data.");
+ }
}
- }
- if let Ok(ref mut start_time_option) = first_frame_time_guard {
- if start_time_option.is_none() {
- **start_time_option = Some(Instant::now());
+ if let Ok(ref mut start_time_option) = first_frame_time_guard {
+ if start_time_option.is_none() {
+ **start_time_option = Some(Instant::now());
- println!("Audio start time captured");
+ println!("Audio start time captured");
+ }
}
}
- }
- },
- err_fn,
- None,
- ),
- SampleFormat::I32 => device.build_input_stream(
- &config.into(),
- {
- let audio_start_time = Arc::clone(&audio_start_time);
- move |data: &[i32], _: &_| {
- let mut first_frame_time_guard = audio_start_time.try_lock();
-
- let mut bytes = vec![0; data.len() * 2];
- LittleEndian::write_i32_into(data, &mut bytes);
- if let Some(sender) = &audio_channel_sender {
- if sender.try_send(bytes).is_err() {
- eprintln!("Channel send error. Dropping data.");
+ },
+ err_fn,
+ None,
+ ),
+ SampleFormat::I32 => device.build_input_stream(
+ &config.into(),
+ {
+ let audio_start_time = Arc::clone(&audio_start_time);
+ move |data: &[i32], _: &_| {
+ let mut first_frame_time_guard = audio_start_time.try_lock();
+
+ let mut bytes = vec![0; data.len() * 2];
+ LittleEndian::write_i32_into(data, &mut bytes);
+ if let Some(sender) = &audio_channel_sender {
+ if sender.try_send(bytes).is_err() {
+ eprintln!("Channel send error. Dropping data.");
+ }
}
- }
- if let Ok(ref mut start_time_option) = first_frame_time_guard {
- if start_time_option.is_none() {
- **start_time_option = Some(Instant::now());
+ if let Ok(ref mut start_time_option) = first_frame_time_guard {
+ if start_time_option.is_none() {
+ **start_time_option = Some(Instant::now());
- println!("Audio start time captured");
+ println!("Audio start time captured");
+ }
}
}
- }
- },
- err_fn,
- None,
- ),
- SampleFormat::F32 => device.build_input_stream(
- &config.into(),
- {
- let audio_start_time = Arc::clone(&audio_start_time);
- move |data: &[f32], _: &_| {
- let mut first_frame_time_guard = audio_start_time.try_lock();
-
- let mut bytes = vec![0; data.len() * 4];
- LittleEndian::write_f32_into(data, &mut bytes);
- if let Some(sender) = &audio_channel_sender {
- if sender.try_send(bytes).is_err() {
- eprintln!("Channel send error. Dropping data.");
+ },
+ err_fn,
+ None,
+ ),
+ SampleFormat::F32 => device.build_input_stream(
+ &config.into(),
+ {
+ let audio_start_time = Arc::clone(&audio_start_time);
+ move |data: &[f32], _: &_| {
+ let mut first_frame_time_guard = audio_start_time.try_lock();
+
+ let mut bytes = vec![0; data.len() * 4];
+ LittleEndian::write_f32_into(data, &mut bytes);
+ if let Some(sender) = &audio_channel_sender {
+ if sender.try_send(bytes).is_err() {
+ eprintln!("Channel send error. Dropping data.");
+ }
}
- }
- if let Ok(ref mut start_time_option) = first_frame_time_guard {
- if start_time_option.is_none() {
- **start_time_option = Some(Instant::now());
+ if let Ok(ref mut start_time_option) = first_frame_time_guard {
+ if start_time_option.is_none() {
+ **start_time_option = Some(Instant::now());
- println!("Audio start time captured");
+ println!("Audio start time captured");
+ }
}
}
- }
- },
- err_fn,
- None,
- ),
- _sample_format => Err(cpal::BuildStreamError::DeviceNotAvailable),
- };
-
- let stream = stream_result.map_err(|_| "Failed to build input stream")?;
- self.stream = Some(stream);
- self.trigger_play()?;
+ },
+ err_fn,
+ None,
+ ),
+ _sample_format => Err(cpal::BuildStreamError::DeviceNotAvailable),
+ };
+
+ let stream = stream_result.map_err(|_| "Failed to build input stream")?;
+ self.stream = Some(stream);
+ self.trigger_play()?;
+ }
let video_start_time_clone = Arc::clone(&video_start_time);
+ let screenshot_file_path_owned = format!("{}/screen-capture.jpg", screenshot_file_path);
+ let capture_frame_at = Duration::from_secs(3);
+
std::thread::spawn(move || {
println!("Starting video recording capture thread...");
@@ -263,11 +271,28 @@ impl MediaRecorder {
let mut frame_count = 0u32;
let start_time = Instant::now();
let mut time_next = Instant::now() + spf;
+ let mut screenshot_captured: bool = false;
while !should_stop.load(Ordering::SeqCst) {
let now = Instant::now();
if now >= time_next {
+
+ if now - start_time >= capture_frame_at && !screenshot_captured {
+ if let Ok(frame) = capturer.frame() {
+ screenshot_captured = true;
+ let path = Path::new(&screenshot_file_path_owned);
+ let image: ImageBuffer<Rgba<u8>, Vec<u8>> = ImageBuffer::from_raw(
+ w.try_into().unwrap(),
+ adjusted_height.try_into().unwrap(),
+ frame.to_vec()
+ ).expect("Failed to create image buffer");
+ image.save_with_format(&path, image::ImageFormat::Jpeg).expect("Failed to save screenshot");
+
+ println!("Screenshot captured and saved to {:?}", path);
+ }
+ }
+
let mut frame_data = Vec::with_capacity(capture_size);
match capturer.frame() {
@@ -335,8 +360,6 @@ impl MediaRecorder {
audio_filters.push("loudnorm");
- let audio_filters_str = audio_filters.join(",");
-
let mut ffmpeg_audio_command: Vec<String> = vec![
"-f", sample_format,
"-ar", &sample_rate_str,
@@ -375,21 +398,32 @@ impl MediaRecorder {
&video_output_chunk_pattern,
].into_iter().map(|s| s.to_string()).collect();
- println!("Adjusting FFmpeg commands based on start times...");
- adjust_ffmpeg_commands_based_on_start_times(
- Arc::clone(&audio_start_time),
- Arc::clone(&video_start_time),
- &mut ffmpeg_audio_command,
- &mut ffmpeg_video_command,
- ).await;
+ if custom_device != Some("None") {
+ println!("Adjusting FFmpeg commands based on start times...");
+ adjust_ffmpeg_commands_based_on_start_times(
+ Arc::clone(&audio_start_time),
+ Arc::clone(&video_start_time),
+ &mut ffmpeg_audio_command,
+ &mut ffmpeg_video_command,
+ ).await;
+ }
println!("Starting FFmpeg audio and video processes...");
- let ((audio_child, audio_stdin), (video_child, video_stdin)) = self.start_ffmpeg_processes(&ffmpeg_binary_path_str, &ffmpeg_audio_command, &ffmpeg_video_command).await.map_err(|e| e.to_string())?;
+ let mut audio_stdin: Option<ChildStdin> = None;
+ let mut audio_child: Option<Child> = None;
+
+ if custom_device != Some("None") {
+ let (child, stdin) = self.start_audio_ffmpeg_processes(&ffmpeg_binary_path_str, &ffmpeg_audio_command).await.map_err(|e| e.to_string())?;
+ audio_child = Some(child);
+ audio_stdin = Some(stdin);
+ }
+
+ let (video_child, video_stdin) = self.start_video_ffmpeg_processes(&ffmpeg_binary_path_str, &ffmpeg_video_command).await.map_err(|e| e.to_string())?;
if let Some(ffmpeg_audio_stdin) = &self.ffmpeg_audio_stdin {
let mut audio_stdin_lock = ffmpeg_audio_stdin.lock().await;
- *audio_stdin_lock = Some(audio_stdin);
+ *audio_stdin_lock = audio_stdin;
drop(audio_stdin_lock);
}
@@ -399,17 +433,19 @@ impl MediaRecorder {
drop(video_stdin_lock);
}
- tokio::spawn(async move {
- while let Some(bytes) = &audio_channel_receiver.lock().await.as_mut().unwrap().recv().await {
- if let Some(audio_stdin_arc) = &ffmpeg_audio_stdin{
- let mut audio_stdin_guard = audio_stdin_arc.lock().await;
- if let Some(ref mut stdin) = *audio_stdin_guard {
- stdin.write_all(&bytes).await.expect("Failed to write audio data to FFmpeg stdin");
+ if custom_device != Some("None") {
+ tokio::spawn(async move {
+ while let Some(bytes) = &audio_channel_receiver.lock().await.as_mut().unwrap().recv().await {
+ if let Some(audio_stdin_arc) = &ffmpeg_audio_stdin{
+ let mut audio_stdin_guard = audio_stdin_arc.lock().await;
+ if let Some(ref mut stdin) = *audio_stdin_guard {
+ stdin.write_all(&bytes).await.expect("Failed to write audio data to FFmpeg stdin");
+ }
+ drop(audio_stdin_guard);
}
- drop(audio_stdin_guard);
}
- }
- });
+ });
+ }
tokio::spawn(async move {
while let Some(bytes) = &video_channel_receiver.lock().await.as_mut().unwrap().recv().await {
@@ -423,7 +459,10 @@ impl MediaRecorder {
}
});
- self.ffmpeg_audio_process = Some(audio_child);
+ if custom_device != Some("None") {
+ self.ffmpeg_audio_process = audio_child;
+ }
+
self.ffmpeg_video_process = Some(video_child);
self.device_name = Some(device.name().expect("Failed to get device name"));
@@ -437,7 +476,7 @@ impl MediaRecorder {
stream.play().map_err(|_| "Failed to play stream")?;
println!("Audio recording playing.");
} else {
- return Err("Recording was not started");
+ return Err("Starting the recording did not work");
}
Ok(())
@@ -472,7 +511,7 @@ impl MediaRecorder {
stream.pause().map_err(|_| "Failed to pause stream")?;
println!("Audio recording paused.");
} else {
- return Err("Recording was not started".to_string());
+ return Err("Original recording was not started".to_string());
}
if let Some(process) = &mut self.ffmpeg_audio_process {
@@ -487,19 +526,28 @@ impl MediaRecorder {
Ok(())
}
- async fn start_ffmpeg_processes(
+ async fn start_audio_ffmpeg_processes(
&self,
ffmpeg_binary_path: &str,
audio_ffmpeg_command: &[String],
- video_ffmpeg_command: &[String],
- ) -> Result<((Child, ChildStdin), (Child, ChildStdin)), Error> {
+ ) -> Result<((Child, ChildStdin)), Error> {
let mut audio_process = start_recording_process(ffmpeg_binary_path, audio_ffmpeg_command).await.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
- let mut video_process = start_recording_process(ffmpeg_binary_path, video_ffmpeg_command).await.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
let audio_stdin = audio_process.stdin.take().ok_or_else(|| std::io::Error::new(std::io::ErrorKind::Other, "Failed to take audio stdin"))?;
+
+ Ok(((audio_process, audio_stdin)))
+ }
+
+ async fn start_video_ffmpeg_processes(
+ &self,
+ ffmpeg_binary_path: &str,
+ video_ffmpeg_command: &[String],
+ ) -> Result<((Child, ChildStdin)), Error> {
+ let mut video_process = start_recording_process(ffmpeg_binary_path, video_ffmpeg_command).await.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
+
let video_stdin = video_process.stdin.take().ok_or_else(|| std::io::Error::new(std::io::ErrorKind::Other, "Failed to take video stdin"))?;
- Ok(((audio_process, audio_stdin), (video_process, video_stdin)))
+ Ok(((video_process, video_stdin)))
}
}
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rs
index de27df433..dfcc8cdd0 100644
--- a/apps/desktop/src-tauri/src/recording.rs
+++ b/apps/desktop/src-tauri/src/recording.rs
@@ -57,8 +57,11 @@ pub async fn start_dual_recording(
let audio_chunks_dir = data_dir.join("chunks/audio");
let video_chunks_dir = data_dir.join("chunks/video");
+ let screenshot_dir = data_dir.join("screenshots");
+
clean_and_create_dir(&audio_chunks_dir)?;
clean_and_create_dir(&video_chunks_dir)?;
+ clean_and_create_dir(&screenshot_dir)?;
let audio_name = if options.audio_name.is_empty() {
None
@@ -66,7 +69,7 @@ pub async fn start_dual_recording(
Some(options.audio_name.clone())
};
- let media_recording_preparation = prepare_media_recording(&options, &audio_chunks_dir, &video_chunks_dir, audio_name);
+ let media_recording_preparation = prepare_media_recording(&options, &audio_chunks_dir, &video_chunks_dir, &screenshot_dir, audio_name);
let media_recording_result = media_recording_preparation.await.map_err(|e| e.to_string())?;
state_guard.media_process = Some(media_recording_result);
@@ -76,8 +79,8 @@ pub async fn start_dual_recording(
state_guard.video_uploading_finished = Arc::new(AtomicBool::new(false));
state_guard.audio_uploading_finished = Arc::new(AtomicBool::new(false));
- let screen_upload = start_upload_loop(video_chunks_dir.clone(), options.clone(), "video".to_string(), shutdown_flag.clone(), state_guard.video_uploading_finished.clone());
- let audio_upload = start_upload_loop(audio_chunks_dir, options.clone(), "audio".to_string(), shutdown_flag.clone(), state_guard.audio_uploading_finished.clone());
+ let screen_upload = start_upload_loop(video_chunks_dir.clone(), Some(screenshot_dir.clone()), options.clone(), "video".to_string(), shutdown_flag.clone(), state_guard.video_uploading_finished.clone());
+ let audio_upload = start_upload_loop(audio_chunks_dir, None, options.clone(), "audio".to_string(), shutdown_flag.clone(), state_guard.audio_uploading_finished.clone());
drop(state_guard);
@@ -127,19 +130,24 @@ fn clean_and_create_dir(dir: &Path) -> Result<(), String> {
}
std::fs::create_dir_all(dir).map_err(|e| e.to_string())?;
- let segment_list_path = dir.join("segment_list.txt");
- match File::open(&segment_list_path) {
- Ok(_) => Ok(()),
- Err(ref e) if e.kind() == ErrorKind::NotFound => {
- File::create(&segment_list_path).map_err(|e| e.to_string())?;
- Ok(())
- },
- Err(e) => Err(e.to_string()),
+ if !dir.to_string_lossy().contains("screenshots") {
+ let segment_list_path = dir.join("segment_list.txt");
+ match File::open(&segment_list_path) {
+ Ok(_) => Ok(()),
+ Err(ref e) if e.kind() == ErrorKind::NotFound => {
+ File::create(&segment_list_path).map_err(|e| e.to_string())?;
+ Ok(())
+ },
+ Err(e) => Err(e.to_string()),
+ }
+ } else {
+ Ok(())
}
}
async fn start_upload_loop(
chunks_dir: PathBuf,
+ screenshot_dir: Option<PathBuf>,
options: RecordingOptions,
video_type: String,
shutdown_flag: Arc<AtomicBool>,
@@ -147,6 +155,8 @@ async fn start_upload_loop(
) -> Result<(), String> {
let mut watched_segments: HashSet<String> = HashSet::new();
let mut is_final_loop = false;
+ let mut screenshot_uploaded = false;
+
loop {
let mut upload_tasks = vec![];
if shutdown_flag.load(Ordering::SeqCst) {
@@ -178,12 +188,27 @@ async fn start_upload_loop(
watched_segments.insert(segment_filename.clone());
}
+ if let Some(screenshot_dir) = &screenshot_dir {
+ let screenshot_path = screenshot_dir.join("screen-capture.jpg");
+ if !screenshot_uploaded && screenshot_path.is_file() {
+ let options_clone = options.clone();
+ let video_type_clone = video_type.clone();
+ let screenshot_path_clone = screenshot_path.clone();
+ upload_tasks.push(tokio::spawn(async move {
+ let filepath_str = screenshot_path_clone.to_str().unwrap_or_default().to_owned();
+ println!("Uploading screenshot for {}: {}", video_type_clone, filepath_str);
+ upload_file(Some(options_clone), filepath_str, "screenshot".to_string()).await.map(|_| ())
+ }));
+ screenshot_uploaded = true;
+ }
+ }
+
// Await all initiated upload tasks in parallel
if !upload_tasks.is_empty() {
let _ = join_all(upload_tasks).await;
}
- tokio::time::sleep(Duration::from_millis(500)).await;
+ tokio::time::sleep(Duration::from_millis(100)).await;
}
uploading_finished.store(true, Ordering::SeqCst);
Ok(())
@@ -207,12 +232,14 @@ fn load_segment_list(segment_list_path: &Path) -> io::Result<HashSet<String>> {
async fn prepare_media_recording(
options: &RecordingOptions,
audio_chunks_dir: &Path,
+ screenshot_dir: &Path,
video_chunks_dir: &Path,
audio_name: Option<String>,
) -> Result<MediaRecorder, String> {
let mut media_recorder = MediaRecorder::new();
let audio_file_path = audio_chunks_dir.to_str().unwrap();
let video_file_path = video_chunks_dir.to_str().unwrap();
- media_recorder.start_media_recording(options.clone(), audio_file_path, video_file_path, audio_name.as_ref().map(String::as_str)).await?;
+ let screenshot_dir_path = screenshot_dir.to_str().unwrap();
+ media_recorder.start_media_recording(options.clone(), audio_file_path, screenshot_dir_path, video_file_path, audio_name.as_ref().map(String::as_str)).await?;
Ok(media_recorder)
}
\ No newline at end of file
diff --git a/apps/desktop/src-tauri/src/upload.rs b/apps/desktop/src-tauri/src/upload.rs
index 35b683978..cd2de7a49 100644
--- a/apps/desktop/src-tauri/src/upload.rs
+++ b/apps/desktop/src-tauri/src/upload.rs
@@ -1,7 +1,6 @@
use serde_json::Value as JsonValue;
use std::path::{Path};
use std::process::Command;
-use std::env;
use reqwest;
use crate::recording::RecordingOptions;
diff --git a/apps/desktop/src-tauri/src/utils.rs b/apps/desktop/src-tauri/src/utils.rs
index 348b95131..3f3d7d35a 100644
--- a/apps/desktop/src-tauri/src/utils.rs
+++ b/apps/desktop/src-tauri/src/utils.rs
@@ -1,66 +1,9 @@
use tokio::process::{ChildStderr};
use std::process::{Command};
-use std::io::Error as IoError;
-use reqwest::Client;
use ffmpeg_sidecar::{
paths::sidecar_dir,
};
-pub async fn send_metadata_api(video_id: &str, start_timestamp: f64, log_type: &str) -> Result<(), String> {
- let client = Client::new();
- println!("Sending metadata API request for video {}: {}", video_id, start_timestamp);
-
- let params = [
- ("videoId", video_id),
- ("startTime", &start_timestamp.to_string()),
- ("logType", &log_type),
- ];
-
- let server_url_base: String = dotenv_codegen::dotenv!("NEXT_PUBLIC_URL").into();
- let server_url = format!("{}/api/desktop/video/metadata/create", server_url_base);
-
- match client.get(&server_url)
- .query(&params)
- .send()
- .await {
- Ok(response) => {
- if response.status().is_success() {
- let _response_body = response.text().await.map_err(|e| e.to_string())?;
- Ok(())
- } else {
- Err(format!("API call failed with status {:?}", response.status()))
- }
- },
- Err(err) => Err(err.to_string()),
- }
-}
-
-pub async fn monitor_and_log_recording_start(stderr: ChildStderr, video_id: &str, log_type: &str) -> Result<(), std::io::Error> {
- use tokio::io::{BufReader, AsyncBufReadExt};
- use regex::Regex;
-
- let reader = BufReader::new(stderr);
- let mut lines = reader.lines();
- let start_regex = Regex::new(r"Duration: N/A, start: (\d+\.\d+)").unwrap();
-
- while let Some(line) = lines.next_line().await? {
- //log stderr with log_type
- println!("{} stderok: {}", log_type, line);
- // if let Some(caps) = start_regex.captures(&line) {
- // if let Some(start_match) = caps.get(1) {
- // let start_time = start_match.as_str().parse::<f64>().unwrap();
- // println!("{} recording started at timestamp: {}", log_type, start_time);
- // if send_metadata_api(video_id, start_time, log_type).await.is_err() {
- // eprintln!("Failed to send metadata to API.");
- // }
- // return Ok(());
- // }
- // }
- }
-
- Err(std::io::Error::new(std::io::ErrorKind::Other, "Screen recording did not start successfully or start timestamp was not found."))
-}
-
pub fn run_command(command: &str, args: Vec<&str>) -> Result<(String, String), String> {
let output = Command::new(command)
.args(args)
diff --git a/apps/desktop/src/app/styles.css b/apps/desktop/src/app/styles.css
index 3b5b1925e..5c90cacb6 100644
--- a/apps/desktop/src/app/styles.css
+++ b/apps/desktop/src/app/styles.css
@@ -163,7 +163,7 @@ body {
}
#app {
- @apply bg-gradient-to-b from-[rgba(255,255,255,0.9)] to-[rgba(255,255,255,0.1)];
+ @apply bg-gradient-to-b from-[rgba(255,255,255,0.92)] to-[rgba(255,255,255,0.2)];
}
* {
diff --git a/apps/desktop/src/components/recording/ActionButton.tsx b/apps/desktop/src/components/recording/ActionButton.tsx
index f2a3e7de3..5c771fc5c 100644
--- a/apps/desktop/src/components/recording/ActionButton.tsx
+++ b/apps/desktop/src/components/recording/ActionButton.tsx
@@ -6,13 +6,20 @@ export const ActionButton = ({
label,
width,
active,
+ recordingOption = false,
+ optionName,
}: {
handler: () => void;
icon?: ReactNode;
label?: string;
width?: string;
active?: boolean;
+ recordingOption?: boolean;
+ optionName?: string;
}) => {
+ const truncatedLabel =
+ label && label.length > 18 ? label.substring(0, 18) + "..." : label;
+
return (
<div className="flex-grow">
<button
@@ -20,16 +27,31 @@ export const ActionButton = ({
className={`${
active === true
? "bg-white hover:bg-gray-100"
- : "bg-gray-100 hover:bg-white"
- } border-gray-300 w-full h-[50px] py-2 px-4 text-[14px] border-2 flex items-center justify-start rounded-[15px] flex-grow transition-all shadow-sm shadow-[0px 0px 180px rgba(255, 255, 255, 0.18)]`}
+ : "bg-gray-200 hover:bg-white"
+ } border-gray-300 w-full h-[50px] py-2 px-4 text-[14px] border-2 flex items-center justify-between rounded-[15px] flex-grow transition-all shadow-sm shadow-[0px 0px 180px rgba(255, 255, 255, 0.18)]`}
>
- <span>{icon}</span>
- {label && (
- <span
- className={`ml-2 truncate ${width !== "full" && "max-w-[100px]"}`}
- >
- {label}
- </span>
+ <div className="flex items-center">
+ <span>{icon}</span>
+ {truncatedLabel && (
+ <span
+ className={`ml-2 truncate ${width !== "full" && "max-w-[100px]"}`}
+ >
+ {truncatedLabel === "None" ? `No ${optionName}` : truncatedLabel}
+ </span>
+ )}
+ </div>
+ {recordingOption && (
+ <div>
+ <span
+ className={`${
+ label === "None"
+ ? "bg-red-600 text-white"
+ : "bg-tertiary text-primary "
+ } h-5 w-8 font-medium text-xs rounded-full flex items-center justify-center`}
+ >
+ <span>{label === "None" ? "Off" : "On"}</span>
+ </span>
+ </div>
)}
</button>
</div>
diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsx
index 59c8318fa..01ec7791e 100644
--- a/apps/desktop/src/components/windows/inner/Recorder.tsx
+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx
@@ -240,7 +240,7 @@ export const Recorder = () => {
seconds % 60 < 10 ? `0${seconds % 60}` : seconds % 60;
setRecordingTime(`${minutes}:${formattedSeconds}`);
- if (seconds >= 600) {
+ if (seconds >= 300) {
handleStopAllRecordings();
}
}, 1000);
@@ -282,7 +282,7 @@ export const Recorder = () => {
<ActionButton
handler={() => console.log("Screen option selected")}
icon={<Screen className="w-5 h-5" />}
- label="Screen"
+ label="Full screen"
active={selectedDisplayType === "screen"}
/>
<ActionButton
@@ -302,6 +302,8 @@ export const Recorder = () => {
icon={<Video className="w-5 h-5" />}
label={selectedVideoDevice?.label || "Video"}
active={selectedVideoDevice !== null}
+ recordingOption={true}
+ optionName="Video"
/>
<ActionButton
width="full"
@@ -309,6 +311,8 @@ export const Recorder = () => {
icon={<Microphone className="w-5 h-5" />}
label={selectedAudioDevice?.label || "Mic"}
active={selectedAudioDevice !== null}
+ recordingOption={true}
+ optionName="Audio"
/>
</div>
</div>
@@ -335,7 +339,7 @@ export const Recorder = () => {
: "Start Recording"}
</Button>
<div className="text-center mt-3">
- <p className="text-sm text-gray-500">10 min recording limit</p>
+ <p className="text-sm text-gray-600">5 min recording limit</p>
</div>
</div>
<Toaster />