Skip to content

Commit

Permalink
fixup! refactor: better separate user app and system app logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Anomalocaridid committed Oct 14, 2024
1 parent 8fbb702 commit 91d7a72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/apps/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DesktopHandler> {
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,
Expand Down
17 changes: 3 additions & 14 deletions src/config/main_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DesktopHandler> {
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(
Expand Down

0 comments on commit 91d7a72

Please sign in to comment.