feat(applications): handle Path
field in desktop entries (#46)
* feat: handle `Path` field in desktop entries * Fix code style issue
This commit is contained in:
@@ -3,7 +3,7 @@ use anyrun_plugin::{anyrun_interface::HandleResult, *};
|
|||||||
use fuzzy_matcher::FuzzyMatcher;
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
use scrubber::DesktopEntry;
|
use scrubber::DesktopEntry;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{fs, process::Command};
|
use std::{env, fs, process::Command};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
@@ -65,7 +65,12 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Err(why) = Command::new("sh").arg("-c").arg(&entry.exec).spawn() {
|
} else if let Err(why) = Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(&entry.exec)
|
||||||
|
.current_dir(entry.path.as_ref().unwrap_or(&env::current_dir().unwrap()))
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
eprintln!("Error running desktop entry: {}", why);
|
eprintln!("Error running desktop entry: {}", why);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
use std::{collections::HashMap, env, ffi::OsStr, fs};
|
use std::{collections::HashMap, env, ffi::OsStr, fs, path::PathBuf};
|
||||||
|
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct DesktopEntry {
|
pub struct DesktopEntry {
|
||||||
pub exec: String,
|
pub exec: String,
|
||||||
|
pub path: Option<PathBuf>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub desc: Option<String>,
|
pub desc: Option<String>,
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
@@ -73,6 +74,7 @@ impl DesktopEntry {
|
|||||||
}
|
}
|
||||||
exec
|
exec
|
||||||
},
|
},
|
||||||
|
path: map.get("Path").map(PathBuf::from),
|
||||||
name: map.get("Name")?.to_string(),
|
name: map.get("Name")?.to_string(),
|
||||||
desc: None,
|
desc: None,
|
||||||
icon: map
|
icon: map
|
||||||
@@ -118,6 +120,7 @@ impl DesktopEntry {
|
|||||||
}
|
}
|
||||||
None => continue,
|
None => continue,
|
||||||
},
|
},
|
||||||
|
path: entry.path.clone(),
|
||||||
name: match map.get("Name") {
|
name: match map.get("Name") {
|
||||||
Some(name) => name.to_string(),
|
Some(name) => name.to_string(),
|
||||||
None => continue,
|
None => continue,
|
||||||
|
Reference in New Issue
Block a user