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.

general code cleanup

+14 -12
+7 -2
infat-cli/src/main.rs
··· 13 13 14 14 #[tokio::main] 15 15 async fn main() -> Result<()> { 16 - // Install color-eyre for beautiful error reports 16 + // Color eyre for them goooood errors 17 17 color_eyre::install().wrap_err("Failed to install color-eyre error handler")?; 18 18 19 19 let cli = Cli::parse(); ··· 26 26 match cli.command { 27 27 None => { 28 28 // No subcommand provided - load and apply configuration 29 + // Kind of bespoke behavior but infat stands for infatuate 30 + // I like to think it's just running the verb 29 31 handle_config_load(&global_opts) 30 32 .await 31 33 .wrap_err("Failed to load and apply configuration")?; ··· 68 70 } 69 71 None => config::find_config_file().ok_or_else(|| { 70 72 color_eyre::eyre::eyre!( 71 - "No configuration file found. Use {} or place config at XDG location", 73 + "No configuration file found. Use {} or place config at default location", 72 74 "--config".bright_yellow() 73 75 ) 74 76 })?, ··· 127 129 .filter(|&&x| x) 128 130 .count(); 129 131 132 + // Some basic validation that clap can't provide 130 133 if provided_count == 0 { 131 134 return Err(color_eyre::eyre::eyre!( 132 135 "Must provide one of: {}, {}, or {}", ··· 157 160 println!(" Bundle ID: {}", app_info.bundle_id.bright_green()); 158 161 println!(" Version: {}", app_info.version); 159 162 println!(" Path: {}", app_info.path.display().dimmed()); 163 + 164 + // Declared means just those it claims to support 160 165 161 166 // Display declared URL schemes 162 167 if !app_info.declared_schemes.is_empty() {
-1
infat-lib/src/app.rs
··· 1 - // infat-lib/src/app.rs 2 1 //! Application information and management 3 2 4 3 use crate::{
-1
infat-lib/src/association.rs
··· 1 - // infat-lib/src/association.rs 2 1 //! High-level association management combining all the pieces 3 2 4 3 use crate::{
-1
infat-lib/src/config.rs
··· 1 - // infat-lib/src/config.rs 2 1 use crate::{ 3 2 association, 4 3 error::{InfatError, Result},
-1
infat-lib/src/error.rs
··· 1 - // infat-lib/src/error.rs 2 1 use std::path::PathBuf; 3 2 use thiserror::Error; 4 3
+2 -1
infat-lib/src/macos/ffi.rs
··· 1 - // infat-lib/src/macos/ffi.rs 2 1 //! Raw FFI bindings to macOS Launch Services and related APIs 3 2 4 3 use core_foundation::{array::CFArrayRef, base::OSStatus, string::CFStringRef, url::CFURLRef}; 5 4 6 5 pub type LSRolesMask = u32; 6 + 7 7 pub const K_LS_ROLES_VIEWER: LSRolesMask = 2; 8 8 pub const K_LS_ROLES_ALL: LSRolesMask = 0xFFFFFFFF; 9 9 ··· 11 11 pub const K_LS_APPLICATION_NOT_FOUND_ERR: OSStatus = -10814; 12 12 pub const K_LS_UNKNOWN_ERR: OSStatus = -10810; 13 13 14 + // Unsafe bindings 14 15 #[link(name = "CoreServices", kind = "framework")] 15 16 extern "C" { 16 17 pub fn LSSetDefaultHandlerForURLScheme(
-1
infat-lib/src/macos/launch_services.rs
··· 1 - // infat-lib/src/macos/launch_services.rs 2 1 //! High-level Launch Services API wrappers 3 2 4 3 use super::ffi::*;
+4 -2
infat-lib/src/macos/launch_services_db.rs
··· 1 - // infat-lib/src/macos/launch_services_db.rs 2 1 //! Launch Services database parsing for the init command 3 2 4 3 use crate::error::{InfatError, Result}; ··· 50 49 message: "Could not determine home directory".to_string(), 51 50 })?; 52 51 52 + // Needs to be consistent across systems 53 53 let ls_path = home 54 54 .join("Library") 55 55 .join("Preferences") ··· 70 70 }); 71 71 } 72 72 73 + // Here we first parse into an arbitrary value and then compare against our schema 74 + 73 75 let plist_data = std::fs::read(&ls_path)?; 74 76 let value: Value = 75 77 plist::from_bytes(&plist_data).map_err(|e| InfatError::LaunchServicesError { ··· 115 117 continue; 116 118 } 117 119 118 - // Canonicalize the id 120 + // Canonicalize the id (There's sometimes a difference between the id the application provides to launchservices and the one it'll key itself as to be identifed as) 119 121 let canonical_id = match resolve_to_bundle_id(&bundle_id) { 120 122 Ok(id) => id, 121 123 Err(_) => {
+1 -1
infat-lib/src/macos/workspace.rs
··· 1 - // infat-lib/src/macos/workspace.rs 2 1 //! NSWorkspace integration for app discovery and management 3 2 4 3 use crate::error::{InfatError, Result}; ··· 7 6 use std::path::{Path, PathBuf}; 8 7 use tracing::debug; 9 8 9 + // Make a point of linking the AppKit framework 10 10 #[link(name = "AppKit", kind = "framework")] 11 11 extern "C" {} 12 12
-1
infat-lib/src/uti.rs
··· 1 - // infat-lib/src/uti.rs - COMPLETE implementation 2 1 use crate::error::{InfatError, Result}; 3 2 use serde::{Deserialize, Serialize}; 4 3 use std::str::FromStr;