Skip to content

Commit

Permalink
fix build on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jul 20, 2023
1 parent 6758525 commit 826a5fc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ use wry::webview::{
use tauri_runtime::ActivationPolicy;
#[cfg(target_os = "macos")]
pub use wry::application::platform::macos::{
ActivationPolicy as WryActivationPolicy, CustomMenuItemExtMacOS, EventLoopExtMacOS,
WindowExtMacOS,
ActivationPolicy as WryActivationPolicy, EventLoopExtMacOS, WindowExtMacOS,
};

use std::{
Expand Down Expand Up @@ -546,7 +545,7 @@ impl std::fmt::Debug for WindowBuilderWrapper {
s.field("inner", &self.inner).field("center", &self.center);
#[cfg(target_os = "macos")]
{
s = s.field("tabbing_identifier", &self.tabbing_identifier);
s.field("tabbing_identifier", &self.tabbing_identifier);
}
s.finish()
}
Expand Down Expand Up @@ -2537,6 +2536,8 @@ fn create_webview<T: UserEvent>(
target_os = "openbsd"
))]
let _ = menu.init_for_gtk_window(window.gtk_window());
#[cfg(target_os = "macos")]
menu.init_for_nsapp();
}

webview_id_map.insert(window.id(), window_id);
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ impl<R: Runtime> Builder<R> {
R::new(runtime_args)?
};
#[cfg(not(any(windows, target_os = "linux")))]
let mut runtime = R::new()?;
let mut runtime = R::new(runtime_args)?;

#[cfg(target_os = "macos")]
if let Some(menu) = menu {
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub use tauri_runtime_wry::webview_version;

#[cfg(target_os = "macos")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
pub use runtime::{menu::NativeImage, ActivationPolicy};
pub use runtime::ActivationPolicy;

#[cfg(target_os = "macos")]
pub use self::utils::TitleBarStyle;
Expand Down
16 changes: 8 additions & 8 deletions core/tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

//! Menu types and utility functions

use tauri_runtime::menu::builders::AboutMetadataBuilder;
use tauri_utils::config::Config;

pub use crate::runtime::menu::*;
Expand All @@ -14,20 +13,21 @@ pub use crate::runtime::menu::*;

/// Creates a menu filled with default menu items and submenus.
pub fn default(config: &Config) -> Menu {
let about_metadata = AboutMetadataBuilder::new()
.name(config.package.product_name.clone())
.version(config.package.version.clone())
.copyright(config.tauri.bundle.copyright.clone())
.authors(config.tauri.bundle.publisher.clone().map(|p| vec![p]))
.build();
let about_metadata = AboutMetadata {
name: config.package.product_name.clone(),
version: config.package.version.clone(),
copyright: config.tauri.bundle.copyright.clone(),
authors: config.tauri.bundle.publisher.clone().map(|p| vec![p]),
..Default::default()
};

Menu::with_items(&[
#[cfg(target_os = "macos")]
&Submenu::with_items(
config.package.binary_name().unwrap_or_default(),
true,
&[
&PredefinedMenuItem::about(None, Some(about_metadata)),
&PredefinedMenuItem::about(None, Some(about_metadata.clone())),
&PredefinedMenuItem::separator(),
&PredefinedMenuItem::services(None),
&PredefinedMenuItem::separator(),
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ impl<R: Runtime> Window<R> {
{
let _ = menu.remove_for_gtk_window(&self.gtk_window()?);
}
#[cfg(target_os = "macos")]

This comment has been minimized.

Copy link
@amrbashir

amrbashir Jul 20, 2023

Member

@lucasfernog Removing the menu from a window shouldn't remove the global menu on macOS. Same goes for when setting a window menu, it shouldn't set the global menu on macOS. If you want to modify the global macOS menu, you should use app.set_menu and app.remove_menu

This comment has been minimized.

Copy link
@lucasfernog

lucasfernog Jul 20, 2023

Author Member

ahh ok my bad

This comment has been minimized.

Copy link
@lucasfernog

lucasfernog Jul 20, 2023

Author Member

@amrbashir we shouldn't even have these window-specific menu APIs on macOS

This comment has been minimized.

Copy link
@amrbashir

amrbashir Jul 20, 2023

Member

we could add it behind an #[cfg] but I think it is fine to keep and make it easier to call them, we should just improve the documentation around it and see how it goes

menu.remove_for_nsapp();
}

let prev_menu = current_menu.take().map(|m| m.1);
Expand Down

0 comments on commit 826a5fc

Please sign in to comment.