Skip to content

Commit

Permalink
refactor: remove unnecessary mutex
Browse files Browse the repository at this point in the history
continuation of #7721
  • Loading branch information
amrbashir committed Aug 31, 2023
1 parent 49beb67 commit 3bde4b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
Expand Down Expand Up @@ -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)),
},
Expand Down Expand Up @@ -2682,41 +2682,41 @@ 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);
}
}
}
#[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);
}
}
TrayMessage::Create(_tray, _tx) => {
// 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();
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/src/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 3bde4b3

Please sign in to comment.