From 73a0beed212fafdfec4851398cd708fa82325a24 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Tue, 14 Nov 2023 00:52:22 +0000 Subject: [PATCH] chore: Merge branch v1 into v2 (#702) Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/6857681267 Co-authored-by: lucasfernog --- package.json | 2 +- src/ext.rs | 49 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 42f0e80..6bee2fb 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "LICENSE" ], "devDependencies": { - "tslib": "2.6.0" + "tslib": "2.6.2" }, "dependencies": { "@tauri-apps/api": "2.0.0-alpha.11" diff --git a/src/ext.rs b/src/ext.rs index 11a725d..36ec7f9 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -109,13 +109,20 @@ impl WindowExt for Window { }, #[cfg(feature = "tray-icon")] TrayLeft => { - if let Some((tray_x, tray_y)) = tray_position { - PhysicalPosition { - x: tray_x, - y: tray_y - window_size.height, - } + if let (Some((tray_x, tray_y)), Some((_, _tray_height))) = + (tray_position, tray_size) + { + let y = tray_y - window_size.height; + // Choose y value based on the target OS + #[cfg(target_os = "windows")] + let y = if y < 0 { tray_y + _tray_height } else { y }; + + #[cfg(target_os = "macos")] + let y = if y < 0 { tray_y } else { y }; + + PhysicalPosition { x: tray_x, y } } else { - panic!("tray position not set"); + panic!("Tray position not set"); } } #[cfg(feature = "tray-icon")] @@ -131,11 +138,20 @@ impl WindowExt for Window { } #[cfg(feature = "tray-icon")] TrayRight => { - if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size) + if let (Some((tray_x, tray_y)), Some((tray_width, _tray_height))) = + (tray_position, tray_size) { + let y = tray_y - window_size.height; + // Choose y value based on the target OS + #[cfg(target_os = "windows")] + let y = if y < 0 { tray_y + _tray_height } else { y }; + + #[cfg(target_os = "macos")] + let y = if y < 0 { tray_y } else { y }; + PhysicalPosition { x: tray_x + tray_width, - y: tray_y - window_size.height, + y, } } else { panic!("Tray position not set"); @@ -155,12 +171,19 @@ impl WindowExt for Window { } #[cfg(feature = "tray-icon")] TrayCenter => { - if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size) + if let (Some((tray_x, tray_y)), Some((tray_width, _tray_height))) = + (tray_position, tray_size) { - PhysicalPosition { - x: tray_x + (tray_width / 2) - (window_size.width / 2), - y: tray_y - window_size.height, - } + let x = tray_x + tray_width / 2 - window_size.width / 2; + let y = tray_y - window_size.height; + // Choose y value based on the target OS + #[cfg(target_os = "windows")] + let y = if y < 0 { tray_y + _tray_height } else { y }; + + #[cfg(target_os = "macos")] + let y = if y < 0 { tray_y } else { y }; + + PhysicalPosition { x, y } } else { panic!("Tray position not set"); }