From ad83e043ef24bd4da4e33e110c998e31f97c06e4 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Tue, 27 Aug 2024 01:49:16 +0300 Subject: [PATCH 1/2] feat: add `DoubleClick` variant for `TrayIconEvent` --- .changes/tray-double-click.md | 5 +++++ Cargo.lock | 4 ++-- core/tauri/Cargo.toml | 2 +- core/tauri/src/tray/mod.rs | 26 ++++++++++++++++++++++++++ examples/api/src-tauri/src/tray.rs | 3 +-- 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 .changes/tray-double-click.md diff --git a/.changes/tray-double-click.md b/.changes/tray-double-click.md new file mode 100644 index 000000000000..af9b54ebe351 --- /dev/null +++ b/.changes/tray-double-click.md @@ -0,0 +1,5 @@ +--- +"tauri": "patch:feat" +--- + +On Windows, Add and emit `DoubleClick` variant for `TrayIconEvent`. diff --git a/Cargo.lock b/Cargo.lock index 589218b06f05..2e5bfbdadbf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4350,9 +4350,9 @@ dependencies = [ [[package]] name = "tray-icon" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b92252d649d771105448969f2b2dda4342ba48b77731b60d37c93665e26615b" +checksum = "131a65b2cef2081bc14dbcd414c906edbfa3bb5323dd7e748cc298614681196b" dependencies = [ "core-graphics 0.24.0", "crossbeam-channel", diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index c31a072475ef..7f67bcd68440 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -79,7 +79,7 @@ specta = { version = "^2.0.0-rc.16", optional = true, default-features = false, [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies] muda = { version = "0.14", default-features = false, features = [ "serde" ] } -tray-icon = { version = "0.15", default-features = false, features = [ "serde" ], optional = true } +tray-icon = { version = "0.16", default-features = false, features = [ "serde" ], optional = true } [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] gtk = { version = "0.18", features = [ "v3_24" ] } diff --git a/core/tauri/src/tray/mod.rs b/core/tauri/src/tray/mod.rs index 3363192d8937..53d1589078b7 100644 --- a/core/tauri/src/tray/mod.rs +++ b/core/tauri/src/tray/mod.rs @@ -91,6 +91,17 @@ pub enum TrayIconEvent { /// Mouse button state when this event was triggered. button_state: MouseButtonState, }, + /// A double click happened on the tray icon. **Windows Only** + DoubleClick { + /// Id of the tray icon which triggered this event. + id: TrayIconId, + /// Physical Position of this event. + position: PhysicalPosition, + /// Position and size of the tray icon. + rect: Rect, + /// Mouse button that triggered this event. + button: MouseButton, + }, /// The mouse entered the tray icon region. Enter { /// Id of the tray icon which triggered this event. @@ -125,6 +136,7 @@ impl TrayIconEvent { pub fn id(&self) -> &TrayIconId { match self { TrayIconEvent::Click { id, .. } => id, + TrayIconEvent::DoubleClick { id, .. } => id, TrayIconEvent::Enter { id, .. } => id, TrayIconEvent::Move { id, .. } => id, TrayIconEvent::Leave { id, .. } => id, @@ -151,6 +163,20 @@ impl From for TrayIconEvent { button: button.into(), button_state: button_state.into(), }, + tray_icon::TrayIconEvent::DoubleClick { + id, + position, + rect, + button, + } => TrayIconEvent::DoubleClick { + id, + position, + rect: Rect { + position: rect.position.into(), + size: rect.size.into(), + }, + button: button.into(), + }, tray_icon::TrayIconEvent::Enter { id, position, rect } => TrayIconEvent::Enter { id, position, diff --git a/examples/api/src-tauri/src/tray.rs b/examples/api/src-tauri/src/tray.rs index 196c248f6e0b..aae37c54fbdb 100644 --- a/examples/api/src-tauri/src/tray.rs +++ b/examples/api/src-tauri/src/tray.rs @@ -107,9 +107,8 @@ pub fn create_tray(app: &tauri::AppHandle) -> tauri::Result<()> { _ => {} }) .on_tray_icon_event(|tray, event| { - if let TrayIconEvent::Click { + if let TrayIconEvent::DoubleClick { button: MouseButton::Left, - button_state: MouseButtonState::Up, .. } = event { From 3b31164ddb5d3576353af10f2216f8a96df9fc7b Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 27 Aug 2024 08:41:15 -0300 Subject: [PATCH 2/2] revert api example change --- examples/api/src-tauri/src/tray.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/api/src-tauri/src/tray.rs b/examples/api/src-tauri/src/tray.rs index 21efad225539..25730884a3c4 100644 --- a/examples/api/src-tauri/src/tray.rs +++ b/examples/api/src-tauri/src/tray.rs @@ -109,8 +109,9 @@ pub fn create_tray(app: &tauri::AppHandle) -> tauri::Result<()> { _ => {} }) .on_tray_icon_event(|tray, event| { - if let TrayIconEvent::DoubleClick { + if let TrayIconEvent::Click { button: MouseButton::Left, + button_state: MouseButtonState::Up, .. } = event {