Skip to content

Commit 4737cbf

Browse files
committed
linux-rust: add battery to window and add option for text in tray
1 parent 093554d commit 4737cbf

File tree

7 files changed

+214
-54
lines changed

7 files changed

+214
-54
lines changed

linux-rust/assets/font/sf_pro.otf

5.16 MB
Binary file not shown.

linux-rust/flatpak/me.kavishdevar.librepods.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ command: librepods
1010
finish-args:
1111
- --socket=wayland
1212
- --socket=fallback-x11
13-
- --share=ipc
1413
- --socket=pulseaudio
1514
- --system-talk-name=org.bluez
1615
- --allow=bluetooth

linux-rust/src/devices/enums.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::Display;
2-
use iced::widget::{combo_box, ComboBox};
2+
use iced::widget::combo_box;
33
use serde::{Deserialize, Serialize};
4+
use crate::bluetooth::aacp::BatteryInfo;
45
use crate::devices::airpods::AirPodsInformation;
56
use crate::devices::nothing::NothingInformation;
67

@@ -58,7 +59,8 @@ pub struct AirPodsState {
5859
pub noise_control_state: combo_box::State<AirPodsNoiseControlMode>,
5960
pub conversation_awareness_enabled: bool,
6061
pub personalized_volume_enabled: bool,
61-
pub allow_off_mode: bool
62+
pub allow_off_mode: bool,
63+
pub battery: Vec<BatteryInfo>
6264
}
6365

6466
#[derive(Clone, Debug)]

linux-rust/src/main.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,33 @@ use crate::utils::get_devices_path;
2828

2929
#[derive(Parser)]
3030
struct Args {
31-
#[arg(long)]
31+
#[arg(long, short='d', help="Enable debug logging")]
3232
debug: bool,
33-
#[arg(long)]
33+
#[arg(long, help="Disable system tray, useful if your environment doesn't support AppIndicator or StatusNotifier")]
3434
no_tray: bool,
35-
#[arg(long)]
35+
#[arg(long, help="Start the application minimized to tray")]
3636
start_minimized: bool,
37+
#[arg(long, help="Enable Bluetooth LE debug logging. Only use when absolutely necessary; this produces a lot of logs.")]
38+
le_debug: bool,
39+
#[arg(long, short='v', help="Show application version and exit")]
40+
version: bool
3741
}
3842

