From 575b8b8ad5613b97e0b5a977fa634f096f301257 Mon Sep 17 00:00:00 2001 From: Javier Feliz Date: Fri, 5 Sep 2025 20:12:26 -0400 Subject: [PATCH] Small cleanup --- src/main.rs | 4 +- src/plugins/drun.rs | 4 ++ src/plugins/file_search.rs | 78 ++++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/main.rs b/src/main.rs index 748bb1b..112583e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ fn main() { .build(); app.connect_activate(|app| { - let mut file_search_plugin = plugins::file_search::FileSearchPlugin::new(); + let mut file_search_plugin = plugins::file_search::new(); match file_search_plugin.add_search_path("/home/javi/working-files/DJ Music/") { Err(e) => eprintln!("{}", e), @@ -19,7 +19,7 @@ fn main() { // Create the core launcher let launcher = WaycastLauncher::new() - .add_plugin(Box::new(plugins::drun::DrunPlugin {})) + .add_plugin(Box::new(plugins::drun::new())) .add_plugin(Box::new(file_search_plugin)) .init(); diff --git a/src/plugins/drun.rs b/src/plugins/drun.rs index 1bc9bdf..5388aff 100644 --- a/src/plugins/drun.rs +++ b/src/plugins/drun.rs @@ -86,6 +86,10 @@ pub fn get_desktop_entries() -> Vec { entries } +pub fn new() -> DrunPlugin { + DrunPlugin {} +} + pub struct DrunPlugin {} impl LauncherPlugin for DrunPlugin { diff --git a/src/plugins/file_search.rs b/src/plugins/file_search.rs index a8442b5..95086ad 100644 --- a/src/plugins/file_search.rs +++ b/src/plugins/file_search.rs @@ -37,34 +37,33 @@ impl LauncherListItem for FileEntry { fn execute(&self) -> Result<(), LaunchError> { println!("Executing: {}", self.path.display()); - + // Use xdg-open directly since it works properly with music files - match Command::new("xdg-open") - .arg(&self.path) - .spawn() { - Ok(_) => { - println!("Successfully launched with xdg-open"); - Ok(()) - } - Err(e) => { - println!("xdg-open failed: {}", e); - // Fallback to GIO method - let file_gio = gio::File::for_path(&self.path); - let ctx = gio::AppLaunchContext::new(); - match gio::AppInfo::launch_default_for_uri(file_gio.uri().as_str(), Some(&ctx)) { - Ok(()) => { - println!("Successfully launched with GIO fallback"); - Ok(()) - } - Err(e2) => { - println!("GIO fallback also failed: {}", e2); - Err(LaunchError::CouldNotLaunch( - format!("Both xdg-open and GIO failed: {} / {}", e, e2) - )) - } + match Command::new("xdg-open").arg(&self.path).spawn() { + Ok(_) => { + println!("Successfully launched with xdg-open"); + Ok(()) + } + Err(e) => { + println!("xdg-open failed: {}", e); + // Fallback to GIO method + let file_gio = gio::File::for_path(&self.path); + let ctx = gio::AppLaunchContext::new(); + match gio::AppInfo::launch_default_for_uri(file_gio.uri().as_str(), Some(&ctx)) { + Ok(()) => { + println!("Successfully launched with GIO fallback"); + Ok(()) + } + Err(e2) => { + println!("GIO fallback also failed: {}", e2); + Err(LaunchError::CouldNotLaunch(format!( + "Both xdg-open and GIO failed: {} / {}", + e, e2 + ))) } } } + } } fn icon(&self) -> String { @@ -112,6 +111,19 @@ pub fn default_search_list() -> Vec { Vec::new() } + +pub fn new() -> FileSearchPlugin { + return FileSearchPlugin { + search_paths: default_search_list(), + skip_dirs: vec![ + String::from("vendor"), + String::from("node_modules"), + String::from("cache"), + String::from("zig-cache"), + ], + files: Arc::new(Mutex::new(Vec::new())), + }; +} pub struct FileSearchPlugin { search_paths: Vec, skip_dirs: Vec, @@ -120,19 +132,6 @@ pub struct FileSearchPlugin { } impl FileSearchPlugin { - pub fn new() -> Self { - return FileSearchPlugin { - search_paths: default_search_list(), - skip_dirs: vec![ - String::from("vendor"), - String::from("node_modules"), - String::from("cache"), - String::from("zig-cache"), - ], - files: Arc::new(Mutex::new(Vec::new())), - }; - } - pub fn add_search_path>(&mut self, path: P) -> Result<(), String> { let p = path.as_ref(); @@ -148,6 +147,11 @@ impl FileSearchPlugin { Ok(()) } + pub fn add_skip_dir(&mut self, directory_name: String) -> Result<(), String> { + self.skip_dirs.push(directory_name); + Ok(()) + } + async fn init_with_timeout(&self, timeout: Duration) { let files_clone = Arc::clone(&self.files); let skip_dirs_clone = self.skip_dirs.clone();