refactor: remove unnecessary mutex (#7728)

This commit is contained in:
Amr Bashir 2023-09-07 15:09:59 +03:00 committed by GitHub
parent 50878901ba
commit 53ab2042fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -2102,7 +2102,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
.insert(
id,
TrayContext {
tray: Rc::new(Mutex::new(Some(tray))),
tray: Rc::new(RefCell::new(Some(tray))),
listeners: Rc::new(RefCell::new(listeners)),
items: Rc::new(RefCell::new(items)),
},
@ -2653,7 +2653,7 @@ fn handle_user_message<T: UserEvent>(
trays.insert(
tray_id,
TrayContext {
tray: Rc::new(Mutex::new(Some(tray))),
tray: Rc::new(RefCell::new(Some(tray))),
listeners: Rc::new(RefCell::new(listeners)),
items: Rc::new(RefCell::new(items)),
},
@ -2682,14 +2682,14 @@ fn handle_user_message<T: UserEvent>(
}
}
TrayMessage::UpdateMenu(menu) => {
if let Some(tray) = &mut *tray_context.tray.lock().unwrap() {
if let Some(tray) = &mut *tray_context.tray.borrow_mut() {
let mut items = HashMap::new();
tray.set_menu(&to_wry_context_menu(&mut items, menu));
*tray_context.items.borrow_mut() = items;
}
}
TrayMessage::UpdateIcon(icon) => {
if let Some(tray) = &mut *tray_context.tray.lock().unwrap() {
if let Some(tray) = &mut *tray_context.tray.borrow_mut() {
if let Ok(icon) = TrayIcon::try_from(icon) {
tray.set_icon(icon.0);
}
@ -2697,18 +2697,18 @@ fn handle_user_message<T: UserEvent>(
}
#[cfg(target_os = "macos")]
TrayMessage::UpdateIconAsTemplate(is_template) => {
if let Some(tray) = &mut *tray_context.tray.lock().unwrap() {
if let Some(tray) = &mut *tray_context.tray.borrow_mut() {
tray.set_icon_as_template(is_template);
}
}
#[cfg(target_os = "macos")]
TrayMessage::UpdateTitle(title) => {
if let Some(tray) = &mut *tray_context.tray.lock().unwrap() {
if let Some(tray) = &mut *tray_context.tray.borrow_mut() {
tray.set_title(&title);
}
}
TrayMessage::UpdateTooltip(tooltip) => {
if let Some(tray) = &mut *tray_context.tray.lock().unwrap() {
if let Some(tray) = &mut *tray_context.tray.borrow_mut() {
tray.set_tooltip(&tooltip);
}
}
@ -2716,7 +2716,7 @@ fn handle_user_message<T: UserEvent>(
// already handled
}
TrayMessage::Destroy(tx) => {
*tray_context.tray.lock().unwrap() = None;
*tray_context.tray.borrow_mut() = None;
tray_context.listeners.borrow_mut().clear();
tray_context.items.borrow_mut().clear();
tx.send(Ok(())).unwrap();

View File

@ -48,7 +48,7 @@ pub type SystemTrayItems = Rc<RefCell<HashMap<u16, WryCustomMenuItem>>>;
#[derive(Clone, Default)]
pub struct TrayContext {
pub tray: Rc<Mutex<Option<WrySystemTray>>>,
pub tray: Rc<RefCell<Option<WrySystemTray>>>,
pub listeners: SystemTrayEventListeners,
pub items: SystemTrayItems,
}