diff --git a/.changes/add-bring-all-to-front-predefined-menu-item-type.md b/.changes/add-bring-all-to-front-predefined-menu-item-type.md new file mode 100644 index 000000000000..fc5e9820a14e --- /dev/null +++ b/.changes/add-bring-all-to-front-predefined-menu-item-type.md @@ -0,0 +1,6 @@ +--- +'tauri': 'patch:enhance' +'@tauri-apps/api': 'patch:enhance' +--- + +Add Bring All to Front predefined menu item type diff --git a/crates/tauri/src/menu/builders/menu.rs b/crates/tauri/src/menu/builders/menu.rs index 2bf38fd56707..bd24f2a9725f 100644 --- a/crates/tauri/src/menu/builders/menu.rs +++ b/crates/tauri/src/menu/builders/menu.rs @@ -642,6 +642,31 @@ macro_rules! shared_menu_builder { .push(PredefinedMenuItem::services(self.manager, Some(text.as_ref())).map(|i| i.kind())); self } + + /// Add Bring All to Front menu item to the menu. + /// + /// ## Platform-specific: + /// + /// - **Windows / Linux:** Unsupported. + pub fn bring_all_to_front(mut self) -> Self { + self + .items + .push(PredefinedMenuItem::bring_all_to_front(self.manager, None).map(|i| i.kind())); + self + } + + /// Add Bring All to Front menu item with specified text to the menu. + /// + /// ## Platform-specific: + /// + /// - **Windows / Linux:** Unsupported. + pub fn bring_all_to_front_with_text>(mut self, text: S) -> Self { + self.items.push( + PredefinedMenuItem::bring_all_to_front(self.manager, Some(text.as_ref())) + .map(|i| i.kind()), + ); + self + } } }; } diff --git a/crates/tauri/src/menu/plugin.rs b/crates/tauri/src/menu/plugin.rs index 6db48a3d10ad..84ab54a98d22 100644 --- a/crates/tauri/src/menu/plugin.rs +++ b/crates/tauri/src/menu/plugin.rs @@ -91,6 +91,7 @@ enum Predefined { Quit, About(Option), Services, + BringAllToFront, } #[derive(Deserialize)] @@ -303,6 +304,9 @@ impl PredefinedMenuItemPayload { PredefinedMenuItem::about(webview, self.text.as_deref(), metadata) } Predefined::Services => PredefinedMenuItem::services(webview, self.text.as_deref()), + Predefined::BringAllToFront => { + PredefinedMenuItem::bring_all_to_front(webview, self.text.as_deref()) + } } } } diff --git a/crates/tauri/src/menu/predefined.rs b/crates/tauri/src/menu/predefined.rs index b2571361565b..cab7fb7b03b7 100644 --- a/crates/tauri/src/menu/predefined.rs +++ b/crates/tauri/src/menu/predefined.rs @@ -384,6 +384,29 @@ impl PredefinedMenuItem { Ok(Self(Arc::new(item))) } + /// Bring All to Front menu item + /// + /// ## Platform-specific: + /// + /// - **Windows / Linux:** Unsupported. + pub fn bring_all_to_front>(manager: &M, text: Option<&str>) -> crate::Result { + let handle = manager.app_handle(); + let app_handle = handle.clone(); + + let text = text.map(|t| t.to_owned()); + + let item = run_main_thread!(handle, || { + let item = muda::PredefinedMenuItem::bring_all_to_front(text.as_deref()); + PredefinedMenuItemInner { + id: item.id().clone(), + inner: Some(item), + app_handle, + } + })?; + + Ok(Self(Arc::new(item))) + } + /// Returns a unique identifier associated with this menu item. pub fn id(&self) -> &MenuId { &self.0.id diff --git a/examples/api/src/components/MenuItemBuilder.svelte b/examples/api/src/components/MenuItemBuilder.svelte index d907e0951a7b..0f93436978a4 100644 --- a/examples/api/src/components/MenuItemBuilder.svelte +++ b/examples/api/src/components/MenuItemBuilder.svelte @@ -32,7 +32,8 @@ 'ShowAll', 'CloseWindow', 'Quit', - 'Services' + 'Services', + 'BringAllToFront' ] function onKindChange(event) { diff --git a/packages/api/src/menu/predefinedMenuItem.ts b/packages/api/src/menu/predefinedMenuItem.ts index fed9a543facc..1517a35fa970 100644 --- a/packages/api/src/menu/predefinedMenuItem.ts +++ b/packages/api/src/menu/predefinedMenuItem.ts @@ -102,6 +102,7 @@ export interface PredefinedMenuItemOptions { | 'CloseWindow' | 'Quit' | 'Services' + | 'BringAllToFront' | { About: AboutMetadata | null }