Skip to content

Commit c2898f2

Browse files
committed
clippy
1 parent 2093ea6 commit c2898f2

2 files changed

Lines changed: 51 additions & 142 deletions

File tree

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

Lines changed: 4 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ pub fn format_project_name<'a>(
416416
};
417417

418418
let result = AC
419-
.try_replace_all(haystack, &[recording_mode, mode, target_kind, &truncated_target_name])
419+
.try_replace_all(
420+
haystack,
421+
&[recording_mode, mode, target_kind, &truncated_target_name],
422+
)
420423
.expect("AhoCorasick replace should never fail with default configuration");
421424

422425
let result = DATE_REGEX.replace_all(&result, |caps: &regex::Captures| {
@@ -2180,125 +2183,6 @@ pub fn remux_fragmented_recording(recording_dir: &Path) -> Result<(), String> {
21802183
}
21812184
}
21822185

2183-
fn analyze_recording_for_remux(
2184-
project_path: &Path,
2185-
meta: &RecordingMeta,
2186-
) -> Option<cap_recording::recovery::IncompleteRecording> {
2187-
use cap_recording::recovery::{IncompleteRecording, RecoverableSegment};
2188-
2189-
let StudioRecordingMeta::MultipleSegments { inner, .. } = meta.studio_meta()? else {
2190-
return None;
2191-
};
2192-
2193-
let mut recoverable_segments = Vec::new();
2194-
2195-
for (index, segment) in inner.segments.iter().enumerate() {
2196-
let display_path = segment.display.path.to_path(project_path);
2197-
let (display_fragments, display_init_segment) = if display_path.is_dir() {
2198-
let frags = find_fragments_in_dir(&display_path);
2199-
let init = display_path.join("init.mp4");
2200-
(frags, if init.exists() { Some(init) } else { None })
2201-
} else if display_path.exists() {
2202-
(vec![display_path], None)
2203-
} else {
2204-
continue;
2205-
};
2206-
2207-
if display_fragments.is_empty() {
2208-
continue;
2209-
}
2210-
2211-
let (camera_fragments, camera_init_segment) = segment
2212-
.camera
2213-
.as_ref()
2214-
.map(|cam| {
2215-
let cam_path = cam.path.to_path(project_path);
2216-
if cam_path.is_dir() {
2217-
let frags = find_fragments_in_dir(&cam_path);
2218-
let init = cam_path.join("init.mp4");
2219-
let init_seg = if init.exists() { Some(init) } else { None };
2220-
if frags.is_empty() {
2221-
(None, None)
2222-
} else {
2223-
(Some(frags), init_seg)
2224-
}
2225-
} else if cam_path.exists() {
2226-
(Some(vec![cam_path]), None)
2227-
} else {
2228-
(None, None)
2229-
}
2230-
})
2231-
.unwrap_or((None, None));
2232-
2233-
let cursor_path = segment
2234-
.cursor
2235-
.as_ref()
2236-
.map(|c| c.to_path(project_path))
2237-
.filter(|p| p.exists());
2238-
2239-
let mic_fragments = segment.mic.as_ref().and_then(|mic| {
2240-
let mic_path = mic.path.to_path(project_path);
2241-
if mic_path.is_dir() {
2242-
let frags = find_fragments_in_dir(&mic_path);
2243-
if frags.is_empty() { None } else { Some(frags) }
2244-
} else if mic_path.exists() {
2245-
Some(vec![mic_path])
2246-
} else {
2247-
None
2248-
}
2249-
});
2250-
2251-
let system_audio_fragments = segment.system_audio.as_ref().and_then(|sys| {
2252-
let sys_path = sys.path.to_path(project_path);
2253-
if sys_path.is_dir() {
2254-
let frags = find_fragments_in_dir(&sys_path);
2255-
if frags.is_empty() { None } else { Some(frags) }
2256-
} else if sys_path.exists() {
2257-
Some(vec![sys_path])
2258-
} else {
2259-
None
2260-
}
2261-
});
2262-
2263-
recoverable_segments.push(RecoverableSegment {
2264-
index: index as u32,
2265-
display_fragments,
2266-
display_init_segment,
2267-
camera_fragments,
2268-
camera_init_segment,
2269-
mic_fragments,
2270-
system_audio_fragments,
2271-
cursor_path,
2272-
});
2273-
}
2274-
2275-
if recoverable_segments.is_empty() {
2276-
return None;
2277-
}
2278-
2279-
Some(IncompleteRecording {
2280-
project_path: project_path.to_path_buf(),
2281-
meta: meta.clone(),
2282-
recoverable_segments,
2283-
estimated_duration: Duration::ZERO,
2284-
})
2285-
}
2286-
2287-
fn find_fragments_in_dir(dir: &Path) -> Vec<PathBuf> {
2288-
let Ok(entries) = std::fs::read_dir(dir) else {
2289-
return Vec::new();
2290-
};
2291-
2292-
let mut fragments: Vec<_> = entries
2293-
.filter_map(|e| e.ok())
2294-
.map(|e| e.path())
2295-
.filter(|p| p.extension().is_some_and(|e| e == "mp4" || e == "m4a"))
2296-
.collect();
2297-
2298-
fragments.sort();
2299-
fragments
2300-
}
2301-
23022186
#[cfg(test)]
23032187
mod tests {
23042188
use super::*;

crates/scap-targets/src/platform/win.rs

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
use std::{ffi::OsString, mem, os::windows::ffi::OsStringExt, path::PathBuf, str::FromStr};
22
use tracing::error;
33
use windows::{
4+
core::{BOOL, PCWSTR, PWSTR},
45
Graphics::Capture::GraphicsCaptureItem,
56
Win32::{
67
Foundation::{CloseHandle, HWND, LPARAM, POINT, RECT, TRUE, WPARAM},
78
Graphics::{
8-
Dwm::{DWMWA_CLOAKED, DWMWA_EXTENDED_FRAME_BOUNDS, DwmGetWindowAttribute},
9+
Dwm::{DwmGetWindowAttribute, DWMWA_CLOAKED, DWMWA_EXTENDED_FRAME_BOUNDS},
910
Gdi::{
10-
BI_RGB, BITMAP, BITMAPINFO, BITMAPINFOHEADER, CreateCompatibleBitmap,
11-
CreateCompatibleDC, CreateSolidBrush, DEVMODEW, DIB_RGB_COLORS,
12-
DISPLAY_DEVICE_STATE_FLAGS, DISPLAY_DEVICEW, DeleteDC, DeleteObject,
13-
ENUM_CURRENT_SETTINGS, EnumDisplayDevicesW, EnumDisplayMonitors,
14-
EnumDisplaySettingsW, FillRect, GetDC, GetDIBits, GetMonitorInfoW, GetObjectA,
15-
HBRUSH, HDC, HGDIOBJ, HMONITOR, MONITOR_DEFAULTTONEAREST, MONITOR_DEFAULTTONULL,
16-
MONITORINFOEXW, MonitorFromPoint, MonitorFromWindow, ReleaseDC, SelectObject,
11+
CreateCompatibleBitmap, CreateCompatibleDC, CreateSolidBrush, DeleteDC,
12+
DeleteObject, EnumDisplayDevicesW, EnumDisplayMonitors, EnumDisplaySettingsW,
13+
FillRect, GetDC, GetDIBits, GetMonitorInfoW, GetObjectA, MonitorFromPoint,
14+
MonitorFromWindow, ReleaseDC, SelectObject, BITMAP, BITMAPINFO, BITMAPINFOHEADER,
15+
BI_RGB, DEVMODEW, DIB_RGB_COLORS, DISPLAY_DEVICEW, DISPLAY_DEVICE_STATE_FLAGS,
16+
ENUM_CURRENT_SETTINGS, HBRUSH, HDC, HGDIOBJ, HMONITOR, MONITORINFOEXW,
17+
MONITOR_DEFAULTTONEAREST, MONITOR_DEFAULTTONULL,
1718
},
1819
},
1920
Storage::FileSystem::{
20-
FILE_FLAGS_AND_ATTRIBUTES, GetFileVersionInfoSizeW, GetFileVersionInfoW, VerQueryValueW,
21+
GetFileVersionInfoSizeW, GetFileVersionInfoW, VerQueryValueW, FILE_FLAGS_AND_ATTRIBUTES,
2122
},
2223
System::{
2324
Threading::{
24-
GetCurrentProcessId, OpenProcess, PROCESS_NAME_FORMAT,
25-
PROCESS_QUERY_LIMITED_INFORMATION, QueryFullProcessImageNameW,
25+
GetCurrentProcessId, OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_FORMAT,
26+
PROCESS_QUERY_LIMITED_INFORMATION,
2627
},
2728
WinRT::Graphics::Capture::IGraphicsCaptureItemInterop,
2829
},
@@ -32,25 +33,26 @@ use windows::{
3233
PROCESS_PER_MONITOR_DPI_AWARE,
3334
},
3435
Shell::{
35-
ExtractIconExW, SHFILEINFOW, SHGFI_ICON, SHGFI_LARGEICON, SHGFI_SMALLICON,
36-
SHGetFileInfoW,
36+
ExtractIconExW, SHGetFileInfoW, SHFILEINFOW, SHGFI_ICON, SHGFI_LARGEICON,
37+
SHGFI_SMALLICON,
3738
},
3839
WindowsAndMessaging::{
39-
DI_FLAGS, DestroyIcon, DrawIconEx, EnumChildWindows, EnumWindows, GCLP_HICON,
40-
GW_HWNDNEXT, GWL_EXSTYLE, GWL_STYLE, GetClassLongPtrW, GetClassNameW,
41-
GetClientRect, GetCursorPos, GetDesktopWindow, GetIconInfo,
40+
DestroyIcon, DrawIconEx, EnumChildWindows, EnumWindows, GetClassLongPtrW,
41+
GetClassNameW, GetClientRect, GetCursorPos, GetDesktopWindow, GetIconInfo,
4242
GetLayeredWindowAttributes, GetWindow, GetWindowLongPtrW, GetWindowLongW,
4343
GetWindowRect, GetWindowTextLengthW, GetWindowTextW, GetWindowThreadProcessId,
44-
HICON, ICONINFO, IsIconic, IsWindowVisible, PrivateExtractIconsW, SendMessageW,
44+
IsIconic, IsWindowVisible, PrivateExtractIconsW, SendMessageW, WindowFromPoint,
45+
DI_FLAGS, GCLP_HICON, GWL_EXSTYLE, GWL_STYLE, GW_HWNDNEXT, HICON, ICONINFO,
4546
WM_GETICON, WS_CHILD, WS_EX_LAYERED, WS_EX_TOOLWINDOW, WS_EX_TOPMOST,
46-
WS_EX_TRANSPARENT, WindowFromPoint,
47+
WS_EX_TRANSPARENT,
4748
},
4849
},
4950
},
50-
core::{BOOL, PCWSTR, PWSTR},
5151
};
5252

53-
use crate::bounds::{LogicalSize, PhysicalBounds, PhysicalPosition, PhysicalSize};
53+
use crate::bounds::{
54+
LogicalBounds, LogicalPosition, LogicalSize, PhysicalBounds, PhysicalPosition, PhysicalSize,
55+
};
5456

5557
// All of this assumes PROCESS_PER_MONITOR_DPI_AWARE
5658
//
@@ -124,7 +126,7 @@ impl DisplayImpl {
124126
}
125127

126128
pub fn raw_id(&self) -> DisplayIdImpl {
127-
DisplayIdImpl(self.0.0 as u64)
129+
DisplayIdImpl(self.0 .0 as u64)
128130
}
129131

130132
pub fn from_id(id: String) -> Option<Self> {
@@ -149,6 +151,29 @@ impl DisplayImpl {
149151
))
150152
}
151153

