Skip to content

Commit

Permalink
feat(tray): add TrayIcon::rect method (#9615)
Browse files Browse the repository at this point in the history
  • Loading branch information
pronebird committed May 3, 2024
1 parent f1badb9 commit 07ff78c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/tray-icon-rect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": "minor:feat"
---

Add `TrayIcon::rect` method to retrieve the tray icon rectangle
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/tauri-build/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
if deps.is_empty() {
if let Some(alias) = &metadata.alias {
deps = find_dependency(manifest, alias, metadata.kind);
name = alias.clone();
name.clone_from(alias)
}
}

Expand Down
6 changes: 4 additions & 2 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4136,8 +4136,10 @@ fn calculate_window_center_position(
{
use tao::platform::windows::MonitorHandleExtWindows;
use windows::Win32::Graphics::Gdi::{GetMonitorInfoW, HMONITOR, MONITORINFO};
let mut monitor_info = MONITORINFO::default();
monitor_info.cbSize = std::mem::size_of::<MONITORINFO>() as u32;
let mut monitor_info = MONITORINFO {
cbSize: std::mem::size_of::<MONITORINFO>() as u32,
..Default::default()
};
let status = unsafe { GetMonitorInfoW(HMONITOR(target_monitor.hmonitor()), &mut monitor_info) };
if status.into() {
let available_width = monitor_info.rcWork.right - monitor_info.rcWork.left;
Expand Down
6 changes: 3 additions & 3 deletions core/tauri/src/async_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl GlobalRuntime {
}
}

fn spawn<F: Future>(&self, task: F) -> JoinHandle<F::Output>
fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Runtime {
}

/// Spawns a future onto the runtime.
pub fn spawn<F: Future>(&self, task: F) -> JoinHandle<F::Output>
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
Expand Down Expand Up @@ -189,7 +189,7 @@ impl RuntimeHandle {
}

/// Spawns a future onto the runtime.
pub fn spawn<F: Future>(&self, task: F) -> JoinHandle<F::Output>
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
Expand Down
14 changes: 14 additions & 0 deletions core/tauri/src/tray/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ impl<R: Runtime> TrayIcon<R> {
.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(),
}
}))
}
}

impl<R: Runtime> Resource for TrayIcon<R> {
Expand Down

0 comments on commit 07ff78c

Please sign in to comment.