Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions linux-rust/src/devices/airpods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::Mutex;
use tokio::time::{Duration, sleep};
use crate::utils::get_app_settings_path;
use crate::utils::AppSettings;

pub struct AirPodsDevice {
pub mac_address: Address,
Expand Down Expand Up @@ -81,16 +81,7 @@ impl AirPodsDevice {
error!("Failed to request proximity keys: {}", e);
}

let app_settings_path = get_app_settings_path();
let settings = std::fs::read_to_string(&app_settings_path)
.ok()
.and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok());
let stem_control = settings
.clone()
.and_then(|v| v.get("stem_control").cloned())
.and_then(|s| serde_json::from_value(s).ok())
.unwrap_or(false);

let stem_control = AppSettings::load().stem_control;
if stem_control {
// Enable stem press detection (double and triple tap)
// StemConfig bitmask for the control command: single=0x01, double=0x02, triple=0x04, long=0x08
Expand Down
6 changes: 2 additions & 4 deletions linux-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::bluetooth::managers::DeviceManagers;
use crate::devices::enums::DeviceData;
use crate::ui::messages::BluetoothUIMessage;
use crate::ui::tray::MyTray;
use crate::utils::{get_app_settings_path, get_devices_path};
use crate::utils::get_devices_path;
use bluer::{Address, InternalErrorKind};
use clap::Parser;
use dbus::arg::{RefArg, Variant};
Expand All @@ -19,10 +19,9 @@ use dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
use dbus::message::MatchRule;
use devices::airpods::AirPodsDevice;
use ksni::TrayMethods;
use log::{debug, info, warn};
use log::{info, warn};
use std::collections::HashMap;
use std::env;
use std::sync::atomic::{AtomicBool};
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio::sync::mpsc::unbounded_channel;
Expand Down Expand Up @@ -82,7 +81,6 @@ fn main() -> iced::Result {
let device_managers: Arc<RwLock<HashMap<String, DeviceManagers>>> =
Arc::new(RwLock::new(HashMap::new()));

// Load stem_control initial value from settings JSON, then apply CLI override.
if args.no_tray {
// Run headless without UI
info!("Running in headless mode (no GUI)");
Expand Down
12 changes: 2 additions & 10 deletions linux-rust/src/ui/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::sync::mpsc::UnboundedSender;

use crate::bluetooth::aacp::{BatteryStatus, ControlCommandIdentifiers};
use crate::ui::messages::BluetoothUIMessage;
use crate::utils::get_app_settings_path;
use crate::utils::AppSettings;

#[derive(Debug)]
pub struct MyTray {
Expand Down Expand Up @@ -66,15 +66,7 @@ impl ksni::Tray for MyTray {
};
let any_bud_charging = matches!(self.battery_l_status, Some(BatteryStatus::Charging))
|| matches!(self.battery_r_status, Some(BatteryStatus::Charging));
let app_settings_path = get_app_settings_path();
let settings = std::fs::read_to_string(&app_settings_path)
.ok()
.and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok());
let text_mode = settings
.clone()
.and_then(|v| v.get("tray_text_mode").cloned())
.and_then(|ttm| serde_json::from_value(ttm).ok())
.unwrap_or(false);
let text_mode = AppSettings::load().tray_text_mode;
let icon = generate_icon(&text, text_mode, any_bud_charging);
vec![icon]
}
Expand Down
Loading