From 07ff78c2de74d3bd85328ce6536f8a858be89128 Mon Sep 17 00:00:00 2001 From: Andrej Mihajlov Date: Fri, 3 May 2024 04:56:54 +0200 Subject: [PATCH] feat(tray): add `TrayIcon::rect` method (#9615) --- .changes/tray-icon-rect.md | 5 +++++ Cargo.lock | 6 +++--- core/tauri-build/src/manifest.rs | 2 +- core/tauri-runtime-wry/src/lib.rs | 6 ++++-- core/tauri/src/async_runtime.rs | 6 +++--- core/tauri/src/tray/mod.rs | 14 ++++++++++++++ 6 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 .changes/tray-icon-rect.md diff --git a/.changes/tray-icon-rect.md b/.changes/tray-icon-rect.md new file mode 100644 index 000000000..1eae30d7f --- /dev/null +++ b/.changes/tray-icon-rect.md @@ -0,0 +1,5 @@ +--- +"tauri": "minor:feat" +--- + +Add `TrayIcon::rect` method to retrieve the tray icon rectangle \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index e80b86940..20f19ab45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/core/tauri-build/src/manifest.rs b/core/tauri-build/src/manifest.rs index e321a3624..fbcb82795 100644 --- a/core/tauri-build/src/manifest.rs +++ b/core/tauri-build/src/manifest.rs @@ -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) } } diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 9d886cef8..16a26d68b 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -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::() as u32; + let mut monitor_info = MONITORINFO { + cbSize: std::mem::size_of::() 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; diff --git a/core/tauri/src/async_runtime.rs b/core/tauri/src/async_runtime.rs index f3ef1d140..4925878ce 100644 --- a/core/tauri/src/async_runtime.rs +++ b/core/tauri/src/async_runtime.rs @@ -42,7 +42,7 @@ impl GlobalRuntime { } } - fn spawn(&self, task: F) -> JoinHandle + fn spawn(&self, task: F) -> JoinHandle where F: Future + Send + 'static, F::Output: Send + 'static, @@ -96,7 +96,7 @@ impl Runtime { } /// Spawns a future onto the runtime. - pub fn spawn(&self, task: F) -> JoinHandle + pub fn spawn(&self, task: F) -> JoinHandle where F: Future + Send + 'static, F::Output: Send + 'static, @@ -189,7 +189,7 @@ impl RuntimeHandle { } /// Spawns a future onto the runtime. - pub fn spawn(&self, task: F) -> JoinHandle + pub fn spawn(&self, task: F) -> JoinHandle where F: Future + Send + 'static, F::Output: Send + 'static, diff --git a/core/tauri/src/tray/mod.rs b/core/tauri/src/tray/mod.rs index 66b9e2b83..7f0919ff4 100644 --- a/core/tauri/src/tray/mod.rs +++ b/core/tauri/src/tray/mod.rs @@ -421,6 +421,20 @@ impl TrayIcon { .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> { + run_item_main_thread!(self, |self_: Self| self_.inner.rect().map(|rect| { + Rect { + position: rect.position.into(), + size: rect.size.into(), + } + })) + } } impl Resource for TrayIcon {