Skip to content

Commit

Permalink
fix(core): docs.rs build failing for macOS (#8095)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Nov 14, 2023
1 parent f964cbd commit 2ba8856
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-docs-rs-macos-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:bug
---

Fix docs.rs build for `x86_64-apple-darwin`.
12 changes: 10 additions & 2 deletions core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ no-default-features = true
features = [
"wry",
"custom-protocol",
"api-all",
"windows7-compat",
"cli",
"updater",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
93 changes: 49 additions & 44 deletions core/tauri/src/api/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2ba8856

Please sign in to comment.