Compare commits

...

2 Commits

Author SHA1 Message Date
9631cf2cd2 Fix json output using join method
Some checks failed
Rust / build-macos (push) Has been cancelled
Rust / build-windows (push) Has been cancelled
Rust / build-linux (push) Failing after 17s
Rust / publish-aur (push) Has been skipped
2026-05-14 17:24:33 +00:00
Lennard Kittner
1e8049d458 Fix non linux tray app 2026-05-14 18:51:20 +02:00
2 changed files with 32 additions and 38 deletions

View File

@@ -232,9 +232,9 @@ fn main() {
if let Some(output_json) = matches.get_one::<bool>("json") {
if *output_json {
let properties = &device.get_device_state().device_properties;
let mut headset_info_string = "{\n".to_string();
let mut headset_info_json = "{\n ".to_string();
let mut json_properties: Vec<String> = properties
let json_properties: Vec<String> = properties
.get_properties()
.iter()
.map(|property| match property {
@@ -255,35 +255,17 @@ fn main() {
property_descriptor,
) => match &property_descriptor.data {
Some(data) => {
format!(" \"{}\": \"{}\",\n", property_descriptor.name, data)
format!("\"{}\": \"{}\"", property_descriptor.name, data)
}
_ => "".to_string(),
},
})
.collect();
// The last property needs to end without a comma
match json_properties.last_mut() {
#[allow(unused_assignments)]
Some(mut json_property) => {
let mut last_property = json_property[0..(json_property.len() - 2)].to_string();
last_property += "\n";
json_property = &mut last_property;
}
None => {
// Unreachable:
// The program exits if no device is found
// but also has a property for the device being connected
unreachable!();
}
}
headset_info_json += &json_properties.join(",\n ");
for json_property in json_properties {
headset_info_string += &json_property;
}
headset_info_string += "}";
println!("{}", headset_info_string);
headset_info_json += "\n}";
println!("{}", headset_info_json);
} else {
println!("{}", device.get_device_state().device_properties);
}

View File

@@ -3,9 +3,9 @@ use std::{
sync::{mpsc::Sender, Arc, Mutex},
};
use hyper_headset::devices::{DeviceEvent, DeviceProperties, PropertyType};
#[cfg(target_os = "windows")]
use image::{Rgba, RgbaImage};
use hyper_headset::devices::{DeviceEvent, DeviceProperties, PropertyType};
use tray_icon::{
menu::{CheckMenuItem, Menu, MenuEvent, MenuId, MenuItem, PredefinedMenuItem, Submenu},
TrayIcon, TrayIconBuilder,
@@ -50,14 +50,7 @@ fn draw_rect(image: &mut RgbaImage, x: i32, y: i32, width: i32, height: i32, col
}
#[cfg(target_os = "windows")]
fn draw_digit(
image: &mut RgbaImage,
digit: char,
x: i32,
y: i32,
scale: i32,
color: Rgba<u8>,
) {
fn draw_digit(image: &mut RgbaImage, digit: char, x: i32, y: i32, scale: i32, color: Rgba<u8>) {
let rows = match digit {
'0' => ["111", "101", "101", "101", "111"],
// Narrow upright '1'.
@@ -170,7 +163,14 @@ fn render_windows_battery_icon_rgba(key: WindowsIconKey) -> Vec<u8> {
let mut x = start_x;
for (idx, digit) in text.chars().enumerate() {
draw_digit(&mut image, digit, x, start_y, scale, Rgba([10, 10, 10, 255]));
draw_digit(
&mut image,
digit,
x,
start_y,
scale,
Rgba([10, 10, 10, 255]),
);
x += glyph_widths[idx] + spacing;
}
@@ -404,7 +404,10 @@ impl TrayApp {
continue;
};
let menu_item = MenuItem::new(
format!("{} {}{}", property.prefix, current_value, property.suffix),
format!(
"{} {}{}",
property.pretty_name, current_value, property.suffix
),
false,
None,
);
@@ -415,7 +418,10 @@ impl TrayApp {
continue;
};
let submenu = Submenu::new(
format!("{} {}{}", property.prefix, current_value, property.suffix),
format!(
"{} {}{}",
property.pretty_name, current_value, property.suffix
),
property.property_type == PropertyType::ReadWrite,
);
@@ -446,7 +452,10 @@ impl TrayApp {
let create_event = property.create_event;
let update_sender = self.sender.clone();
let menu_item = MenuItem::new(
format!("{} {}{}", property.prefix, current_value, property.suffix),
format!(
"{} {}{}",
property.pretty_name, current_value, property.suffix
),
property.property_type == PropertyType::ReadWrite
&& property.data.is_some(),
None,
@@ -467,7 +476,10 @@ impl TrayApp {
continue;
};
let menu_item = MenuItem::new(
format!("{} {}{}", property.prefix, current_value, property.suffix),
format!(
"{} {}{}",
property.pretty_name, current_value, property.suffix
),
false,
None,
);