Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: apply clippy auto-fixes

Louis Beaumontd1b0cb2ef941
diff --git a/screenpipe-audio/src/core/device.rs b/screenpipe-audio/src/core/device.rs
index c7799c15f..09c19a894 100644
--- a/screenpipe-audio/src/core/device.rs
+++ b/screenpipe-audio/src/core/device.rs
@@ -312,7 +312,7 @@ pub async fn default_output_device() -> Result<AudioDevice> {
let device = host
.default_output_device()
.ok_or_else(|| anyhow!("No default output device found"))?;
- return Ok(AudioDevice::new(device.name()?, DeviceType::Output));
+ Ok(AudioDevice::new(device.name()?, DeviceType::Output))
}
#[cfg(not(target_os = "macos"))]
diff --git a/screenpipe-audio/src/transcription/whisper/model.rs b/screenpipe-audio/src/transcription/whisper/model.rs
index 16e91f640..a1d568b13 100644
--- a/screenpipe-audio/src/transcription/whisper/model.rs
+++ b/screenpipe-audio/src/transcription/whisper/model.rs
@@ -37,7 +37,7 @@ pub fn download_whisper_model(engine: Arc<AudioTranscriptionEngine>) -> Result<P
info!("model downloaded {}", model_name);
- return Ok(model);
+ Ok(model)
}
pub fn create_whisper_context_parameters<'a>(
diff --git a/screenpipe-core/src/operator/platforms/macos.rs b/screenpipe-core/src/operator/platforms/macos.rs
index 5632c6770..2fded9e1d 100644
--- a/screenpipe-core/src/operator/platforms/macos.rs
+++ b/screenpipe-core/src/operator/platforms/macos.rs
@@ -244,7 +244,7 @@ impl MacOSEngine {
// Check if cached element is still valid
match cached_element.0.role() {
- Ok(role) if role.to_string() == "AXApplication" => {
+ Ok(role) if role == "AXApplication" => {
// First try to activate the app using the cached element
unsafe {
use objc::{class, msg_send, sel, sel_impl};
@@ -387,7 +387,7 @@ fn map_generic_role_to_macos_roles(role: &str) -> Vec<String> {
fn macos_role_to_generic_role(role: &str) -> Vec<String> {
match role.to_lowercase().as_str() {
- "AXWindow" => vec!["window".to_string()],
+ "axwindow" => vec!["window".to_string()],
"AXButton" | "AXMenuItem" | "AXMenuBarItem" => vec!["button".to_string()],
"AXTextField" | "AXTextArea" | "AXTextEdit" | "AXSearchField" | "AXURIField"
| "AXAddressField" => vec![
@@ -397,7 +397,7 @@ fn macos_role_to_generic_role(role: &str) -> Vec<String> {
"url".to_string(),
"urlfield".to_string(),
],
- "AXList" => vec!["list".to_string()],
+ "axlist" => vec!["list".to_string()],
"AXCell" => vec!["listitem".to_string()],
"AXSheet" | "AXDialog" => vec!["dialog".to_string()],
"AXGroup" | "AXGenericElement" | "AXWebArea" => {
@@ -538,7 +538,7 @@ impl AccessibilityEngine for MacOSEngine {
.element
.0
.role()
- .map_or(false, |r| r.to_string() == "AXApplication")
+ .is_ok_and(|r| r == "AXApplication")
{
if let Some(app_name) = root_elem.attributes().label {
self.refresh_accessibility_tree(Some(&app_name))?;
@@ -622,7 +622,7 @@ impl AccessibilityEngine for MacOSEngine {
&self.system_wide.0,
move |e| {
// Use move to take ownership of name_owned
- e.title().unwrap_or(CFString::new("")).to_string() == name_owned
+ e.title().unwrap_or(CFString::new("")) == name_owned
},
None,
);
@@ -712,14 +712,14 @@ impl AccessibilityEngine for MacOSEngine {
}
}
- return Err(AutomationError::ElementNotFound(format!(
+ Err(AutomationError::ElementNotFound(format!(
"No element found with role '{}' and id '{}'",
role, id
- )));
+ )))
} else {
- return Err(AutomationError::UnsupportedOperation(
+ Err(AutomationError::UnsupportedOperation(
"Only role -> id chains are supported".to_string(),
- ));
+ ))
}
}
Selector::Filter(_) => Err(AutomationError::UnsupportedOperation(
@@ -766,7 +766,7 @@ impl AccessibilityEngine for MacOSEngine {
Selector::Id(id) => {
let id_owned = id.clone();
let collector = ElementsCollectorWithWindows::new(start_element, move |e| {
- e.identifier().unwrap_or(CFString::new("")).to_string() == id_owned
+ e.identifier().unwrap_or(CFString::new("")) == id_owned
});
let ax_ui_elements = collector.find_all();
@@ -782,7 +782,7 @@ impl AccessibilityEngine for MacOSEngine {
Selector::Name(name) => {
let name_owned = name.clone();
let collector = ElementsCollectorWithWindows::new(start_element, move |e| {
- e.title().unwrap_or(CFString::new("")).to_string() == name_owned
+ e.title().unwrap_or(CFString::new("")) == name_owned
});
let ax_ui_elements = collector.find_all();
@@ -930,8 +930,10 @@ impl fmt::Display for ClickMethod {
// Define enum for click method selection
#[derive(Debug)]
+#[derive(Default)]
pub enum ClickMethodSelection {
/// Try all methods in sequence (current behavior)
+ #[default]
Auto,
/// Use only AXPress action
AXPress,
@@ -941,11 +943,6 @@ pub enum ClickMethodSelection {
MouseSimulation,
}
-impl Default for ClickMethodSelection {
- fn default() -> Self {
- ClickMethodSelection::Auto
- }
-}
// Our concrete UIElement implementation for macOS
pub struct MacOSUIElement {
@@ -973,7 +970,7 @@ impl MacOSUIElement {
loop {
// Check if current element is an application
if let Ok(role) = current.0.role() {
- if role.to_string() == "AXApplication" {
+ if role == "AXApplication" {
return Some(MacOSUIElement {
element: current,
use_background_apps: self.use_background_apps,
@@ -1050,7 +1047,7 @@ impl MacOSUIElement {
fn click_press(&self) -> Result<ClickResult, AutomationError> {
let press_attr = AXAttribute::new(&CFString::new("AXPress"));
- match self.element.0.perform_action(&press_attr.as_CFString()) {
+ match self.element.0.perform_action(press_attr.as_CFString()) {
Ok(_) => {
debug!("Successfully clicked element with AXPress");
Ok(ClickResult {
@@ -1068,7 +1065,7 @@ impl MacOSUIElement {
fn click_accessibility_click(&self) -> Result<ClickResult, AutomationError> {
let click_attr = AXAttribute::new(&CFString::new("AXClick"));
- match self.element.0.perform_action(&click_attr.as_CFString()) {
+ match self.element.0.perform_action(click_attr.as_CFString()) {
Ok(_) => {
debug!("Successfully clicked element with AXClick");
Ok(ClickResult {
@@ -1346,7 +1343,7 @@ impl UIElementImpl for MacOSUIElement {
.element
.0
.role()
- .map_or(false, |r| r.to_string() == "AXWindow");
+ .is_ok_and(|r| r == "AXWindow");
// Special case for windows
if is_window {
@@ -1669,7 +1666,7 @@ impl UIElementImpl for MacOSUIElement {
// First try using the AXRaise action
let raise_attr = AXAttribute::new(&CFString::new("AXRaise"));
- if let Ok(_) = self.element.0.perform_action(&raise_attr.as_CFString()) {
+ if self.element.0.perform_action(raise_attr.as_CFString()).is_ok() {
debug!("Successfully raised element");
// Now try to directly focus the element
@@ -1704,7 +1701,7 @@ impl UIElementImpl for MacOSUIElement {
self.click().map(|_result| {
// Optionally log the details of how the click was performed
debug!("Focus achieved via click method: {}", _result.method);
- ()
+
})
}
@@ -1946,7 +1943,7 @@ impl UIElementImpl for MacOSUIElement {
self.element
.0
- .perform_action(&action_attr.as_CFString())
+ .perform_action(action_attr.as_CFString())
.map_err(|e| {
AutomationError::PlatformError(format!(
"Failed to perform action {}: {}",
@@ -1964,7 +1961,7 @@ impl UIElementImpl for MacOSUIElement {
.element
.0
.role()
- .map_or(false, |r| r.to_string() == "AXApplication")
+ .is_ok_and(|r| r == "AXApplication")
{
if let Some(app_name) = self.attributes().label {
engine.refresh_accessibility_tree(Some(&app_name))?;
@@ -2157,7 +2154,7 @@ fn parse_ax_attribute_value(
// Create an array of element addresses
let mut items = Vec::with_capacity(count as usize);
for i in 0..count {
- let item = CFArrayGetValueAtIndex(array_ref, i as isize);
+ let item = CFArrayGetValueAtIndex(array_ref, i);
if !item.is_null() {
// Correctly wrap the raw pointer into AXUIElement
let ax_element = AXUIElement::wrap_under_get_rule(item as *mut _);
@@ -2186,7 +2183,7 @@ fn element_contains_text(e: &AXUIElement, text: &str) -> bool {
.value()
.ok()
.and_then(|v| v.downcast_into::<CFString>())
- .map_or(false, |s| s.to_string().contains(text));
+ .is_some_and(|s| s.to_string().contains(text));
if contains_in_value {
return true;
@@ -2196,12 +2193,12 @@ fn element_contains_text(e: &AXUIElement, text: &str) -> bool {
let contains_in_title = e
.title()
.ok()
- .map_or(false, |t| t.to_string().contains(text));
+ .is_some_and(|t| t.to_string().contains(text));
let contains_in_desc = e
.description()
.ok()
- .map_or(false, |d| d.to_string().contains(text));
+ .is_some_and(|d| d.to_string().contains(text));
// Check common text attributes
for attr_name in &[
diff --git a/screenpipe-core/src/operator/platforms/mod.rs b/screenpipe-core/src/operator/platforms/mod.rs
index 48aa4ded5..9cbdcbec7 100644
--- a/screenpipe-core/src/operator/platforms/mod.rs
+++ b/screenpipe-core/src/operator/platforms/mod.rs
@@ -56,10 +56,10 @@ pub fn create_engine(
) -> Result<Box<dyn AccessibilityEngine>, AutomationError> {
#[cfg(target_os = "macos")]
{
- return Ok(Box::new(macos::MacOSEngine::new(
+ Ok(Box::new(macos::MacOSEngine::new(
use_background_apps,
activate_app,
- )?));
+ )?))
}
#[cfg(target_os = "windows")]
{
diff --git a/screenpipe-core/src/pipes.rs b/screenpipe-core/src/pipes.rs
index bd6e0b589..966f05767 100644
--- a/screenpipe-core/src/pipes.rs
+++ b/screenpipe-core/src/pipes.rs
@@ -1624,7 +1624,7 @@ pub async fn download_pipe_private(
) -> anyhow::Result<PathBuf> {
info!("processing private pipe from zip: {}", source);
- let dest_dir = screenpipe_dir.join("pipes").join(&pipe_name);
+ let dest_dir = screenpipe_dir.join("pipes").join(pipe_name);
debug!("destination directory: {:?}", dest_dir);
// Create temp directory for download
diff --git a/screenpipe-db/src/db.rs b/screenpipe-db/src/db.rs
index 00b9260ec..4eb839a84 100644
--- a/screenpipe-db/src/db.rs
+++ b/screenpipe-db/src/db.rs
@@ -915,10 +915,7 @@ impl DatabaseManager {
.into_iter()
.map(|raw| async move {
let speaker = match raw.speaker_id {
- Some(id) => match self.get_speaker_by_id(id).await {
- Ok(speaker) => Some(speaker),
- Err(_) => None,
- },
+ Some(id) => (self.get_speaker_by_id(id).await).ok(),
None => None,
};
diff --git a/screenpipe-events/src/custom_events/meetings.rs b/screenpipe-events/src/custom_events/meetings.rs
index 5c76ae443..e03d9a9c3 100644
--- a/screenpipe-events/src/custom_events/meetings.rs
+++ b/screenpipe-events/src/custom_events/meetings.rs
@@ -56,7 +56,7 @@ pub async fn poll_meetings_events() -> Result<()> {
&& !meeting_in_progress
&& !ui_frame.window.is_empty()
&& is_meeting_keyword
- && last_meeting_end.map_or(true, |t| t.elapsed() >= MEETING_RESTART_TIMEOUT)
+ && last_meeting_end.is_none_or(|t| t.elapsed() >= MEETING_RESTART_TIMEOUT)
{
meeting_in_progress = true;
send_event(
@@ -112,7 +112,7 @@ pub async fn poll_meetings_events() -> Result<()> {
if (is_meeting_app && (has_meeting_keywords || has_meeting_ui))
&& !meeting_in_progress
- && last_meeting_end.map_or(true, |t| t.elapsed() >= MEETING_RESTART_TIMEOUT)
+ && last_meeting_end.is_none_or(|t| t.elapsed() >= MEETING_RESTART_TIMEOUT)
{
meeting_in_progress = true;
send_event(
@@ -152,7 +152,7 @@ pub async fn poll_meetings_events() -> Result<()> {
if recent_speakers.len() >= 2
&& !meeting_in_progress
- && last_meeting_end.map_or(true, |t| t.elapsed() >= MEETING_RESTART_TIMEOUT)
+ && last_meeting_end.is_none_or(|t| t.elapsed() >= MEETING_RESTART_TIMEOUT)
{
meeting_in_progress = true;
send_event(
diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rs
index e75866569..9993e2eb9 100644
--- a/screenpipe-server/src/core.rs
+++ b/screenpipe-server/src/core.rs
@@ -186,7 +186,7 @@ async fn record_video(
loop {
// Increment and check heartbeat
heartbeat_counter += 1;
- if heartbeat_counter % heartbeat_interval == 0 {
+ if heartbeat_counter.is_multiple_of(heartbeat_interval) {
let uptime = start_time.elapsed().as_secs();
let frames_per_sec = if uptime > 0 {
frames_processed as f64 / uptime as f64
@@ -200,7 +200,7 @@ async fn record_video(
}
// Periodically check database health
- if heartbeat_counter % db_health_check_interval == 0 {
+ if heartbeat_counter.is_multiple_of(db_health_check_interval) {
debug!("Checking database health for monitor {}", monitor_id);
// Just log that we're checking the DB health
debug!("Database health check periodic reminder");
@@ -208,7 +208,7 @@ async fn record_video(
}
// In the try-catch block inside the loop, add health checks
- if heartbeat_counter % health_check_interval == 0 {
+ if heartbeat_counter.is_multiple_of(health_check_interval) {
debug!(
"Checking VideoCapture task health for monitor {}",
monitor_id
@@ -343,7 +343,7 @@ async fn record_video(
}
} else {
// Log when frame queue is empty
- if heartbeat_counter % 10 == 0 {
+ if heartbeat_counter.is_multiple_of(10) {
debug!(
"record_video: No frames in queue for monitor {}",
monitor_id
diff --git a/screenpipe-server/src/embedding/embedding_endpoint.rs b/screenpipe-server/src/embedding/embedding_endpoint.rs
index 84f071720..c5c81622c 100644
--- a/screenpipe-server/src/embedding/embedding_endpoint.rs
+++ b/screenpipe-server/src/embedding/embedding_endpoint.rs
@@ -68,8 +68,7 @@ pub async fn get_or_initialize_model() -> anyhow::Result<Arc<Mutex<EmbeddingMode
EMBEDDING_MODEL
.get()
- .ok_or_else(|| anyhow::anyhow!("model initialization failed"))
- .map(|model| model.clone())
+ .ok_or_else(|| anyhow::anyhow!("model initialization failed")).cloned()
}
#[oasgen]
diff --git a/screenpipe-server/src/server.rs b/screenpipe-server/src/server.rs
index dac092532..50bbabe3a 100644
--- a/screenpipe-server/src/server.rs
+++ b/screenpipe-server/src/server.rs
@@ -1162,7 +1162,7 @@ impl SCServer {
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
+ .map_err(|e| std::io::Error::other(e))?;
Ok(())
}
@@ -3851,7 +3851,7 @@ async fn list_interactable_elements_handler(
timestamp: now.to_rfc3339(),
expires_at: expires_at.to_rfc3339(),
element_count: elements.len(),
- ttl_seconds: ttl_seconds,
+ ttl_seconds,
};
Ok(JsonResponse(ListInteractableElementsResponse {
diff --git a/screenpipe-server/src/video.rs b/screenpipe-server/src/video.rs
index f3f852ee8..18ad773bb 100644
--- a/screenpipe-server/src/video.rs
+++ b/screenpipe-server/src/video.rs
@@ -273,10 +273,7 @@ impl VideoCapture {
check_interval.tick().await;
// Check if monitor is available
- let monitor_exists = match get_monitor_by_id(monitor_id).await {
- Some(_) => true,
- None => false,
- };
+ let monitor_exists = (get_monitor_by_id(monitor_id).await).is_some();
// Update availability flag
let current_availability = monitor_available_clone.load(Ordering::SeqCst);
@@ -624,7 +621,7 @@ async fn write_frame_with_retry(
async fn flush_ffmpeg_input(stdin: &mut ChildStdin, frame_count: usize, fps: f64) {
let frames_per_flush = (fps.max(0.1) * 1.0).ceil() as usize;
- if frame_count % frames_per_flush == 0 {
+ if frame_count.is_multiple_of(frames_per_flush) {
debug!("Flushing FFmpeg input after {} frames", frames_per_flush);
if let Err(e) = stdin.flush().await {
error!("Failed to flush FFmpeg input: {}", e);
diff --git a/screenpipe-vision/src/browser_utils/macos.rs b/screenpipe-vision/src/browser_utils/macos.rs
index da3d4676e..4b6c705c4 100644
--- a/screenpipe-vision/src/browser_utils/macos.rs
+++ b/screenpipe-vision/src/browser_utils/macos.rs
@@ -14,6 +14,12 @@ use super::BrowserUrlDetector;
pub struct MacOSUrlDetector;
+impl Default for MacOSUrlDetector {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl MacOSUrlDetector {
pub fn new() -> Self {
Self
diff --git a/screenpipe-vision/src/capture_screenshot_by_window.rs b/screenpipe-vision/src/capture_screenshot_by_window.rs
index 9d1e506af..fd3fe08f8 100644
--- a/screenpipe-vision/src/capture_screenshot_by_window.rs
+++ b/screenpipe-vision/src/capture_screenshot_by_window.rs
@@ -292,7 +292,7 @@ pub async fn capture_all_visible_windows(
image,
app_name,
window_name,
- process_id: process_id as i32,
+ process_id: process_id,
is_focused,
});
}
diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rs
index b16939200..0961022ab 100644
--- a/screenpipe-vision/src/core.rs
+++ b/screenpipe-vision/src/core.rs
@@ -590,8 +590,7 @@ fn get_active_browser_url_sync(
std::io::ErrorKind::NotFound,
"No active URL found",
)),
- Err(e) => Err(std::io::Error::new(
- std::io::ErrorKind::Other,
+ Err(e) => Err(std::io::Error::other(
format!("Failed to get active URL: {}", e),
)),
}