Эх сурвалжийг харах

fix(core): docs.rs build failing for macOS (#8095)

Lucas Fernandes Nogueira 1 жил өмнө
parent
commit
2ba8856343

+ 5 - 0
.changes/fix-docs-rs-macos-build.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch:bug
+---
+
+Fix docs.rs build for `x86_64-apple-darwin`.

+ 10 - 2
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"

+ 1 - 1
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;
 

+ 49 - 44
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();
-    });
+      crate::async_runtime::spawn(async move {
+        let _ = notification.show();
+      });
 
-    Ok(())
+      Ok(())
+    }
   }
 
   /// Shows the notification. This API is similar to [`Self::show`], but it also works on Windows 7.