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

This commit is contained in:
Lucas Fernandes Nogueira 2023-11-13 22:34:22 -03:00 committed by GitHub
parent f964cbdb93
commit 2ba8856343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 47 deletions

View File

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

View File

@ -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"

View File

@ -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;

View File

@ -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.