diff --git a/waycast-core/src/lib.rs b/waycast-core/src/lib.rs index 6e00675..a64491e 100644 --- a/waycast-core/src/lib.rs +++ b/waycast-core/src/lib.rs @@ -15,7 +15,9 @@ pub trait LauncherListItem { } pub trait LauncherPlugin { - fn init(&self); + fn init(&self) { + // Default empty init - plugins can override this + } fn name(&self) -> String; fn priority(&self) -> i32; fn description(&self) -> Option; diff --git a/waycast-macros/src/lib.rs b/waycast-macros/src/lib.rs index 9f8a61d..f717aed 100644 --- a/waycast-macros/src/lib.rs +++ b/waycast-macros/src/lib.rs @@ -142,7 +142,7 @@ impl PluginConfig { quote! { false } }; - // Generate init method + // Generate init method only if explicitly specified in config let init_method = if let Some(ref init_fn) = self.init_fn { quote! { fn init(&self) { @@ -150,11 +150,8 @@ impl PluginConfig { } } } else { - quote! { - fn init(&self) { - // Default empty init - } - } + // Don't generate init method - user should implement it themselves or it will use default + quote! {} }; // Generate default_list method @@ -217,7 +214,8 @@ impl PluginConfig { // Stub implementations to satisfy rust-analyzer // These are only compiled when rust-analyzer is checking the code #[cfg(rust_analyzer)] - fn init(&self) { unimplemented!("Generated by plugin! macro") } + #[allow(unused)] + fn init(&self) { unimplemented!("Generated by plugin! macro or implement your own") } #[cfg(rust_analyzer)] fn name(&self) -> String { unimplemented!("Generated by plugin! macro") } #[cfg(rust_analyzer)] diff --git a/waycast-plugins/src/file_search.rs b/waycast-plugins/src/file_search.rs index 958df08..2dd2813 100644 --- a/waycast-plugins/src/file_search.rs +++ b/waycast-plugins/src/file_search.rs @@ -193,10 +193,27 @@ impl LauncherPlugin for FileSearchPlugin { priority: 500, description: "Search and open files", prefix: "f", - init: file_search_init, default_list: file_search_default_list, filter: file_search_filter } + + fn init(&self) { + // Start async file scanning with 2000ms timeout + let self_clone = FileSearchPlugin { + search_paths: self.search_paths.clone(), + skip_dirs: self.skip_dirs.clone(), + files: Arc::clone(&self.files), + }; + + std::thread::spawn(move || { + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(async { + self_clone + .init_with_timeout(Duration::from_millis(2000)) + .await; + }); + }); + } } fn file_search_default_list(_plugin: &FileSearchPlugin) -> Vec> { @@ -225,23 +242,6 @@ fn file_search_filter(plugin: &FileSearchPlugin, query: &str) -> Vec FileSearchPlugin { FileSearchPlugin::new() diff --git a/waycast-plugins/src/projects.rs b/waycast-plugins/src/projects.rs index d615d05..ca199e4 100644 --- a/waycast-plugins/src/projects.rs +++ b/waycast-plugins/src/projects.rs @@ -82,10 +82,57 @@ impl LauncherPlugin for ProjectsPlugin { priority: 800, description: "Search and open code projects", prefix: "proj", - init: projects_init, default_list: projects_default_list, filter: projects_filter } + + fn init(&self) { + let files_clone = Arc::clone(&self.files); + let search_paths = self.search_paths.clone(); + let skip_dirs = self.skip_dirs.clone(); + + std::thread::spawn(move || { + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(async { + let mut project_entries = Vec::new(); + + for search_path in &search_paths { + if let Ok(entries) = fs::read_dir(search_path) { + for entry in entries.flatten() { + if let Ok(file_type) = entry.file_type() { + if file_type.is_dir() { + let path = entry.path(); + + // Skip hidden directories (starting with .) + if let Some(file_name) = path.file_name() { + if let Some(name_str) = file_name.to_str() { + // Skip hidden directories + if name_str.starts_with('.') { + continue; + } + + // Skip directories in skip list + if should_skip_dir(name_str, &skip_dirs) { + continue; + } + + project_entries.push(ProjectEntry { path }); + } + } + } + } + } + } + } + + // Update the shared files collection + let mut files_guard = files_clone.lock().await; + *files_guard = project_entries; + + println!("Projects plugin: Found {} projects", files_guard.len()); + }); + }); + } } fn projects_default_list(_plugin: &ProjectsPlugin) -> Vec> { @@ -114,55 +161,6 @@ fn projects_filter(plugin: &ProjectsPlugin, query: &str) -> Vec