diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index ff8498b5b063..ecfa263ac75d 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -20,7 +20,6 @@ use crate::{ sealed::{ManagerBase, RuntimeOrDispatch}, utils::config::Config, utils::{assets::Assets, Env}, - window::WindowMenu, Context, DeviceEventFilter, EventLoopMessage, Icon, Invoke, InvokeError, InvokeResponse, Manager, Monitor, Runtime, Scopes, StateManager, Theme, Window, }; @@ -640,7 +639,7 @@ macro_rules! shared_app_impl { .init_for_gtk_window(>k_window, Some(>k_box)); } })?; - window_menu.replace(WindowMenu { + window_menu.replace(crate::window::WindowMenu { is_app_wide: true, menu: menu.clone(), }); @@ -1585,12 +1584,20 @@ fn setup(app: &mut App) -> crate::Result<()> { let pending = manager.prepare_window(app_handle.clone(), pending, &window_labels)?; #[cfg(not(target_os = "macos"))] - let window_menu = app.manager.menu_lock().as_ref().map(|m| WindowMenu { - is_app_wide: true, - menu: m.clone(), - }); + let window_menu = app + .manager + .menu_lock() + .as_ref() + .map(|m| crate::window::WindowMenu { + is_app_wide: true, + menu: m.clone(), + }); + #[cfg(not(target_os = "macos"))] let handler = manager.create_webview_before_creation_handler(window_menu.as_ref()); + #[cfg(target_os = "macos")] + #[allow(clippy::type_complexity)] + let handler: Option) + Send>> = None; let window_effects = pending.webview_attributes.window_effects.clone(); let detached = if let RuntimeOrDispatch::RuntimeHandle(runtime) = app_handle.runtime() { diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index af66fd33bd36..b28a37a6dfed 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -10,12 +10,11 @@ use std::{ sync::{Arc, Mutex, MutexGuard}, }; +use crate::menu::Menu; use crate::tray::TrayIcon; -use crate::{menu::Menu, window::WindowMenu}; use serde::Serialize; use serde_json::Value as JsonValue; use serialize_to_javascript::{default_template, DefaultTemplate, Template}; -use tauri_runtime::window::RawWindow; use url::Url; use tauri_macros::default_runtime; @@ -371,11 +370,11 @@ impl WindowManager { self.inner.state.clone() } + #[cfg(not(target_os = "macos"))] pub(crate) fn create_webview_before_creation_handler( &self, - window_menu: Option<&WindowMenu>, - ) -> Option)> { - #[cfg(not(target_os = "macos"))] + window_menu: Option<&crate::window::WindowMenu>, + ) -> Option)> { { if let Some(menu) = window_menu { self @@ -387,13 +386,9 @@ impl WindowManager { } } - #[cfg(target_os = "macos")] - return None; - - #[cfg(not(target_os = "macos"))] if let Some(menu) = &window_menu { let menu = menu.menu.clone(); - Some(move |raw: RawWindow<'_>| { + Some(move |raw: tauri_runtime::window::RawWindow<'_>| { #[cfg(target_os = "windows")] let _ = menu.inner().init_for_hwnd(raw.hwnd as _); #[cfg(any( @@ -1239,7 +1234,7 @@ impl WindowManager { &self, app_handle: AppHandle, window: DetachedWindow, - #[cfg(not(target_os = "macos"))] menu: Option>, + #[cfg(not(target_os = "macos"))] menu: Option>, ) -> Window { let window = Window::new( self.clone(), diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 24c9360f4409..418c2b9d0b75 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -4,7 +4,7 @@ //! The Tauri window types and functions. -use crate::{app::GlobalMenuEventListener, menu::ContextMenu}; +use crate::menu::ContextMenu; pub use tauri_utils::{config::Color, WindowEffect as Effect, WindowEffectState as EffectState}; use url::Url; @@ -121,7 +121,8 @@ pub struct WindowBuilder<'a, R: Runtime> { pub(crate) webview_attributes: WebviewAttributes, web_resource_request_handler: Option>, navigation_handler: Option>, - on_menu_event: Option>>, + #[cfg(not(target_os = "macos"))] + on_menu_event: Option>>, } impl<'a, R: Runtime> fmt::Debug for WindowBuilder<'a, R> { @@ -197,6 +198,7 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { webview_attributes: WebviewAttributes::new(url), web_resource_request_handler: None, navigation_handler: None, + #[cfg(not(target_os = "macos"))] on_menu_event: None, } } @@ -237,6 +239,7 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { web_resource_request_handler: None, menu: None, navigation_handler: None, + #[cfg(not(target_os = "macos"))] on_menu_event: None, }; @@ -348,6 +351,8 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { /// Ok(()) /// }); /// ``` + #[cfg(not(target_os = "macos"))] + #[cfg_attr(doc_cfg, doc(cfg(not(target_os = "macos"))))] pub fn on_menu_event, crate::menu::MenuEvent) + Send + Sync + 'static>( mut self, f: F, @@ -380,9 +385,13 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { .map(|menu| WindowMenu { is_app_wide, menu }) }; + #[cfg(not(target_os = "macos"))] let handler = self .manager .create_webview_before_creation_handler(window_menu.as_ref()); + #[cfg(target_os = "macos")] + #[allow(clippy::type_complexity)] + let handler: Option) + Send>> = None; let window_effects = pending.webview_attributes.window_effects.clone(); let window = match &mut self.runtime { @@ -399,6 +408,7 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { ) })?; + #[cfg(not(target_os = "macos"))] if let Some(handler) = self.on_menu_event { window.on_menu_event(handler); } @@ -844,6 +854,7 @@ struct JsEventListenerKey { /// A wrapper struct to hold the window menu state /// and whether it is global per-app or specific to this window. +#[cfg(not(target_os = "macos"))] pub(crate) struct WindowMenu { pub(crate) is_app_wide: bool, pub(crate) menu: Menu,