Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow playing default notification sound #50

Merged
merged 1 commit into from
Jul 23, 2023

Conversation

amrbashir
Copy link
Contributor

@amrbashir amrbashir commented Jul 3, 2023

@lucasfernog
Copy link
Contributor

I've been testing this but I don't know how to change the default sound on macOS lol

Note that with this change if you provide an unknown sound, the default one will be played.

@amrbashir
Copy link
Contributor Author

amrbashir commented Jul 4, 2023

I've been testing this but I don't know how to change the default sound on macOS lol

I think for testing purposes, it is enough to know that a sound is played.

Note that with this change if you provide an unknown sound, the default one will be played.

It is kinda considered a breaking change but I think for the better, no? I mean if you provide a sound, you want a sound to be played even if it doesn't exist, otherwise don't pass a sound at all to make it silent, plus if this is the default macOS sound, I think we should follow it.

@Pandawan
Copy link
Contributor

Pandawan commented Jul 4, 2023

We might still want to allow explicitly specifying “no sound” when using the sound option. So maybe bring back “_mute” (or similar)?

Otherwise looks p good to me

@amrbashir
Copy link
Contributor Author

If you want to specify a "no sound" option, then just pass an empty string "", "_mute" was never really exposed to the user.

@Pandawan
Copy link
Contributor

Pandawan commented Jul 4, 2023

oh I missed that, sorry was checking this rather quickly

Copy link

@casperstorm casperstorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came across this project because I am currently looking at notifications for https://github.com/squidowl/halloy. :)

objc/notify.m Outdated
{
userNotification.soundName = options[@"sound"];
if (![options[@"sound"] isEqualToString:@"NSUserNotificationDefaultSoundName"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure i find NSUserNotificationDefaultSoundName to be best suited for a default sound option.
I propose a enum instead:

enum Sound {
  Default,
  Custom(String)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will probably require a breaking change so I will let it up to the maintainers whether they want this or not

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this breaking change is acceptable in this case, there are going to be a few more of these before the next release anyway, so please go break things :D

@@ -242,8 +241,8 @@ impl<'a> Notification<'a> {
_ => "no",
}),
NSString::from_str(match self.sound {
Some(sound) if check_sound(sound) => sound,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the check_sound not needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to let the OS decided whether this is a valid sound or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's hard to determine if a sound is valid, the OS pretty much checks the entire file system 😂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the verdict here? leave it in?

objc/notify.m Outdated
{
userNotification.soundName = options[@"sound"];
if (![options[@"sound"] isEqualToString:@"NSUserNotificationDefaultSoundName"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this breaking change is acceptable in this case, there are going to be a few more of these before the next release anyway, so please go break things :D

@@ -242,8 +241,8 @@ impl<'a> Notification<'a> {
_ => "no",
}),
NSString::from_str(match self.sound {
Some(sound) if check_sound(sound) => sound,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the verdict here? leave it in?

@hoodie
Copy link
Collaborator

hoodie commented Jul 23, 2023

thanks for the contribution @amrbashir, sorry for the late response, if you could go ahead and apply these quick changes I'd go ahead and merge this.

@hoodie hoodie force-pushed the feat/default-sound branch 3 times, most recently from ee19343 to c0ffee2 Compare July 23, 2023 17:12
@hoodie
Copy link
Collaborator

hoodie commented Jul 23, 2023

I found a way to add the enum based API without a breaking change.
Thanks for your contribution @amrbashir

@hoodie hoodie merged commit b655bf0 into h4llow3En:master Jul 23, 2023
@casperstorm
Copy link

Great choice to go with the enum approach. Well done on this!

///
/// ```no_run
/// # use mac_notification_sys::*;
/// let _ = Notification::new().sound("Blow");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example is wrong here but ok :D

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants