Small cleanup
This commit is contained in:
parent
25710a319f
commit
575b8b8ad5
@ -10,7 +10,7 @@ fn main() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
app.connect_activate(|app| {
|
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/") {
|
match file_search_plugin.add_search_path("/home/javi/working-files/DJ Music/") {
|
||||||
Err(e) => eprintln!("{}", e),
|
Err(e) => eprintln!("{}", e),
|
||||||
@ -19,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
// Create the core launcher
|
// Create the core launcher
|
||||||
let launcher = WaycastLauncher::new()
|
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))
|
.add_plugin(Box::new(file_search_plugin))
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
|
@ -86,6 +86,10 @@ pub fn get_desktop_entries() -> Vec<DesktopEntry> {
|
|||||||
entries
|
entries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new() -> DrunPlugin {
|
||||||
|
DrunPlugin {}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct DrunPlugin {}
|
pub struct DrunPlugin {}
|
||||||
|
|
||||||
impl LauncherPlugin for DrunPlugin {
|
impl LauncherPlugin for DrunPlugin {
|
||||||
|
@ -39,32 +39,31 @@ impl LauncherListItem for FileEntry {
|
|||||||
println!("Executing: {}", self.path.display());
|
println!("Executing: {}", self.path.display());
|
||||||
|
|
||||||
// Use xdg-open directly since it works properly with music files
|
// Use xdg-open directly since it works properly with music files
|
||||||
match Command::new("xdg-open")
|
match Command::new("xdg-open").arg(&self.path).spawn() {
|
||||||
.arg(&self.path)
|
Ok(_) => {
|
||||||
.spawn() {
|
println!("Successfully launched with xdg-open");
|
||||||
Ok(_) => {
|
Ok(())
|
||||||
println!("Successfully launched with xdg-open");
|
}
|
||||||
Ok(())
|
Err(e) => {
|
||||||
}
|
println!("xdg-open failed: {}", e);
|
||||||
Err(e) => {
|
// Fallback to GIO method
|
||||||
println!("xdg-open failed: {}", e);
|
let file_gio = gio::File::for_path(&self.path);
|
||||||
// Fallback to GIO method
|
let ctx = gio::AppLaunchContext::new();
|
||||||
let file_gio = gio::File::for_path(&self.path);
|
match gio::AppInfo::launch_default_for_uri(file_gio.uri().as_str(), Some(&ctx)) {
|
||||||
let ctx = gio::AppLaunchContext::new();
|
Ok(()) => {
|
||||||
match gio::AppInfo::launch_default_for_uri(file_gio.uri().as_str(), Some(&ctx)) {
|
println!("Successfully launched with GIO fallback");
|
||||||
Ok(()) => {
|
Ok(())
|
||||||
println!("Successfully launched with GIO fallback");
|
}
|
||||||
Ok(())
|
Err(e2) => {
|
||||||
}
|
println!("GIO fallback also failed: {}", e2);
|
||||||
Err(e2) => {
|
Err(LaunchError::CouldNotLaunch(format!(
|
||||||
println!("GIO fallback also failed: {}", e2);
|
"Both xdg-open and GIO failed: {} / {}",
|
||||||
Err(LaunchError::CouldNotLaunch(
|
e, e2
|
||||||
format!("Both xdg-open and GIO failed: {} / {}", e, e2)
|
)))
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon(&self) -> String {
|
fn icon(&self) -> String {
|
||||||
@ -112,6 +111,19 @@ pub fn default_search_list() -> Vec<PathBuf> {
|
|||||||
|
|
||||||
Vec::new()
|
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 {
|
pub struct FileSearchPlugin {
|
||||||
search_paths: Vec<PathBuf>,
|
search_paths: Vec<PathBuf>,
|
||||||
skip_dirs: Vec<String>,
|
skip_dirs: Vec<String>,
|
||||||
@ -120,19 +132,6 @@ pub struct FileSearchPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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<P: AsRef<Path>>(&mut self, path: P) -> Result<(), String> {
|
pub fn add_search_path<P: AsRef<Path>>(&mut self, path: P) -> Result<(), String> {
|
||||||
let p = path.as_ref();
|
let p = path.as_ref();
|
||||||
|
|
||||||
@ -148,6 +147,11 @@ impl FileSearchPlugin {
|
|||||||
Ok(())
|
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) {
|
async fn init_with_timeout(&self, timeout: Duration) {
|
||||||
let files_clone = Arc::clone(&self.files);
|
let files_clone = Arc::clone(&self.files);
|
||||||
let skip_dirs_clone = self.skip_dirs.clone();
|
let skip_dirs_clone = self.skip_dirs.clone();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user