Skip to content

Commit 6bccc9d

Browse files
Clippy improvements
1 parent a782308 commit 6bccc9d

5 files changed

Lines changed: 62 additions & 99 deletions

File tree

apps/desktop/src-tauri/src/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,9 @@ async fn get_video_metadata(path: PathBuf) -> Result<VideoRecordingMetadata, Str
899899
RecordingMetaInner::Studio(meta) => {
900900
let status = meta.status();
901901
if let StudioRecordingStatus::Failed { .. } = status {
902-
return Err(format!("Unable to get metadata on failed recording"));
902+
return Err("Unable to get metadata on failed recording".to_string());
903903
} else if let StudioRecordingStatus::InProgress = status {
904-
return Err(format!("Unable to get metadata on in-progress recording"));
904+
return Err("Unable to get metadata on in-progress recording".to_string());
905905
}
906906

907907
match meta {
@@ -1754,7 +1754,7 @@ async fn editor_delete_project(
17541754

17551755
let _ = tokio::fs::remove_dir_all(&path).await;
17561756

1757-
RecordingDeleted { path }.emit(&app);
1757+
RecordingDeleted { path }.emit(&app).ok();
17581758

17591759
Ok(())
17601760
}
@@ -2480,17 +2480,15 @@ async fn resume_uploads(app: AppHandle) -> Result<(), String> {
24802480
}
24812481

24822482
// Save the updated meta if we made changes
2483-
if needs_save {
2484-
if let Err(err) = meta.save_for_project() {
2485-
error!("Failed to save recording meta for {path:?}: {err}");
2486-
}
2483+
if needs_save && let Err(err) = meta.save_for_project() {
2484+
error!("Failed to save recording meta for {path:?}: {err}");
24872485
}
24882486

24892487
// Handle upload resumption
24902488
if let Some(upload_meta) = meta.upload {
24912489
match upload_meta {
24922490
UploadMeta::MultipartUpload {
2493-
video_id,
2491+
video_id: _,
24942492
file_path,
24952493
pre_created_video,
24962494
recording_dir,
@@ -2513,8 +2511,7 @@ async fn resume_uploads(app: AppHandle) -> Result<(), String> {
25132511
tokio::spawn(async move {
25142512
if let Ok(meta) = build_video_meta(&file_path)
25152513
.map_err(|err| error!("Failed to resume video upload. error getting video metadata: {}", err))
2516-
{
2517-
if let Ok(uploaded_video) = upload_video(
2514+
&& let Ok(uploaded_video) = upload_video(
25182515
&app,
25192516
video_id,
25202517
file_path,
@@ -2550,8 +2547,6 @@ async fn resume_uploads(app: AppHandle) -> Result<(), String> {
25502547
.set_text(uploaded_video.link.clone());
25512548
NotificationType::ShareableLinkCopied.send(&app);
25522549
}
2553-
2554-
}
25552550
});
25562551
}
25572552
UploadMeta::Failed { .. } | UploadMeta::Complete => {}
@@ -2668,9 +2663,9 @@ fn open_project_from_path(path: &Path, app: AppHandle) -> Result<(), String> {
26682663
RecordingMetaInner::Studio(meta) => {
26692664
let status = meta.status();
26702665
if let StudioRecordingStatus::Failed { .. } = status {
2671-
return Err(format!("Unable to open failed recording"));
2666+
return Err("Unable to open failed recording".to_string());
26722667
} else if let StudioRecordingStatus::InProgress = status {
2673-
return Err(format!("Recording in progress"));
2668+
return Err("Recording in progress".to_string());
26742669
}
26752670

26762671
let project_path = path.to_path_buf();

apps/desktop/src-tauri/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
use std::sync::Arc;
55

66
use cap_desktop_lib::DynLoggingLayer;
7-
use dirs;
8-
use tracing_appender;
97
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
108

119
fn main() {

apps/desktop/src-tauri/src/recording.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ fn ycbcr_to_rgb(y: u8, cb: u8, cr: u8, range: Nv12Range) -> (u8, u8, u8) {
520520

521521
#[cfg(target_os = "macos")]
522522
fn clamp_channel(value: f32) -> u8 {
523-
value.max(0.0).min(255.0) as u8
523+
value.clamp(0.0, 255.0) as u8
524524
}
525525

526526
#[cfg(target_os = "macos")]
@@ -929,15 +929,15 @@ async fn capture_window_thumbnail(window: &scap_targets::Window) -> Option<Strin
929929
#[tauri::command(async)]
930930
#[specta::specta]
931931
pub async fn list_displays_with_thumbnails() -> Result<Vec<CaptureDisplayWithThumbnail>, String> {
932-
tokio::task::spawn_blocking(|| collect_displays_with_thumbnails())
932+
tokio::task::spawn_blocking(collect_displays_with_thumbnails)
933933
.await
934934
.map_err(|err| err.to_string())?
935935
}
936936

937937
#[tauri::command(async)]
938938
#[specta::specta]
939939
pub async fn list_windows_with_thumbnails() -> Result<Vec<CaptureWindowWithThumbnail>, String> {
940-
tokio::task::spawn_blocking(|| collect_windows_with_thumbnails())
940+
tokio::task::spawn_blocking(collect_windows_with_thumbnails)
941941
.await
942942
.map_err(|err| err.to_string())?
943943
}
@@ -1681,35 +1681,30 @@ async fn handle_recording_finish(
16811681
})
16821682
.ok();
16831683
}
1684-
} else {
1685-
if let Ok(meta) = build_video_meta(&output_path)
1686-
.map_err(|err| error!("Error getting video metadata: {}", err))
1687-
{
1688-
// The upload_video function handles screenshot upload, so we can pass it along
1689-
upload_video(
1690-
&app,
1691-
video_upload_info.id.clone(),
1692-
output_path,
1693-
display_screenshot.clone(),
1694-
meta,
1695-
None,
1696-
)
1697-
.await
1698-
.map(|_| {
1699-
info!("Final video upload with screenshot completed successfully")
1700-
})
1701-
.map_err(|error| {
1702-
error!("Error in upload_video: {error}");
1703-
1704-
let mut meta =
1705-
RecordingMeta::load_for_project(&recording_dir).unwrap();
1706-
meta.upload = Some(UploadMeta::Failed { error });
1707-
meta.save_for_project()
1708-
.map_err(|e| format!("Failed to save recording meta: {e}"))
1709-
.ok();
1710-
})
1711-
.ok();
1712-
}
1684+
} else if let Ok(meta) = build_video_meta(&output_path)
1685+
.map_err(|err| error!("Error getting video metadata: {}", err))
1686+
{
1687+
// The upload_video function handles screenshot upload, so we can pass it along
1688+
upload_video(
1689+
&app,
1690+
video_upload_info.id.clone(),
1691+
output_path,
1692+
display_screenshot.clone(),
1693+
meta,
1694+
None,
1695+
)
1696+
.await
1697+
.map(|_| info!("Final video upload with screenshot completed successfully"))
1698+
.map_err(|error| {
1699+
error!("Error in upload_video: {error}");
1700+
1701+
let mut meta = RecordingMeta::load_for_project(&recording_dir).unwrap();
1702+
meta.upload = Some(UploadMeta::Failed { error });
1703+
meta.save_for_project()
1704+
.map_err(|e| format!("Failed to save recording meta: {e}"))
1705+
.ok();
1706+
})
1707+
.ok();
17131708
}
17141709
}
17151710
});
@@ -1902,11 +1897,11 @@ fn generate_zoom_segments_from_clicks_impl(
19021897

19031898
let mut merged: Vec<(f64, f64)> = Vec::new();
19041899
for interval in intervals {
1905-
if let Some(last) = merged.last_mut() {
1906-
if interval.0 <= last.1 + MERGE_GAP_THRESHOLD {
1907-
last.1 = last.1.max(interval.1);
1908-
continue;
1909-
}
1900+
if let Some(last) = merged.last_mut()
1901+
&& interval.0 <= last.1 + MERGE_GAP_THRESHOLD
1902+
{
1903+
last.1 = last.1.max(interval.1);
1904+
continue;
19101905
}
19111906
merged.push(interval);
19121907
}

apps/desktop/src-tauri/src/upload.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async fn file_reader_stream(path: impl AsRef<Path>) -> Result<(ReaderStream<File
153153
}
154154

155155
pub async fn upload_image(app: &AppHandle, file_path: PathBuf) -> Result<UploadedItem, String> {
156-
let is_new_uploader_enabled = GeneralSettingsStore::get(&app)
156+
let is_new_uploader_enabled = GeneralSettingsStore::get(app)
157157
.map_err(|err| error!("Error checking status of new uploader flow from settings: {err}"))
158158
.ok()
159159
.and_then(|v| v.map(|v| v.enable_new_uploader))
@@ -470,17 +470,15 @@ pub fn from_pending_file_to_chunks(
470470

471471
loop {
472472
// Check if realtime recording is done
473-
if !realtime_is_done.unwrap_or(true) {
474-
if let Some(ref realtime_receiver) = realtime_upload_done {
475-
match realtime_receiver.try_recv() {
476-
Ok(_) => realtime_is_done = Some(true),
477-
Err(flume::TryRecvError::Empty) => {},
478-
Err(_) => yield Err(std::io::Error::new(
479-
std::io::ErrorKind::Interrupted,
480-
"Realtime generation failed"
481-
))?,
482-
};
483-
}
473+
if !realtime_is_done.unwrap_or(true) && let Some(ref realtime_receiver) = realtime_upload_done {
474+
match realtime_receiver.try_recv() {
475+
Ok(_) => realtime_is_done = Some(true),
476+
Err(flume::TryRecvError::Empty) => {},
477+
Err(_) => yield Err(std::io::Error::new(
478+
std::io::ErrorKind::Interrupted,
479+
"Realtime generation failed"
480+
))?,
481+
};
484482
}
485483

486484
// Check file existence and size
@@ -608,7 +606,7 @@ fn multipart_uploader(
608606
let url = Uri::from_str(&presigned_url).map_err(|err| format!("uploader/part/{part_number}/invalid_url: {err:?}"))?;
609607
let resp = reqwest::Client::builder()
610608
.retry(reqwest::retry::for_host(url.host().unwrap_or("<unknown>").to_string()).classify_fn(|req_rep| {
611-
if req_rep.status().map_or(false, |s| s.is_server_error()) {
609+
if req_rep.status().is_some_and(|s| s.is_server_error()) {
612610
req_rep.retryable()
613611
} else {
614612
req_rep.success()
@@ -657,7 +655,7 @@ pub async fn singlepart_uploader(
657655
.retry(
658656
reqwest::retry::for_host(url.host().unwrap_or("<unknown>").to_string()).classify_fn(
659657
|req_rep| {
660-
if req_rep.status().map_or(false, |s| s.is_server_error()) {
658+
if req_rep.status().is_some_and(|s| s.is_server_error()) {
661659
req_rep.retryable()
662660
} else {
663661
req_rep.success()

apps/desktop/src-tauri/src/upload_legacy.rs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use crate::api::S3VideoMeta;
99
use crate::web_api::ManagerExt;
1010
use crate::{UploadProgress, VideoUploadInfo};
11-
use cap_utils::spawn_actor;
1211
use ffmpeg::ffi::AV_TIME_BASE;
1312
use flume::Receiver;
1413
use futures::StreamExt;
@@ -79,15 +78,15 @@ pub struct CreateErrorResponse {
7978
// deserializer.deserialize_any(StringOrObject)
8079
// }
8180

82-
impl S3UploadMeta {
83-
pub fn id(&self) -> &str {
84-
&self.id
85-
}
81+
// impl S3UploadMeta {
82+
// pub fn id(&self) -> &str {
83+
// &self.id
84+
// }
8685

87-
// pub fn new(id: String) -> Self {
88-
// Self { id }
89-
// }
90-
}
86+
// // pub fn new(id: String) -> Self {
87+
// // Self { id }
88+
// // }
89+
// }
9190

9291
pub struct UploadedVideo {
9392
pub link: String,
@@ -617,31 +616,9 @@ pub struct MultipartCompleteResponse<'a> {
617616
meta: Option<S3VideoMeta>,
618617
}
619618

620-
pub struct InstantMultipartUpload {
621-
pub handle: tokio::task::JoinHandle<Result<(), String>>,
622-
}
619+
pub struct InstantMultipartUpload {}
623620

624621
impl InstantMultipartUpload {
625-
// /// starts a progressive (multipart) upload that runs until recording stops
626-
// /// and the file has stabilized (no additional data is being written).
627-
// pub fn spawn(
628-
// app: AppHandle,
629-
// video_id: String,
630-
// file_path: PathBuf,
631-
// pre_created_video: VideoUploadInfo,
632-
// realtime_upload_done: Option<Receiver<()>>,
633-
// ) -> Self {
634-
// Self {
635-
// handle: spawn_actor(Self::run(
636-
// app,
637-
// video_id,
638-
// file_path,
639-
// pre_created_video,
640-
// realtime_upload_done,
641-
// )),
642-
// }
643-
// }
644-
645622
pub async fn run(
646623
app: AppHandle,
647624
video_id: String,

0 commit comments

Comments
 (0)