Skip to content

Commit

Permalink
macos fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zzeneg committed Oct 2, 2024
1 parent c07f13b commit 0dceaf7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ fn get_providers(data_sender: &broadcast::Sender<Vec<u8>>) -> Vec<Box<dyn Provid
}

#[cfg(target_os = "macos")]
fn get_providers(data_sender: &broadcast::Sender<Vec<u8>>, layouts: Vec<String>) -> Vec<Box<dyn Provider>> {
fn get_providers(data_sender: &broadcast::Sender<Vec<u8>>) -> Vec<Box<dyn Provider>> {
return vec![
TimeProvider::new(data_sender.clone()),
VolumeProvider::new(data_sender.clone()),
LayoutProvider::new(data_sender.clone(), layouts),
LayoutProvider::new(data_sender.clone()),
];
}

Expand Down
27 changes: 14 additions & 13 deletions src/providers/layout/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,25 @@ impl Provider for LayoutProvider {
let is_started = self.is_started.clone();
let mut synced_layout = "".to_string();

std::thread::spawn(move || {
let mut connected_receiver = connected_sender.subscribe();
loop {
if !is_started.load(Relaxed) {
break;
}
std::thread::spawn(move || loop {
if !is_started.load(Relaxed) {
break;
}

if let Some(layout) = get_keyboard_layout() {
let lang = layout.split('.').last().unwrap().to_string();
if synced_layout != lang {
synced_layout = lang;
send_data(&synced_layout, &layouts, &data_sender);
}
if let Some(layout) = get_keyboard_layout() {
let lang = layout.split('.').last().unwrap().to_string();
if synced_layout != lang {
synced_layout = lang;
send_data(&synced_layout, &layouts, &data_sender);
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
std::thread::sleep(std::time::Duration::from_millis(100));
});

tracing::info!("Layout Provider stopped");
}

fn stop(&self) {
self.is_started.store(false, Relaxed);
}
}
2 changes: 1 addition & 1 deletion src/providers/volume/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub struct VolumeProvider {
}

impl VolumeProvider {
pub fn new(data_sender: mpsc::Sender<Vec<u8>>) -> Box<dyn Provider> {
pub fn new(data_sender: broadcast::Sender<Vec<u8>>) -> Box<dyn Provider> {
let sender = data_sender.clone();
let volume_changed_block = RcBlock::new(move |_: u32, _: u64| {
if let Some(volume) = get_current_volume() {
Expand Down

0 comments on commit 0dceaf7

Please sign in to comment.