Repository: tauri-apps/tauri
File: crates/tauri/src/tray/mod.rs (Rust)

Code before:
  /// ## Platform-specific:
  ///
  /// - **Linux**: Unsupported.
  pub fn set_show_menu_on_left_click(&self, #[allow(unused)] enable: bool) -> crate::Result<()> {
    #[cfg(any(target_os = "macos", windows))]
    run_item_main_thread!(self, |self_: Self| {
      self_.inner.set_show_menu_on_left_click(enable)
    })?;
    Ok(())
  }

  /// Get tray icon rect.
  ///
  /// ## Platform-specific:
  ///
  /// - **Linux**: Unsupported, always returns `None`.
  pub fn rect(&self) -> crate::Result<Option<crate::Rect>> {
    run_item_main_thread!(self, |self_: Self| {
      self_.inner.rect().map(|rect| Rect {
        position: rect.position.into(),
        size: rect.size.into(),
      })
    })
  }

  /// Get the inner tray icon.
  ///
  /// Note that `tray-icon` crate may be updated in minor releases of Tauri.
  /// Therefore, it’s recommended to pin Tauri to at least a minor version when you’re using `with_inner_tray_icon`.
  pub fn with_inner_tray_icon<F, T>(&self, f: F) -> crate::Result<T>
  where
    F: FnOnce(tray_icon::TrayIcon) -> T + Send + 'static,
    T: Send + 'static,
  {
    run_item_main_thread!(self, |self_: Self| { f(self_.inner.clone()) })
  }
}

impl<R: Runtime> Resource for TrayIcon<R> {
  fn close(self: std::sync::Arc<Self>) {
    let mut icons = self.app_handle.manager.tray.icons.lock().unwrap();
    for (i, (tray_icon_id, _rid)) in icons.iter_mut().enumerate() {
      if tray_icon_id == &self.id {
        icons.swap_remove(i);
        return;
      }
    }
  }
}

#[cfg(test)]

Review comment (suggestion):
```suggestion
  /// Do something with the inner [`tray_icon::TrayIcon`] on main thread
```

Code after:
  /// ## Platform-specific:
  ///
  /// - **Linux**: Unsupported.
  pub fn set_show_menu_on_left_click(&self, #[allow(unused)] enable: bool) -> crate::Result<()> {
    #[cfg(any(target_os = "macos", windows))]
    run_item_main_thread!(self, |self_: Self| {
      self_.inner.set_show_menu_on_left_click(enable)
    })?;
    Ok(())
  }

  /// Get tray icon rect.
  ///
  /// ## Platform-specific:
  ///
  /// - **Linux**: Unsupported, always returns `None`.
  pub fn rect(&self) -> crate::Result<Option<crate::Rect>> {
    run_item_main_thread!(self, |self_: Self| {
      self_.inner.rect().map(|rect| Rect {
        position: rect.position.into(),
        size: rect.size.into(),
      })
    })
  }

  /// Do something with the inner [`tray_icon::TrayIcon`] on main thread
  ///
  /// Note that `tray-icon` crate may be updated in minor releases of Tauri.
  /// Therefore, it’s recommended to pin Tauri to at least a minor version when you’re using `with_inner_tray_icon`.
  pub fn with_inner_tray_icon<F, T>(&self, f: F) -> crate::Result<T>
  where
    F: FnOnce(&tray_icon::TrayIcon) -> T + Send + 'static,
    T: Send + 'static,
  {
    run_item_main_thread!(self, |self_: Self| { f(&self_.inner) })
  }
}

impl<R: Runtime> Resource for TrayIcon<R> {
  fn close(self: std::sync::Arc<Self>) {
    let mut icons = self.app_handle.manager.tray.icons.lock().unwrap();
    for (i, (tray_icon_id, _rid)) in icons.iter_mut().enumerate() {
      if tray_icon_id == &self.id {
        icons.swap_remove(i);
        return;
      }
    }
  }
}

#[cfg(test)]