This commit is contained in:
Gregory 2020-06-10 14:22:26 -04:00
parent e33f52cbb5
commit 66bcde83f4
No known key found for this signature in database
GPG key ID: 2E44FAEEDC94B1E2
5 changed files with 15 additions and 11 deletions

View file

@ -2,4 +2,4 @@ mod system;
mod user;
pub use system::SystemApps;
pub use user::MimeApps;
pub use user::{MimeApps, Rule as MimeappsRule};

View file

@ -89,10 +89,7 @@ impl MimeApps {
}
pub fn read() -> Result<Self> {
let raw_conf = std::fs::read_to_string(Self::path()?)?;
let file = Self::parse(Rule::file, &raw_conf)
.expect("unsuccessful parse") // unwrap the parse result
.next()
.unwrap();
let file = Self::parse(Rule::file, &raw_conf)?.next().unwrap();
let mut current_section_name = "".to_string();
let mut conf = Self {

View file

@ -42,14 +42,19 @@ impl DesktopEntry {
Ok(())
}
fn exec_inner(&self, arg: Vec<String>) -> Result<()> {
let (cmd, args) = self.get_cmd(arg)?;
let mut cmd = Command::new(cmd);
cmd.args(args);
let mut cmd = {
let (cmd, args) = self.get_cmd(arg)?;
let mut cmd = Command::new(cmd);
cmd.args(args);
cmd
};
if self.term {
cmd.status()?;
} else {
cmd.stdout(Stdio::null()).stderr(Stdio::null()).spawn()?;
};
Ok(())
}
pub fn get_cmd(&self, arg: Vec<String>) -> Result<(String, Vec<String>)> {

View file

@ -4,6 +4,6 @@ mod handler;
mod mime_types;
pub use self::db::{autocomplete as db_autocomplete, SHARED_MIME_DB};
pub use desktop_entry::{DesktopEntry, Mode as ExecMode, Rule as PestRule};
pub use desktop_entry::{DesktopEntry, Mode as ExecMode, Rule as EntryRule};
pub use handler::Handler;
pub use mime_types::{MimeOrExtension, MimeType};

View file

@ -1,7 +1,9 @@
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Parse(#[from] pest::error::Error<crate::common::PestRule>),
ParseEntry(#[from] pest::error::Error<crate::common::EntryRule>),
#[error(transparent)]
ParseApps(#[from] pest::error::Error<crate::apps::MimeappsRule>),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
@ -16,7 +18,7 @@ pub enum Error {
Ambiguous(String),
#[error(transparent)]
BadMimeType(#[from] mime::FromStrError),
#[error("Malformed desktop entry at .{0}")]
#[error("malformed desktop entry at .{0}")]
BadEntry(std::path::PathBuf),
}