Connect applications to schemes, filetypes, and more on macOS (more to come)
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

auto clippy fixes

+37 -39
+12 -12
infat-cli/src/main.rs
··· 5 5 owo_colors::OwoColorize, 6 6 }; 7 7 use infat_lib::{ 8 - app, association, config, macos::launch_services_db, uti::SuperType, GlobalOptions, 8 + app, association, config, macos::launch_services_db, GlobalOptions, 9 9 }; 10 10 use std::path::PathBuf; 11 - use tracing::{error, info}; 11 + use tracing::info; 12 12 13 13 #[derive(Parser, Debug, Clone)] 14 14 #[command( ··· 233 233 info!("Getting info for application: {}", app_name); 234 234 235 235 let app_info = app::get_app_info(&app_name) 236 - .wrap_err_with(|| format!("Failed to get info for app: {}", app_name))?; 236 + .wrap_err_with(|| format!("Failed to get info for app: {app_name}"))?; 237 237 238 238 // Display application information 239 239 println!("{}", "Application Information".bright_blue().bold()); ··· 264 264 let exts: Vec<String> = declared_type 265 265 .extensions 266 266 .iter() 267 - .map(|ext| format!(".{}", ext)) 267 + .map(|ext| format!(".{ext}")) 268 268 .collect(); 269 269 println!(" Extensions: {}", exts.join(", ").bright_green()); 270 270 } ··· 279 279 info!("Getting info for extension: .{}", extension); 280 280 281 281 let info = association::get_info_for_extension(&extension) 282 - .wrap_err_with(|| format!("Failed to get info for extension: .{}", extension))?; 282 + .wrap_err_with(|| format!("Failed to get info for extension: .{extension}"))?; 283 283 284 284 println!( 285 285 "📄 File Extension: {}", 286 - format!(".{}", extension).bright_green() 286 + format!(".{extension}").bright_green() 287 287 ); 288 288 289 289 if let Some(uti) = &info.uti { ··· 303 303 if !all_app_names.is_empty() { 304 304 println!("\n{}", "All registered apps:".bright_blue().bold()); 305 305 for app_name in all_app_names { 306 - println!(" • {}", app_name); 306 + println!(" • {app_name}"); 307 307 } 308 308 } else { 309 309 println!( ··· 315 315 info!("Getting info for type: {}", type_name); 316 316 317 317 let info = association::get_info_for_type(&type_name) 318 - .wrap_err_with(|| format!("Failed to get info for type: {}", type_name))?; 318 + .wrap_err_with(|| format!("Failed to get info for type: {type_name}"))?; 319 319 320 320 println!("🏷️ File Type: {}", type_name.bright_green()); 321 321 ··· 336 336 if !all_app_names.is_empty() { 337 337 println!("\n{}", "All registered apps:".bright_blue().bold()); 338 338 for app_name in all_app_names { 339 - println!(" • {}", app_name); 339 + println!(" • {app_name}"); 340 340 } 341 341 } else { 342 342 println!("\n{}", "No applications registered for this type".yellow()); ··· 381 381 382 382 association::set_default_app_for_extension(&extension, &app_name) 383 383 .await 384 - .wrap_err_with(|| format!("Failed to set default app for .{}", extension))?; 384 + .wrap_err_with(|| format!("Failed to set default app for .{extension}"))?; 385 385 386 386 if !opts.quiet { 387 387 println!( ··· 396 396 397 397 association::set_default_app_for_url_scheme(&url_scheme, &app_name) 398 398 .await 399 - .wrap_err_with(|| format!("Failed to set default app for {} scheme", url_scheme))?; 399 + .wrap_err_with(|| format!("Failed to set default app for {url_scheme} scheme"))?; 400 400 401 401 if !opts.quiet { 402 402 println!( ··· 411 411 412 412 association::set_default_app_for_type(&type_name, &app_name) 413 413 .await 414 - .wrap_err_with(|| format!("Failed to set default app for type {}", type_name))?; 414 + .wrap_err_with(|| format!("Failed to set default app for type {type_name}"))?; 415 415 416 416 if !opts.quiet { 417 417 println!(
+3 -3
infat-lib/src/app.rs
··· 7 7 }; 8 8 use plist::Value; 9 9 use std::path::PathBuf; 10 - use tracing::{debug, warn}; 10 + use tracing::debug; 11 11 12 12 /// Information about an application's declared file types and URL schemes 13 13 #[derive(Debug, Clone)] ··· 75 75 .to_string(); 76 76 77 77 // Parse declared document types 78 - let declared_types = parse_document_types(&dict); 78 + let declared_types = parse_document_types(dict); 79 79 80 80 // Parse declared URL schemes 81 - let declared_schemes = parse_url_schemes(&dict); 81 + let declared_schemes = parse_url_schemes(dict); 82 82 83 83 Ok(AppInfo { 84 84 bundle_id,
+1 -1
infat-lib/src/association.rs
··· 104 104 let all_apps = launch_services::get_all_apps_for_uti(&uti)?; 105 105 106 106 Ok(AssociationInfo { 107 - identifier: format!(".{}", extension), 107 + identifier: format!(".{extension}"), 108 108 uti: Some(uti), 109 109 default_app, 110 110 all_apps,
+3 -3
infat-lib/src/config.rs
··· 153 153 success_count += 1; 154 154 } 155 155 Err(e) => { 156 - let msg = format!("Failed to set type {} → {}: {}", type_name, app_name, e); 156 + let msg = format!("Failed to set type {type_name} → {app_name}: {e}"); 157 157 if robust { 158 158 warn!("{}", msg); 159 159 errors.push(msg); ··· 178 178 success_count += 1; 179 179 } 180 180 Err(e) => { 181 - let msg = format!("Failed to set .{} → {}: {}", ext, app_name, e); 181 + let msg = format!("Failed to set .{ext} → {app_name}: {e}"); 182 182 if robust { 183 183 warn!("{}", msg); 184 184 errors.push(msg); ··· 203 203 success_count += 1; 204 204 } 205 205 Err(e) => { 206 - let msg = format!("Failed to set {} → {}: {}", scheme, app_name, e); 206 + let msg = format!("Failed to set {scheme} → {app_name}: {e}"); 207 207 if robust { 208 208 warn!("{}", msg); 209 209 errors.push(msg);
+4 -5
infat-lib/src/macos/ffi.rs
··· 2 2 //! Raw FFI bindings to macOS Launch Services and related APIs 3 3 4 4 use core_foundation::{ 5 - array::{CFArray, CFArrayRef}, 6 - base::{CFTypeRef, OSStatus, TCFType}, 7 - string::{CFString, CFStringRef}, 8 - url::{CFURLRef, CFURL}, 5 + array::CFArrayRef, 6 + base::OSStatus, 7 + string::CFStringRef, 8 + url::CFURLRef, 9 9 }; 10 - use std::ffi::c_void; 11 10 12 11 pub type LSRolesMask = u32; 13 12 pub const K_LS_ROLES_VIEWER: LSRolesMask = 2;
+7 -7
infat-lib/src/macos/launch_services.rs
··· 4 4 use super::ffi::*; 5 5 use crate::error::{InfatError, Result}; 6 6 use core_foundation::{ 7 - array::{CFArray, CFArrayRef}, 8 - base::{CFType, OSStatus, TCFType}, 9 - string::{CFString, CFStringRef}, 7 + array::CFArray, 8 + base::TCFType, 9 + string::CFString, 10 10 url::CFURL, 11 11 }; 12 12 use std::path::Path; 13 - use tracing::{debug, warn}; 13 + use tracing::debug; 14 14 15 15 /// Set the default application for a URL scheme 16 16 pub fn set_default_app_for_url_scheme(scheme: &str, bundle_id: &str) -> Result<()> { ··· 31 31 32 32 if status != 0 { 33 33 return Err(InfatError::LaunchServicesError { 34 - message: format!("Failed to set URL scheme handler: error {}", status), 34 + message: format!("Failed to set URL scheme handler: error {status}"), 35 35 }); 36 36 } 37 37 ··· 56 56 57 57 if status != 0 { 58 58 return Err(InfatError::LaunchServicesError { 59 - message: format!("Failed to set UTI handler: error {}", status), 59 + message: format!("Failed to set UTI handler: error {status}"), 60 60 }); 61 61 } 62 62 ··· 161 161 162 162 if status != 0 { 163 163 return Err(InfatError::LaunchServicesError { 164 - message: format!("Failed to register application: error {}", status), 164 + message: format!("Failed to register application: error {status}"), 165 165 }); 166 166 } 167 167
+2 -3
infat-lib/src/macos/launch_services_db.rs
··· 6 6 use plist::Value; 7 7 use serde::{Deserialize, Serialize}; 8 8 use std::collections::HashMap; 9 - use std::path::PathBuf; 10 9 use tracing::{debug, info, warn}; 11 10 12 11 #[derive(Debug, Deserialize, Serialize)] ··· 74 73 let plist_data = std::fs::read(&ls_path)?; 75 74 let value: Value = 76 75 plist::from_bytes(&plist_data).map_err(|e| InfatError::LaunchServicesError { 77 - message: format!("Failed to parse Launch Services database: {}", e), 76 + message: format!("Failed to parse Launch Services database: {e}"), 78 77 })?; 79 78 80 79 let db: LaunchServicesDatabase = 81 80 plist::from_value(&value).map_err(|e| InfatError::LaunchServicesError { 82 - message: format!("Failed to deserialize Launch Services database: {}", e), 81 + message: format!("Failed to deserialize Launch Services database: {e}"), 83 82 })?; 84 83 85 84 info!(
+4 -4
infat-lib/src/macos/workspace.rs
··· 3 3 4 4 use crate::error::{InfatError, Result}; 5 5 use objc::{class, msg_send, runtime::Object, sel, sel_impl}; 6 - use objc_foundation::{INSObject, INSString, NSObject, NSString}; 6 + use objc_foundation::{INSObject, INSString, NSString}; 7 7 use std::path::{Path, PathBuf}; 8 - use tracing::{debug, warn}; 8 + use tracing::debug; 9 9 10 10 #[link(name = "AppKit", kind = "framework")] 11 11 extern "C" {} ··· 155 155 let mut found_count = 0; 156 156 for entry in entries.flatten() { 157 157 let entry_path = entry.path(); 158 - if entry_path.extension().map_or(false, |ext| ext == "app") { 158 + if entry_path.extension().is_some_and(|ext| ext == "app") { 159 159 apps.push(entry_path); 160 160 found_count += 1; 161 161 } ··· 187 187 188 188 // Try as a file path 189 189 let path = PathBuf::from(name_or_bundle_id); 190 - if path.exists() && path.extension().map_or(false, |ext| ext == "app") { 190 + if path.exists() && path.extension().is_some_and(|ext| ext == "app") { 191 191 return Ok(Some(path)); 192 192 } 193 193
+1 -1
infat-lib/src/uti.rs
··· 503 503 Self::M4vVideo => "m4v-video", 504 504 Self::M4aAudio => "m4a-audio", 505 505 _ => { 506 - return write!(f, "{:?}", self) 506 + return write!(f, "{self:?}") 507 507 .map(|_| ()) 508 508 .map_err(|_| std::fmt::Error) 509 509 }