diff --git a/examples/api/src-tauri/src/cmd.rs b/examples/api/src-tauri/src/cmd.rs index 3b050d9c06e3..939ceba12f89 100644 --- a/examples/api/src-tauri/src/cmd.rs +++ b/examples/api/src-tauri/src/cmd.rs @@ -2,9 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use crate::PopupMenu; use serde::Deserialize; -use tauri::{command, Runtime, State, Window}; +use tauri::command; #[derive(Debug, Deserialize)] #[allow(unused)] @@ -24,9 +23,9 @@ pub fn perform_request(endpoint: String, body: RequestBody) -> String { "message response".into() } -#[cfg(not(target_os = "macos"))] +#[cfg(all(desktop, not(target_os = "macos")))] #[command] -pub fn toggle_menu(window: Window) { +pub fn toggle_menu(window: tauri::Window) { if window.is_menu_visible().unwrap_or_default() { let _ = window.hide_menu(); } else { @@ -36,7 +35,10 @@ pub fn toggle_menu(window: Window) { #[cfg(target_os = "macos")] #[command] -pub fn toggle_menu(app: tauri::AppHandle, app_menu: State<'_, crate::AppMenu>) { +pub fn toggle_menu( + app: tauri::AppHandle, + app_menu: tauri::State<'_, crate::AppMenu>, +) { if let Some(menu) = app.remove_menu().unwrap() { app_menu.0.lock().unwrap().replace(menu); } else { @@ -46,7 +48,11 @@ pub fn toggle_menu(app: tauri::AppHandle, app_menu: State<'_, cra } } +#[cfg(desktop)] #[command] -pub fn popup_context_menu(window: Window, popup_menu: State<'_, PopupMenu>) { +pub fn popup_context_menu( + window: tauri::Window, + popup_menu: tauri::State<'_, crate::PopupMenu>, +) { window.popup_menu(&popup_menu.0).unwrap(); } diff --git a/examples/api/src-tauri/src/lib.rs b/examples/api/src-tauri/src/lib.rs index 21db44ca7712..0d62b43c9a65 100644 --- a/examples/api/src-tauri/src/lib.rs +++ b/examples/api/src-tauri/src/lib.rs @@ -12,13 +12,12 @@ mod cmd; mod tray; use serde::Serialize; -use tauri::{ - menu::{Menu, MenuBuilder}, - window::WindowBuilder, - App, AppHandle, Manager, RunEvent, Runtime, WindowUrl, -}; +use tauri::{window::WindowBuilder, App, AppHandle, RunEvent, Runtime, WindowUrl}; use tauri_plugin_sample::{PingRequest, SampleExt}; +#[cfg(desktop)] +use tauri::Manager; + pub type SetupHook = Box Result<(), Box> + Send>; pub type OnEvent = Box; @@ -30,7 +29,8 @@ struct Reply { #[cfg(target_os = "macos")] pub struct AppMenu(pub std::sync::Mutex>>); -pub struct PopupMenu(Menu); +#[cfg(desktop)] +pub struct PopupMenu(tauri::menu::Menu); #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { @@ -60,8 +60,9 @@ pub fn run_app) + Send + 'static>( #[cfg(target_os = "macos")] app.manage(AppMenu::(Default::default())); + #[cfg(desktop)] app.manage(PopupMenu( - MenuBuilder::new(app) + tauri::menu::MenuBuilder::new(app) .check("Tauri is awesome!") .text("Do something") .copy() @@ -141,7 +142,9 @@ pub fn run_app) + Send + 'static>( .invoke_handler(tauri::generate_handler![ cmd::log_operation, cmd::perform_request, + #[cfg(desktop)] cmd::toggle_menu, + #[cfg(desktop)] cmd::popup_context_menu ]) .build(tauri::tauri_build_context!())