From 2ba8856343e284ed022f28cff6d16db15ad4645f Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 13 Nov 2023 22:34:22 -0300 Subject: [PATCH] fix(core): docs.rs build failing for macOS (#8095) --- .changes/fix-docs-rs-macos-build.md | 5 ++ core/tauri/Cargo.toml | 12 +++- core/tauri/src/api/mod.rs | 2 +- core/tauri/src/api/notification.rs | 93 +++++++++++++++-------------- 4 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 .changes/fix-docs-rs-macos-build.md diff --git a/.changes/fix-docs-rs-macos-build.md b/.changes/fix-docs-rs-macos-build.md new file mode 100644 index 000000000..bfff22b23 --- /dev/null +++ b/.changes/fix-docs-rs-macos-build.md @@ -0,0 +1,5 @@ +--- +"tauri": patch:bug +--- + +Fix docs.rs build for `x86_64-apple-darwin`. diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index a493280d2..0ec045ae4 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -17,7 +17,6 @@ no-default-features = true features = [ "wry", "custom-protocol", - "api-all", "windows7-compat", "cli", "updater", @@ -27,7 +26,16 @@ features = [ "http-multipart", "icon-png", "test", - "dox" + "dox", + "dialog", + "global-shortcut", + "http-request", + "os-api", + "process-relaunch", + "process-exit", + "protocol-asset", + "process-command-api", + "shell-open", ] rustdoc-args = [ "--cfg", "doc_cfg" ] default-target = "x86_64-unknown-linux-gnu" diff --git a/core/tauri/src/api/mod.rs b/core/tauri/src/api/mod.rs index cd296db7d..00bfc3a20 100644 --- a/core/tauri/src/api/mod.rs +++ b/core/tauri/src/api/mod.rs @@ -31,7 +31,7 @@ pub mod cli; #[cfg_attr(doc_cfg, doc(cfg(feature = "cli")))] pub use clap; -#[cfg(all(desktop, feature = "notification"))] +#[cfg(all(desktop, any(feature = "notification", feature = "dox")))] #[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "notification"))))] pub mod notification; diff --git a/core/tauri/src/api/notification.rs b/core/tauri/src/api/notification.rs index 2959591ca..019696ee6 100644 --- a/core/tauri/src/api/notification.rs +++ b/core/tauri/src/api/notification.rs @@ -153,55 +153,60 @@ impl Notification { deprecated = "This function does not work on Windows 7. Use `Self::notify` instead." )] pub fn show(self) -> crate::api::Result<()> { - let mut notification = notify_rust::Notification::new(); - if let Some(body) = self.body { - notification.body(&body); - } - if let Some(title) = self.title { - notification.summary(&title); - } - if let Some(icon) = self.icon { - notification.icon(&icon); - } else { - notification.auto_icon(); - } - if let Some(sound) = self.sound { - notification.sound_name(&match sound { - #[cfg(target_os = "macos")] - Sound::Default => "NSUserNotificationDefaultSoundName".to_string(), - #[cfg(windows)] - Sound::Default => "Default".to_string(), - #[cfg(all(unix, not(target_os = "macos")))] - Sound::Default => "message-new-instant".to_string(), - Sound::Custom(c) => c, - }); - } - #[cfg(windows)] + #[cfg(feature = "dox")] + return Ok(()); + #[cfg(not(feature = "dox"))] { - let exe = tauri_utils::platform::current_exe()?; - let exe_dir = exe.parent().expect("failed to get exe directory"); - let curr_dir = exe_dir.display().to_string(); - // set the notification's System.AppUserModel.ID only when running the installed app - if !(curr_dir.ends_with(format!("{SEP}target{SEP}debug").as_str()) - || curr_dir.ends_with(format!("{SEP}target{SEP}release").as_str())) - { - notification.app_id(&self.identifier); + let mut notification = notify_rust::Notification::new(); + if let Some(body) = self.body { + notification.body(&body); } - } - #[cfg(target_os = "macos")] - { - let _ = notify_rust::set_application(if cfg!(feature = "custom-protocol") { - &self.identifier + if let Some(title) = self.title { + notification.summary(&title); + } + if let Some(icon) = self.icon { + notification.icon(&icon); } else { - "com.apple.Terminal" + notification.auto_icon(); + } + if let Some(sound) = self.sound { + notification.sound_name(&match sound { + #[cfg(target_os = "macos")] + Sound::Default => "NSUserNotificationDefaultSoundName".to_string(), + #[cfg(windows)] + Sound::Default => "Default".to_string(), + #[cfg(all(unix, not(target_os = "macos")))] + Sound::Default => "message-new-instant".to_string(), + Sound::Custom(c) => c, + }); + } + #[cfg(windows)] + { + let exe = tauri_utils::platform::current_exe()?; + let exe_dir = exe.parent().expect("failed to get exe directory"); + let curr_dir = exe_dir.display().to_string(); + // set the notification's System.AppUserModel.ID only when running the installed app + if !(curr_dir.ends_with(format!("{SEP}target{SEP}debug").as_str()) + || curr_dir.ends_with(format!("{SEP}target{SEP}release").as_str())) + { + notification.app_id(&self.identifier); + } + } + #[cfg(target_os = "macos")] + { + let _ = notify_rust::set_application(if cfg!(feature = "custom-protocol") { + &self.identifier + } else { + "com.apple.Terminal" + }); + } + + crate::async_runtime::spawn(async move { + let _ = notification.show(); }); + + Ok(()) } - - crate::async_runtime::spawn(async move { - let _ = notification.show(); - }); - - Ok(()) } /// Shows the notification. This API is similar to [`Self::show`], but it also works on Windows 7.