154+
pub fn logical_bounds(&self) -> Option<LogicalBounds> {
155+
let physical_bounds = self.physical_bounds()?;
156+
157+
let dpi = unsafe {
158+
let mut dpi_x = 0;
159+
GetDpiForMonitor(self.0, MDT_EFFECTIVE_DPI, &mut dpi_x, &mut 0).ok()?;
160+
dpi_x
161+
};
162+
163+
let scale = dpi as f64 / 96.0;
164+
165+
Some(LogicalBounds::new(
166+
LogicalPosition::new(
167+
physical_bounds.position().x() / scale,
168+
physical_bounds.position().y() / scale,
169+
),
170+
LogicalSize::new(
171+
physical_bounds.size().width() / scale,
172+
physical_bounds.size().height() / scale,
173+
),
174+
))
175+
}
176+
152177
pub fn get_containing_cursor() -> Option<Self> {
153178
let cursor = get_cursor_position()?;
154179
let point = POINT {
@@ -424,7 +449,7 @@ impl WindowImpl {
424449
}
425450

426451
pub fn id(&self) -> WindowIdImpl {
427-
WindowIdImpl(self.0.0 as u64)
452+
WindowIdImpl(self.0 .0 as u64)
428453
}
429454

430455
pub fn level(&self) -> Option<i32> {

0 commit comments

Comments
 (0)