mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-03 08:36:07 +03:00
* feat(core): add option to disable tray menu on left click, closes #4584 * Update .changes/menu-on-left-click.md [skip ci] Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
This commit is contained in:
parent
f7c59ecfc8
commit
f8a3becb28
5
.changes/menu-on-left-click-config.md
Normal file
5
.changes/menu-on-left-click-config.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-utils": patch
|
||||
---
|
||||
|
||||
Added `menu_on_left_click: bool` to the `SystemTrayConfig`.
|
7
.changes/menu-on-left-click.md
Normal file
7
.changes/menu-on-left-click.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"tauri": patch
|
||||
"tauri-runtime": patch
|
||||
"tauri-runtime-wry": patch
|
||||
---
|
||||
|
||||
Added option to disable tray menu on left click on macOS.
|
@ -1911,7 +1911,9 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
tray_builder = tray_builder.with_icon_as_template(system_tray.icon_as_template);
|
||||
tray_builder = tray_builder
|
||||
.with_icon_as_template(system_tray.icon_as_template)
|
||||
.with_menu_on_left_click(system_tray.menu_on_left_click);
|
||||
}
|
||||
|
||||
let tray = tray_builder
|
||||
|
@ -41,6 +41,8 @@ pub struct SystemTray {
|
||||
pub menu: Option<menu::SystemTrayMenu>,
|
||||
#[cfg(target_os = "macos")]
|
||||
pub icon_as_template: bool,
|
||||
#[cfg(target_os = "macos")]
|
||||
pub menu_on_left_click: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "system-tray")]
|
||||
@ -69,6 +71,14 @@ impl SystemTray {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets whether the menu should appear when the tray receives a left click. Defaults to `true`.
|
||||
#[cfg(target_os = "macos")]
|
||||
#[must_use]
|
||||
pub fn with_menu_on_left_click(mut self, menu_on_left_click: bool) -> Self {
|
||||
self.menu_on_left_click = menu_on_left_click;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the menu to show when the system tray is right clicked.
|
||||
#[must_use]
|
||||
pub fn with_menu(mut self, menu: menu::SystemTrayMenu) -> Self {
|
||||
|
@ -2295,6 +2295,13 @@ pub struct SystemTrayConfig {
|
||||
/// 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.
|
||||
#[serde(default)]
|
||||
pub icon_as_template: bool,
|
||||
/// A Boolean value that determines whether the menu should appear when the tray icon receives a left click on macOS.
|
||||
#[serde(default = "default_tray_menu_on_left_click")]
|
||||
pub menu_on_left_click: bool,
|
||||
}
|
||||
|
||||
fn default_tray_menu_on_left_click() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// We enable the unnecessary_wraps because we need
|
||||
@ -3184,8 +3191,15 @@ mod build {
|
||||
impl ToTokens for SystemTrayConfig {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let icon_as_template = self.icon_as_template;
|
||||
let menu_on_left_click = self.menu_on_left_click;
|
||||
let icon_path = path_buf_lit(&self.icon_path);
|
||||
literal_struct!(tokens, SystemTrayConfig, icon_path, icon_as_template);
|
||||
literal_struct!(
|
||||
tokens,
|
||||
SystemTrayConfig,
|
||||
icon_path,
|
||||
icon_as_template,
|
||||
menu_on_left_click
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1346,12 +1346,12 @@ impl<R: Runtime> Builder<R> {
|
||||
let system_tray_icon = context.system_tray_icon.clone();
|
||||
|
||||
#[cfg(all(feature = "system-tray", target_os = "macos"))]
|
||||
let system_tray_icon_as_template = context
|
||||
let (system_tray_icon_as_template, system_tray_menu_on_left_click) = context
|
||||
.config
|
||||
.tauri
|
||||
.system_tray
|
||||
.as_ref()
|
||||
.map(|t| t.icon_as_template)
|
||||
.map(|t| (t.icon_as_template, t.menu_on_left_click))
|
||||
.unwrap_or_default();
|
||||
|
||||
#[cfg(shell_scope)]
|
||||
@ -1492,7 +1492,9 @@ impl<R: Runtime> Builder<R> {
|
||||
tray = tray.with_menu(menu);
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
let tray = tray.with_icon_as_template(system_tray_icon_as_template);
|
||||
let tray = tray
|
||||
.with_icon_as_template(system_tray_icon_as_template)
|
||||
.with_menu_on_left_click(system_tray_menu_on_left_click);
|
||||
|
||||
let tray_handler = app
|
||||
.runtime
|
||||
|
@ -129,7 +129,8 @@
|
||||
},
|
||||
"systemTray": {
|
||||
"iconPath": "../../.icons/tray_icon_with_transparency.png",
|
||||
"iconAsTemplate": true
|
||||
"iconAsTemplate": true,
|
||||
"menuOnLeftClick": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2409,6 +2409,11 @@
|
||||
"description": "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.",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"menuOnLeftClick": {
|
||||
"description": "A Boolean value that determines whether the menu should appear when the tray icon receives a left click on macOS.",
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
Loading…
Reference in New Issue
Block a user