mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
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![popup, toggle])
|
|
.build()
|
|
}
|