Skip to content

Commit

Permalink
upgrade libs
Browse files Browse the repository at this point in the history
  • Loading branch information
JojiiOfficial committed Jun 28, 2024
1 parent 1690eab commit 44cb782
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 426 deletions.
524 changes: 234 additions & 290 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ readme = "README.md"
galaxy_buds_rs = { git = "https://github.com/JojiiOfficial/GalaxyBuds-rs" }
#galaxy_buds_rs = "0.2.10"
#galaxy_buds_rs = { path = "../GalaxyBuds-rs" }
clap = { version = "3.2.25", features = ["std"] }
clap_complete = "3.2.5"
clap = { version = "4.5", features = ["std", "cargo"] }
clap_complete = "4.5"
async-std = { version = "1.12.0", features = ["attributes"] }
bluetooth-serial-port-async = "0.6.3"
blurz = "0.4.0"
ofiles = "0.2.0"
serde = { version = "1.0.200", features = ["derive"] }
serde_json = "1.0.116"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.118"
notify-rust = "4.11.0"
toml = "0.5.11"
toml = "0.8.14"
mpris = "2.0.1"
#clap_generate = "3.0.3"
nix = "0.24.3"
nix = {version = "0.29.0", features = ["signal"]}
rust-pulsectl-fork = { version = "0.2.12", optional = true }
human-panic = "1.2.3"
log = "0.4.21"
pretty_env_logger = "0.4.0"
human-panic = "2.0.0"
log = "0.4.22"
pretty_env_logger = "0.5.0"

[features]
default = ["pulse-sink"]
Expand Down
150 changes: 59 additions & 91 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{Arg, Command, ValueHint};

pub fn build<'a>(_s: &str) -> App<'a> {
App::new("earbuds")
.setting(AppSettings::TrailingVarArg)
.setting(AppSettings::ColoredHelp)
.setting(AppSettings::ArgRequiredElseHelp)
pub fn build<'a>() -> Command {
Command::new("earbuds")
.arg_required_else_help(true)
.about("ok")
//.version(crate_version!())
.author("Jojii S")
//.help("Control your Galaxy Buds live from cli")
Expand All @@ -20,13 +19,13 @@ pub fn build<'a>(_s: &str) -> App<'a> {
.short('o')
.long("output")
.global(true)
.possible_values(&["json", "normal"]),
.value_parser(["json", "normal"]),
)
.arg(
Arg::new("generator")
.long("generate")
.help("Generate completion scripts for a given type of shell")
.possible_values(&["bash", "elvish", "fish", "powershell", "zsh"]),
.value_parser(["bash", "elvish", "fish", "powershell", "zsh"]),
)
.arg(
Arg::new("daemon")
Expand Down Expand Up @@ -57,111 +56,80 @@ pub fn build<'a>(_s: &str) -> App<'a> {
.global(true)
.help("Specify the device to use")
.short('s')
.takes_value(true)
.num_args(1)
.value_hint(ValueHint::Unknown)
.long("device"),
)
.subcommand(
App::new("status")
.setting(AppSettings::ColoredHelp)
Command::new("status")
.alias("info")
.help("Display informations for a given device"),
.about("Display informations for a given device"),
)
.subcommand(
App::new("set")
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::ColoredHelp)
.help("Turn on/off features and control the equalizer setting")
.arg(
Arg::new("key")
.required(true)
.takes_value(true)
.possible_values(&[
"equalizer",
"anc",
"touchpadlock",
"touchpad",
"ambientsound",
"tap-action",
]),
)
.arg(Arg::new("value").required(true).takes_value(true))
Command::new("set")
.about("Turn on/off features and control the equalizer setting")
.arg(Arg::new("key").required(true).num_args(1).value_parser([
"equalizer",
"anc",
"touchpadlock",
"touchpad",
"ambientsound",
"tap-action",
]))
.arg(Arg::new("value").required(true).num_args(1))
.arg(
Arg::new("opt")
.help("Provide additional input for some keys")
.takes_value(true),
.num_args(1),
),
)
.subcommand(
App::new("enable")
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::ColoredHelp)
.help("Turn off a given features")
.arg(
Arg::new("key")
.required(true)
.takes_value(true)
.possible_values(&["anc", "touchpad"]),
),
Command::new("enable").about("Turn on a given feature").arg(
Arg::new("key")
.required(true)
.num_args(1)
.value_parser(["anc", "touchpad"]),
),
)
.subcommand(
App::new("disable")
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::ColoredHelp)
.help("Turn off a given features")
.arg(
Arg::new("key")
.required(true)
.takes_value(true)
.possible_values(&["equalizer", "anc", "touchpad"]),
),
Command::new("disable")
.arg_required_else_help(true)
.about("Turn off a given feature")
.arg(Arg::new("key").required(true).num_args(1).value_parser([
"equalizer",
"anc",
"touchpad",
])),
)
.subcommand(
App::new("toggle")
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::ColoredHelp)
.help("Toggle the state of a feature")
.arg(
Arg::new("key")
.required(true)
.takes_value(true)
.possible_values(&["anc", "touchpadlock", "touchpad"]),
),
Command::new("toggle")
.arg_required_else_help(true)
.about("Toggle the state of a feature")
.arg(Arg::new("key").required(true).num_args(1).value_parser([
"anc",
"touchpadlock",
"touchpad",
])),
)
.subcommand(
App::new("config")
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::ColoredHelp)
.help("Interact with the buds configuration")
Command::new("config")
.arg_required_else_help(true)
.about("Interact with the buds configuration")
.subcommand(
App::new("set")
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::ColoredHelp)
.help("Set a config value")
.arg(
Arg::new("key")
.required(true)
.takes_value(true)
.possible_values(&[
"auto-pause",
"auto-play",
"low-battery-notification",
"smart-sink",
]),
)
.arg(Arg::new("value").required(true).takes_value(true)),
Command::new("set")
.arg_required_else_help(true)
.about("Set a config value")
.arg(Arg::new("key").required(true).num_args(1).value_parser([
"auto-pause",
"auto-play",
"low-battery-notification",
"smart-sink",
]))
.arg(Arg::new("value").required(true).num_args(1)),
),
)
// Connect
.subcommand(
App::new("connect")
.help("Connect your earbuds")
.setting(AppSettings::ColoredHelp),
)
.subcommand(Command::new("connect").about("Connect your earbuds"))
// Disconnect
.subcommand(
App::new("disconnect")
.help("Disconnect your earbuds")
.setting(AppSettings::ColoredHelp),
)
.subcommand(Command::new("disconnect").about("Disconnect your earbuds"))
}
8 changes: 6 additions & 2 deletions src/cmd/config_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ use clap::ArgMatches;

