Skip to content

Commit fc30b20

Browse files
authored
feat(api/tray): add TrayIcon.setShowMenuOnLeftClick method (#11726)
1 parent 7a9b920 commit fc30b20

File tree

19 files changed

+203
-74
lines changed

19 files changed

+203
-74
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/api": "minor:feat"
3+
---
4+
5+
Add `TrayIcon.setShowMenuOnLeftClick` method and deprecate `TrayIcon.setMenuOnLeftClick` to match the Rust API.
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/api": "minor:feat"
3+
---
4+
5+
Add `TrayIconOptions.showMenuOnLeftClick` field and deprecate `TrayIconOptions.menuOnLeftClick` to match the Rust API.
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": "minor:feat"
3+
---
4+
5+
Add `TrayIconBuilder::show_menu_on_left_click` method and deprecate `TrayIconBuilder::menu_on_left_click` for consistent naming and clarity.
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/api": "minor:enhance"
3+
---
4+
5+
Add support for `TrayIconOptions.menuOnLeftClick` option and `TrayIcon.setMenuOnLeftClick` on Windows.
6+
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
"tauri": patch:bug
2+
"tauri": "minor:enhance"
33
---
44

5-
Support for `set_show_menu_on_left_click` was implemented on Windows too. So it
6-
should not be macOS anymore. [tauri-apps/tray-icon#199](https://github.com/tauri-apps/tray-icon/pull/199)
5+
Add support for `TrayIconBuilder::menu_on_left_click` and `TrayIcon::set_show_menu_on_left_click` on Windows.
6+

crates/tauri-cli/config.schema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,13 @@
16241624
"type": "boolean"
16251625
},
16261626
"menuOnLeftClick": {
1627-
"description": "A Boolean value that determines whether the menu should appear when the tray icon receives a left click on macOS.",
1627+
"description": "A Boolean value that determines whether the menu should appear when the tray icon receives a left click.\n\n ## Platform-specific:\n\n - **Linux**: Unsupported.",
1628+
"default": true,
1629+
"deprecated": true,
1630+
"type": "boolean"
1631+
},
1632+
"showMenuOnLeftClick": {
1633+
"description": "A Boolean value that determines whether the menu should appear when the tray icon receives a left click.\n\n ## Platform-specific:\n\n - **Linux**: Unsupported.",
16281634
"default": true,
16291635
"type": "boolean"
16301636
},

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,13 @@
16241624
"type": "boolean"
16251625
},
16261626
"menuOnLeftClick": {
1627-
"description": "A Boolean value that determines whether the menu should appear when the tray icon receives a left click on macOS.",
1627+
"description": "A Boolean value that determines whether the menu should appear when the tray icon receives a left click.\n\n ## Platform-specific:\n\n - **Linux**: Unsupported.",
1628+
"default": true,
1629+
"deprecated": true,
1630+
"type": "boolean"
1631+
},
1632+
"showMenuOnLeftClick": {
1633+
"description": "A Boolean value that determines whether the menu should appear when the tray icon receives a left click.\n\n ## Platform-specific:\n\n - **Linux**: Unsupported.",
16281634
"default": true,
16291635
"type": "boolean"
16301636
},

crates/tauri-utils/src/config.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,9 +2431,21 @@ pub struct TrayIconConfig {
24312431
/// A Boolean value that determines whether the image represents a [template](https://developer.apple.com/documentation/appkit/nsimage/1520017-template?language=objc) image on macOS.
24322432
#[serde(default, alias = "icon-as-template")]
24332433
pub icon_as_template: bool,
2434-
/// A Boolean value that determines whether the menu should appear when the tray icon receives a left click on macOS.
2434+
/// A Boolean value that determines whether the menu should appear when the tray icon receives a left click.
2435+
///
2436+
/// ## Platform-specific:
2437+
///
2438+
/// - **Linux**: Unsupported.
24352439
#[serde(default = "default_true", alias = "menu-on-left-click")]
2440+
#[deprecated(since = "2.2.0", note = "Use `show_menu_on_left_click` instead.")]
24362441
pub menu_on_left_click: bool,
2442+
/// A Boolean value that determines whether the menu should appear when the tray icon receives a left click.
2443+
///
2444+
/// ## Platform-specific:
2445+
///
2446+
/// - **Linux**: Unsupported.
2447+
#[serde(default = "default_true", alias = "show-menu-on-left-click")]
2448+
pub show_menu_on_left_click: bool,
24372449
/// Title for MacOS tray
24382450
pub title: Option<String>,
24392451
/// Tray icon tooltip on Windows and macOS
@@ -3351,7 +3363,9 @@ mod build {
33513363
fn to_tokens(&self, tokens: &mut TokenStream) {
33523364
let id = opt_str_lit(self.id.as_ref());
33533365
let icon_as_template = self.icon_as_template;
3366+
#[allow(deprecated)]
33543367
let menu_on_left_click = self.menu_on_left_click;
3368+
let show_menu_on_left_click = self.show_menu_on_left_click;
33553369
let icon_path = path_buf_lit(&self.icon_path);
33563370
let title = opt_str_lit(self.title.as_ref());
33573371
let tooltip = opt_str_lit(self.tooltip.as_ref());
@@ -3362,6 +3376,7 @@ mod build {
33623376
icon_path,
33633377
icon_as_template,
33643378
menu_on_left_click,
3379+
show_menu_on_left_click,
33653380
title,
33663381
tooltip
33673382
);

crates/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri/src/app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2042,10 +2042,12 @@ tauri::Builder::default()
20422042
{
20432043
let config = app.config();
20442044
if let Some(tray_config) = &config.app.tray_icon {
2045+
#[allow(deprecated)]
20452046
let mut tray =
20462047
TrayIconBuilder::with_id(tray_config.id.clone().unwrap_or_else(|| "main".into()))
20472048
.icon_as_template(tray_config.icon_as_template)
2048-
.menu_on_left_click(tray_config.menu_on_left_click);
2049+
.menu_on_left_click(tray_config.menu_on_left_click)
2050+
.show_menu_on_left_click(tray_config.show_menu_on_left_click);
20492051
if let Some(icon) = &app.manager.tray.icon {
20502052
tray = tray.icon(icon.clone());
20512053
}

0 commit comments

Comments
 (0)