Skip to content

Commit

Permalink
Remove the Sync requirement to callback closures
Browse files Browse the repository at this point in the history
  • Loading branch information
iovxw committed Feb 22, 2024
1 parent 929aa47 commit fa55ed8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::collections::HashMap;
use std::fmt;
use std::sync::Arc;
use std::sync::{Arc, Mutex};

use zbus::zvariant::{OwnedValue, Value};

Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct StandardItem<T> {
/// How the menuitem feels the information it's displaying to the
/// user should be presented.
pub disposition: Disposition,
pub activate: Box<dyn Fn(&mut T) + Send + Sync>,
pub activate: Box<dyn Fn(&mut T) + Send>,
}

impl<T> Default for StandardItem<T> {
Expand Down Expand Up @@ -240,7 +240,7 @@ pub struct CheckmarkItem<T> {
/// How the menuitem feels the information it's displaying to the
/// user should be presented.
pub disposition: Disposition,
pub activate: Box<dyn Fn(&mut T) + Send + Sync>,
pub activate: Box<dyn Fn(&mut T) + Send>,
}

impl<T> Default for CheckmarkItem<T> {
Expand Down Expand Up @@ -294,7 +294,7 @@ impl<T: 'static> From<CheckmarkItem<T>> for RawMenuItem<T> {
/// Menu item, contains [`RadioItem`]
pub struct RadioGroup<T> {
pub selected: usize,
pub select: Box<dyn Fn(&mut T, usize) + Send + Sync>,
pub select: Box<dyn Fn(&mut T, usize) + Send>,
pub options: Vec<RadioItem>,
}

Expand Down Expand Up @@ -398,7 +398,7 @@ pub(crate) struct RawMenuItem<T> {
/// How the menuitem feels the information it's displaying to the
/// user should be presented.
disposition: Disposition,
pub on_clicked: Box<dyn Fn(&mut T, usize) + Send + Sync>,
pub on_clicked: Box<dyn Fn(&mut T, usize) + Send>,
}

macro_rules! if_not_default_then_insert {
Expand Down Expand Up @@ -712,7 +712,7 @@ pub(crate) fn menu_flatten<T: 'static>(
}
MenuItem::RadioGroup(group) => {
let offset = list.len();
let on_selected = Arc::new(group.select);
let on_selected = Arc::new(Mutex::new(group.select));
for (idx, option) in group.options.into_iter().enumerate() {
let on_selected = on_selected.clone();
let item = RawMenuItem {
Expand All @@ -731,7 +731,7 @@ pub(crate) fn menu_flatten<T: 'static>(
},
disposition: option.disposition,
on_clicked: Box::new(move |this: &mut T, id| {
(on_selected)(this, id - offset);
(on_selected.lock().unwrap())(this, id - offset);
}),
..Default::default()
};
Expand Down

0 comments on commit fa55ed8

Please sign in to comment.