/// Set a value
pub fn set(sc: &mut SocketClient, app: &ArgMatches) {
let value = app.value_of("value").unwrap_or_default();
let skey = app.value_of("key").unwrap();
let value = app
.get_one::<String>("value")
.map(|i| i.as_str())
.unwrap_or_default();

let skey = app.get_one::<String>("key").unwrap();
let key = match Key::parse(skey) {
Some(k) => k,
None => {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn show(sc: &mut SocketClient, app: &ArgMatches) {

println!("Info for '{}':", bt_name);
println!();
if app.is_present("verbose") {
if app.contains_id("verbose") {
println!("Type:\t\t{:?}", res.model);
}
println!("Battery:\tL: {}%, R: {}%", res.batt_left, res.batt_right);
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn show(sc: &mut SocketClient, app: &ArgMatches) {
(res.debug.temperature_right * 100_f32).floor() / 100_f32
);

if app.is_present("verbose") {
if app.contains_id("verbose") {
println!(
"Current left:\t{:?}mA",
(res.debug.current_left * 10000_f64).floor()
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/set_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use galaxy_buds_rs::message::bud_property::{BudProperty, EqualizerType, Touchpad

/// Set a value
pub fn set(sc: &mut SocketClient, app: &ArgMatches, toggle: bool, value: &str) {
let skey = app.value_of("key").unwrap();
let skey = app.get_one::<String>("key").unwrap();
let key = match Key::parse(skey) {
Some(k) => k,
None => {
Expand All @@ -31,8 +31,8 @@ pub fn set(sc: &mut SocketClient, app: &ArgMatches, toggle: bool, value: &str) {
);

// Set opt param if present
if app.is_present("opt") {
request.opt_param3 = app.value_of("opt").map(|s| s.to_owned());
if app.contains_id("opt") {
request.opt_param3 = app.get_one::<String>("opt").cloned();
}

// Do unix_socket request
Expand Down
8 changes: 2 additions & 6 deletions src/cmd/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ use clap::ArgMatches;

// return ture if user wants the data in json
pub fn print_as_json(app: &ArgMatches) -> bool {
app.is_present("output") && app.value_of("output").unwrap() == "json"
app.contains_id("output") && app.get_one::<String>("output").unwrap() == "json"
}

// Get the device from ArgMatches or none
pub fn get_device_from_app(app: &ArgMatches) -> Option<String> {
if app.is_present("device") {
app.value_of("device").map(|s| s.to_owned())
} else {
None
}
app.get_one::<String>("device").cloned()
}

/// Unwrap a response
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/bluetooth/bt_connection_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::rfcomm_connector::ConnectionEventData;
pub struct BudsConnection {
pub addr: String,
pub socket: BtSocket,
pub fd: i32,
// pub fd: i32,
}

/// Listens for new Bluethooth connections
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/bluetooth/rfcomm_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ pub fn connect_rfcomm<S: AsRef<str>>(addr: S) -> Result<BudsConnection, String>
let mut socket = BtSocket::new(BtProtocol::RFCOMM).map_err(|e| e.to_string())?;
let address = BtAddr::from_str(addr.as_ref()).unwrap();
socket.connect(address).map_err(|e| e.to_string())?;
let fd = socket.get_fd();
// let fd = socket.get_fd();

Ok(BudsConnection {
addr: addr.as_ref().to_owned(),
socket,
fd,
// fd,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/unix_socket/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn set_value(payload: &Request, address: String, config: Arc<Mutex<Con
if cfg.is_none() {
return get_err("error getting config!");
}
let mut cfg = cfg.unwrap();
let cfg = cfg.unwrap();

// Set the right value of the config
match key.as_str() {
Expand Down
10 changes: 6 additions & 4 deletions src/daemon_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use std::{
process::{exit, Command, Stdio},
};

use nix::{
sys::signal::{self, SIGTERM},
unistd::Pid,
};

/// Start the daemon detached from the current cli
pub fn start() -> bool {
let curr_exe = env::current_exe().expect("Couldn't get current executable!");
Expand Down Expand Up @@ -65,10 +70,7 @@ pub fn kill<P: AsRef<Path>>(quiet: bool, daemon_path: P) -> bool {
println!("pids: {pids:?}");
if let Ok(pids) = pids {
let u: u32 = (*pids.get(0).unwrap()).into();
if let Err(err) = nix::sys::signal::kill(
nix::unistd::Pid::from_raw(u as i32),
nix::sys::signal::SIGTERM,
) {
if let Err(err) = signal::kill(Pid::from_raw(u as i32), SIGTERM) {
eprintln!("Error killing process: {:?}", err);
exit(1);
} else if !quiet {
Expand Down
Loading

0 comments on commit 44cb782

Please sign in to comment.