feat(tray): add TrayIcon::rect method (#9615)

This commit is contained in:
Andrej Mihajlov 2024-05-03 04:56:54 +02:00 committed by GitHub
parent f1badb9fb3
commit 07ff78c2de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 9 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": "minor:feat"
---
Add `TrayIcon::rect` method to retrieve the tray icon rectangle

6
Cargo.lock generated
View File

@ -1765,7 +1765,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
dependencies = [
"cfg-if",
"windows-targets 0.52.5",
"windows-targets 0.48.5",
]
[[package]]
@ -4077,9 +4077,9 @@ dependencies = [
[[package]]
name = "tray-icon"
version = "0.13.0"
version = "0.13.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8713f74e697917aa794800289e15bce534fc91450312ab2d3edf5b8907f7301a"
checksum = "39240037d755a1832e752d64f99078c3b0b21c09a71c12405070c75ef4e7cd3c"
dependencies = [
"cocoa",
"core-graphics",

View File

@ -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)
}
}

View File

@ -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;

View File

@ -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,
@ -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,
@ -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,

View File

@ -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> {