3943
fn main() -> iced::Result {
4044
let args = Args::parse();
45+
46+
if args.version {
47+
println!("You are running LibrePods version {}", env!("CARGO_PKG_VERSION"));
48+
return Ok(());
49+
}
50+
4151
let log_level = if args.debug { "debug" } else { "info" };
52+
let wayland_display = env::var("WAYLAND_DISPLAY").is_ok();
4253
if env::var("RUST_LOG").is_err() {
43-
unsafe { env::set_var("RUST_LOG", log_level.to_owned() + ",winit=warn,tracing=warn,,iced_wgpu=warn,wgpu_hal=warn,wgpu_core=warn,librepods_rust::bluetooth::le=warn,cosmic_text=warn,naga=warn,iced_winit=warn") };
54+
if wayland_display {
55+
unsafe { env::set_var("WGPU_BACKEND", "gl") };
56+
}
57+
unsafe { env::set_var("RUST_LOG", log_level.to_owned() + &format!(",winit=warn,tracing=warn,iced_wgpu=warn,wgpu_hal=warn,wgpu_core=warn,cosmic_text=warn,naga=warn,iced_winit=warn,librepods_rust::bluetooth::le={}", if args.le_debug { "debug" } else { "warn" })) };
4458
}
4559
env_logger::init();
4660

linux-rust/src/ui/airpods.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn airpods_view<'a>(
2424
) -> iced::widget::Container<'a, Message> {
2525
let mac = mac.to_string();
2626
// order: name, noise control, press and hold config, call controls (not sure if why it might be needed, adding it just in case), audio (personalized volume, conversational awareness, adaptive audio slider), connection settings, microphone, head gestures (not adding this), off listening mode, device information
27+
2728
let aacp_manager_for_rename = aacp_manager.clone();
2829
let rename_input = container(
2930
row![
@@ -221,14 +222,13 @@ pub fn airpods_view<'a>(
221222
column![
222223
text("Personalized Volume").size(16),
223224
text("Adjusts the volume in response to your environment.").size(12).style(
224-
|theme: &Theme| {
225-
let mut style = text::Style::default();
226-
style.color = Some(theme.palette().text.scale_alpha(0.7));
227-
style
228-
}
229-
)
230-
],
231-
Space::with_width(Length::Fill),
225+
|theme: &Theme| {
226+
let mut style = text::Style::default();
227+
style.color = Some(theme.palette().text.scale_alpha(0.7));
228+
style
229+
}
230+
).width(Length::Fill),
231+
].width(Length::Fill),
232232
toggler(state.personalized_volume_enabled)
233233
.on_toggle(
234234
{
@@ -255,6 +255,7 @@ pub fn airpods_view<'a>(
255255
.size(20)
256256
]
257257
.align_y(Center)
258+
.spacing(8)
258259
},
259260
Rule::horizontal(8).style(
260261
|theme: &Theme| {
@@ -272,14 +273,13 @@ pub fn airpods_view<'a>(
272273
column![
273274
text("Conversation Awareness").size(16),
274275
text("Lowers the volume of your audio when it detects that you are speaking.").size(12).style(
275-
|theme: &Theme| {
276-
let mut style = text::Style::default();
277-
style.color = Some(theme.palette().text.scale_alpha(0.7));
278-
style
279-
}
280-
)
281-
],
282-
Space::with_width(Length::Fill),
276+
|theme: &Theme| {
277+
let mut style = text::Style::default();
278+
style.color = Some(theme.palette().text.scale_alpha(0.7));
279+
style
280+
}
281+
).width(Length::Fill),
282+
].width(Length::Fill),
283283
toggler(state.conversation_awareness_enabled)
284284
.on_toggle(move |is_enabled| {
285285
let aacp_manager = aacp_manager_conv_detect.clone();
@@ -299,6 +299,7 @@ pub fn airpods_view<'a>(
299299
.size(20)
300300
]
301301
.align_y(Center)
302+
.spacing(8)
302303
}
303304
]
304305
.spacing(4)
@@ -328,15 +329,14 @@ pub fn airpods_view<'a>(
328329
container(row![
329330
column![
330331
text("Off Listening Mode").size(16),
331-
text("When this is on, AIrPods listening modes will include an Off option. Loud sound levels are not reduced when listening mode is set to Off.").size(12).style(
332+
text("When this is on, AirPods listening modes will include an Off option. Loud sound levels are not reduced when listening mode is set to Off.").size(12).style(
332333
|theme: &Theme| {
333334
let mut style = text::Style::default();
334335
style.color = Some(theme.palette().text.scale_alpha(0.7));
335336
style
336337
}
337-
)
338-
],
339-
Space::with_width(Length::Fill),
338+
).width(Length::Fill)
339+
].width(Length::Fill),
340340
toggler(state.allow_off_mode)
341341
.on_toggle(move |is_enabled| {
342342
let aacp_manager = aacp_manager_olm.clone();
@@ -356,6 +356,7 @@ pub fn airpods_view<'a>(
356356
.size(20)
357357
]
358358
.align_y(Center)
359+
.spacing(8)
359360
)
360361
.padding(Padding{
361362
top: 5.0,

linux-rust/src/ui/tray.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use tokio::sync::mpsc::UnboundedSender;
66

77
use crate::bluetooth::aacp::ControlCommandIdentifiers;
88
use crate::ui::messages::BluetoothUIMessage;
9+
use crate::utils::get_app_settings_path;
910

1011
#[derive(Debug)]
1112
pub(crate) struct MyTray {
@@ -57,7 +58,15 @@ impl ksni::Tray for MyTray {
5758
};
5859
let any_bud_charging = matches!(self.battery_l_status, Some(crate::bluetooth::aacp::BatteryStatus::Charging))
5960
|| matches!(self.battery_r_status, Some(crate::bluetooth::aacp::BatteryStatus::Charging));
60-
let icon = generate_icon(&text, false, any_bud_charging);
61+
let app_settings_path = get_app_settings_path();
62+
let settings = std::fs::read_to_string(&app_settings_path)
63+
.ok()
64+
.and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok());
65+
let text_mode = settings.clone()
66+
.and_then(|v| v.get("tray_text_mode").cloned())
67+
.and_then(|ttm| serde_json::from_value(ttm).ok())
68+
.unwrap_or(false);
69+
let icon = generate_icon(&text, text_mode, any_bud_charging);
6170
vec![icon]
6271
}
6372
fn tool_tip(&self) -> ToolTip {

0 commit comments

Comments
 (0)