Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri': 'patch:enhance'
'@tauri-apps/api': 'patch:enhance'
---

Add Bring All to Front predefined menu item type
25 changes: 25 additions & 0 deletions crates/tauri/src/menu/builders/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: AsRef<str>>(mut self, text: S) -> Self {
self.items.push(
PredefinedMenuItem::bring_all_to_front(self.manager, Some(text.as_ref()))
.map(|i| i.kind()),
);
self
}
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions crates/tauri/src/menu/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enum Predefined {
Quit,
About(Option<AboutMetadata>),
Services,
BringAllToFront,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -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())
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions crates/tauri/src/menu/predefined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,29 @@ impl<R: Runtime> PredefinedMenuItem<R> {
Ok(Self(Arc::new(item)))
}

/// Bring All to Front menu item
///
/// ## Platform-specific:
///
/// - **Windows / Linux:** Unsupported.
pub fn bring_all_to_front<M: Manager<R>>(manager: &M, text: Option<&str>) -> crate::Result<Self> {
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
Expand Down
3 changes: 2 additions & 1 deletion examples/api/src/components/MenuItemBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
'ShowAll',
'CloseWindow',
'Quit',
'Services'
'Services',
'BringAllToFront'
]

function onKindChange(event) {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/menu/predefinedMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface PredefinedMenuItemOptions {
| 'CloseWindow'
| 'Quit'
| 'Services'
| 'BringAllToFront'
| {
About: AboutMetadata | null
}
Expand Down
Loading