Compare commits

...

3 commits

Author SHA1 Message Date
f2cb1defa0
Remove keypress simulation functionality stub 2024-03-14 11:22:06 +01:00
82075e9ff9
Add external command execution 2024-03-14 11:20:47 +01:00
a4e63ae51a
Warn when no active mpris player is found
previously would panic
2024-03-14 11:20:26 +01:00
3 changed files with 26 additions and 10 deletions

View file

@ -1,5 +1,5 @@
use int_enum::IntEnum; use int_enum::IntEnum;
use log::{error, info, warn}; use log::error;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::Path; use std::path::Path;
use std::process; use std::process;
@ -100,9 +100,6 @@ pub enum KeyMapVariant {
PipeWire { PipeWire {
ids: Vec<String>, ids: Vec<String>,
}, },
Key {
keycode: u8, //TODO: add real keycodes
},
Exec { Exec {
command: String, command: String,
args: Option<Vec<String>>, args: Option<Vec<String>>,

View file

@ -4,6 +4,7 @@ use crate::midi_client::KeyEvent;
use crate::mpris_client; use crate::mpris_client;
use crossbeam_channel::Receiver; use crossbeam_channel::Receiver;
use log::{error, info, warn}; use log::{error, info, warn};
use std::process::{Command, Output};
use std::sync::Arc; use std::sync::Arc;
use std::thread; use std::thread;
@ -91,8 +92,20 @@ fn eval(key: NanoKeys, state: u8, config: &Arc<Config>) {
} }
}, },
KeyMapVariant::PipeWire { ids } => {} KeyMapVariant::PipeWire { ids } => {}
KeyMapVariant::Key { keycode } => {} KeyMapVariant::Exec { command, args } => {
KeyMapVariant::Exec { command, args } => {} let output: Result<Output, std::io::Error> = match args {
Some(some_args) => Command::new(command).args(some_args).output(),
None => Command::new(command).output(),
};
match output {
Ok(out) => {
info!("{:?}", out);
}
Err(err) => {
error!("{:?}", err);
}
}
}
} }
} }
} }

View file

@ -1,3 +1,4 @@
use log::warn;
use mpris::Player; use mpris::Player;
use mpris::PlayerFinder; use mpris::PlayerFinder;
use regex::Regex; use regex::Regex;
@ -36,10 +37,15 @@ where
{ {
let player = PlayerFinder::new() let player = PlayerFinder::new()
.expect("Could not connect to D-Bus") .expect("Could not connect to D-Bus")
.find_active() .find_active();
.expect("Could not find any player"); match player {
Ok(p) => {
function(&player); function(&p);
}
Err(err) => {
warn!("Could not find an active player: {err}");
}
}
} }
fn exec_functionality<F>(player_id: Option<&str>, exec_closure: F) fn exec_functionality<F>(player_id: Option<&str>, exec_closure: F)