tauri/examples/api/src-tauri/src/menu_plugin.rs
Tony 013f8f6523
feat: add a new option to remove unused commands (#12890)
* Add a new option to remove unused commands

* Fix compile

* Add markers to all core plugins

* Clippy

* Add allow unused when running with this

* Use build script to generate allowed-commands.json

* Clean up and add proper reruns

* Wrong path

* Revert to #[cfg_attr(not(debug_assertions), allow(unused))]

* Add change files

* Some more docs

* Add version requirement note

* Avoid rerun if no capabilities folder

* Remove unused box

* small cleanup

* fix channel

* implement for app handler too

* rely on core:default for channel perms

* Move this feature to config

* Docs change

* Forget one last remove_unused_commands

* Remove removeUnusedCommands from helloworld

* tell handler that the app ACL manifest exists

* update change file

* update doc

* update change file

* Use a struct to pass the data instead of env var

* Clippy

* Fix can't exclude inlined plugins on Windows
due to UNC paths...

* Apply suggestion from code review

* Remove remove on empty to tauri-build

* Revert "Remove remove on empty to tauri-build"

This reverts commit b727dd621e.

* Centralize remove_file(allowed_commands_file_path)

* Escape glob pattern

* update change file

* remove unused commands for dev too

* Update crates/tauri-utils/src/config.rs

Co-authored-by: Fabian-Lars <github@fabianlars.de>

* regen schema

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Co-authored-by: Fabian-Lars <github@fabianlars.de>
2025-03-15 13:46:08 -03:00

53 lines
1.2 KiB
Rust

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![cfg(all(desktop, not(test)))]
use tauri::{
command,
plugin::{Builder, TauriPlugin},
Runtime,
};
#[cfg(not(target_os = "macos"))]
#[command]
pub fn toggle<R: tauri::Runtime>(window: tauri::Window<R>) {
if window.is_menu_visible().unwrap_or_default() {
let _ = window.hide_menu();
} else {
let _ = window.show_menu();
}
}
#[cfg(target_os = "macos")]
#[command]
pub fn toggle<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
app_menu: tauri::State<'_, crate::AppMenu<R>>,
) {
if let Some(menu) = app.remove_menu().unwrap() {
app_menu.0.lock().unwrap().replace(menu);
} else {
app
.set_menu(app_menu.0.lock().unwrap().clone().expect("no app menu"))
.unwrap();
}
}
#[command]
pub fn popup<R: tauri::Runtime>(
window: tauri::Window<R>,
popup_menu: tauri::State<'_, crate::PopupMenu<R>>,
) {
window.popup_menu(&popup_menu.0).unwrap();
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("app-menu")
.invoke_handler(tauri::generate_handler![
#![plugin(app_menu)]
popup, toggle
])
.build()
}