This commit is contained in:
signadou 2026-02-06 16:38:23 +08:00 committed by GitHub
commit db2a294780
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 61 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
'tauri': 'patch:enhance'
'@tauri-apps/api': 'patch:enhance'
---
Add Bring All to Front predefined menu item type

View File

@ -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
}
}
};
}

View File

@ -91,6 +91,7 @@ enum Predefined {
Quit,
About(Option<AboutMetadata>),
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())
}
}
}
}

View File

@ -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

View File

@ -32,7 +32,8 @@
'ShowAll',
'CloseWindow',
'Quit',
'Services'
'Services',
'BringAllToFront'
]
function onKindChange(event) {

View File

@ -102,6 +102,7 @@ export interface PredefinedMenuItemOptions {
| 'CloseWindow'
| 'Quit'
| 'Services'
| 'BringAllToFront'
| {
About: AboutMetadata | null
}