2017-07-14 15:23:42 +00:00
|
|
|
//! Helper functions for invoking system commands.
|
|
|
|
|
2017-07-13 22:27:46 +00:00
|
|
|
|
2017-06-26 07:08:37 +00:00
|
|
|
use errors::*;
|
|
|
|
use glib;
|
|
|
|
use prefs::Prefs;
|
|
|
|
use std::error::Error;
|
|
|
|
use std;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-14 15:23:42 +00:00
|
|
|
/// Execute an available volume control command asynchronously, starting with
|
|
|
|
/// the preferences and using some fallback values. If none of these
|
|
|
|
/// are valid executables in `$PATH`, then return `Err(err)`.
|
2017-06-26 07:08:37 +00:00
|
|
|
pub fn execute_vol_control_command(prefs: &Prefs) -> Result<()> {
|
|
|
|
let m_cmd = prefs.get_avail_vol_control_cmd();
|
|
|
|
|
|
|
|
match m_cmd {
|
|
|
|
Some(ref cmd) => execute_command(cmd.as_str()),
|
|
|
|
None => bail!("No command found"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-14 15:23:42 +00:00
|
|
|
/// Try to execute the given command asynchronously via gtk.
|
2017-06-26 07:08:37 +00:00
|
|
|
pub fn execute_command(cmd: &str) -> Result<()> {
|
2017-09-01 22:54:32 +00:00
|
|
|
return Ok(glib::spawn_command_line_async(cmd)
|
2017-07-19 10:12:08 +00:00
|
|
|
.map_err(|e| {
|
|
|
|
std::io::Error::new(std::io::ErrorKind::Other, e.description())
|
2017-09-01 22:54:32 +00:00
|
|
|
})?);
|
2017-06-26 07:08:37 +00:00
|
|
|
}
|