Skip to content

Commit 074299c

Browse files
authored
feat: add Bring All to Front predefined menu item type (#14307)
* Add Bring All to Front predefined menu item type * Format and update changefile * Update .changes/add-bring-all-to-front-predefined-menu-item-type.md
1 parent ec5381e commit 074299c

6 files changed

Lines changed: 61 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri': 'minor:feat'
3+
'@tauri-apps/api': 'minor:feat'
4+
---
5+
6+
Add Bring All to Front predefined menu item type

crates/tauri/src/menu/builders/menu.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,31 @@ macro_rules! shared_menu_builder {
642642
.push(PredefinedMenuItem::services(self.manager, Some(text.as_ref())).map(|i| i.kind()));
643643
self
644644
}
645+
646+
/// Add Bring All to Front menu item to the menu.
647+
///
648+
/// ## Platform-specific:
649+
///
650+
/// - **Windows / Linux:** Unsupported.
651+
pub fn bring_all_to_front(mut self) -> Self {
652+
self
653+
.items
654+
.push(PredefinedMenuItem::bring_all_to_front(self.manager, None).map(|i| i.kind()));
655+
self
656+
}
657+
658+
/// Add Bring All to Front menu item with specified text to the menu.
659+
///
660+
/// ## Platform-specific:
661+
///
662+
/// - **Windows / Linux:** Unsupported.
663+
pub fn bring_all_to_front_with_text<S: AsRef<str>>(mut self, text: S) -> Self {
664+
self.items.push(
665+
PredefinedMenuItem::bring_all_to_front(self.manager, Some(text.as_ref()))
666+
.map(|i| i.kind()),
667+
);
668+
self
669+
}
645670
}
646671
};
647672
}

crates/tauri/src/menu/plugin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ enum Predefined {
9191
Quit,
9292
About(Option<AboutMetadata>),
9393
Services,
94+
BringAllToFront,
9495
}
9596

9697
#[derive(Deserialize)]
@@ -303,6 +304,9 @@ impl PredefinedMenuItemPayload {
303304
PredefinedMenuItem::about(webview, self.text.as_deref(), metadata)
304305
}
305306
Predefined::Services => PredefinedMenuItem::services(webview, self.text.as_deref()),
307+
Predefined::BringAllToFront => {
308+
PredefinedMenuItem::bring_all_to_front(webview, self.text.as_deref())
309+
}
306310
}
307311
}
308312
}

crates/tauri/src/menu/predefined.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,29 @@ impl<R: Runtime> PredefinedMenuItem<R> {
384384
Ok(Self(Arc::new(item)))
385385
}
386386

387+
/// Bring All to Front menu item
388+
///
389+
/// ## Platform-specific:
390+
///
391+
/// - **Windows / Linux:** Unsupported.
392+
pub fn bring_all_to_front<M: Manager<R>>(manager: &M, text: Option<&str>) -> crate::Result<Self> {
393+
let handle = manager.app_handle();
394+
let app_handle = handle.clone();
395+
396+
let text = text.map(|t| t.to_owned());
397+
398+
let item = run_main_thread!(handle, || {
399+
let item = muda::PredefinedMenuItem::bring_all_to_front(text.as_deref());
400+
PredefinedMenuItemInner {
401+
id: item.id().clone(),
402+
inner: Some(item),
403+
app_handle,
404+
}
405+
})?;
406+
407+
Ok(Self(Arc::new(item)))
408+
}
409+
387410
/// Returns a unique identifier associated with this menu item.
388411
pub fn id(&self) -> &MenuId {
389412
&self.0.id

examples/api/src/components/MenuItemBuilder.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
'ShowAll',
3333
'CloseWindow',
3434
'Quit',
35-
'Services'
35+
'Services',
36+
'BringAllToFront'
3637
]
3738
3839
function onKindChange(event) {

packages/api/src/menu/predefinedMenuItem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export interface PredefinedMenuItemOptions {
102102
| 'CloseWindow'
103103
| 'Quit'
104104
| 'Services'
105+
| 'BringAllToFront'
105106
| {
106107
About: AboutMetadata | null
107108
}

0 commit comments

Comments
 (0)