diff --git a/src/apps/user.rs b/src/apps/user.rs index 024d5cf..b533fde 100644 --- a/src/apps/user.rs +++ b/src/apps/user.rs @@ -102,6 +102,18 @@ impl MimeApps { Ok(()) } + /// Get the handler associated with a given mime from mimeapps.list's added associations + /// If there is none, default to the system apps + pub fn get_handler_from_added_associations( + &self, + mime: &Mime, + ) -> Result { + self.added_associations + .get(mime) + .and_then(|h| h.front().cloned()) + .ok_or_else(|| Error::NotFound(mime.to_string())) + } + /// Set a default application association, overwriting any existing association for the same mimetype pub fn set_handler( &mut self, diff --git a/src/config/main_config.rs b/src/config/main_config.rs index 193d066..0c05b21 100644 --- a/src/config/main_config.rs +++ b/src/config/main_config.rs @@ -58,24 +58,13 @@ impl Config { match self.mime_apps.get_handler_from_user(mime, &self.config) { Err(e) if matches!(e, Error::Cancelled) => Err(e), h => h - .or_else(|_| self.get_handler_from_added_associations(mime)) + .or_else(|_| { + self.mime_apps.get_handler_from_added_associations(mime) + }) .or_else(|_| self.system_apps.get_handler(mime)), } } - /// Get the handler associated with a given mime from mimeapps.list's added associations - /// If there is none, default to the system apps - fn get_handler_from_added_associations( - &self, - mime: &Mime, - ) -> Result { - self.mime_apps - .added_associations - .get(mime) - .and_then(|h| h.front().cloned()) - .ok_or_else(|| Error::NotFound(mime.to_string())) - } - /// Given a mime and arguments, launch the associated handler with the arguments #[mutants::skip] // Cannot test directly, runs external command pub fn launch_handler(