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

MacOS notifications not working as expected: showing fallback notifications if explicitly disallowed, showing no notifications if allowed #4989

Open
2 tasks done
Gys opened this issue Jul 4, 2024 · 0 comments
Labels
unverified A bug that has been reported but not verified

Comments

@Gys
Copy link

Gys commented Jul 4, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

Just before the first notification is shown, a system alert is shown to notify the user of the app wanting to send notifications. On hoovering, it shows a closing x and a dropdown Options with Allow and Don't Allow.

If I explicitly disallow to send notifications, it will subsequently show fallback notifications instead. That is not what should happen. The app should not show any notifications.

If I explicitly allow to send notifications I receive no further notifications. No 'official' notifications and no fall back notifications.

If I just close the notification (clicking the top left x on hoovering) without choosing any of the options, then the effect is the same as disallowing.

How to reproduce

I have a simple notifications app. I create a fyne release version and install the resulting .pkg file on MacOS.

Screenshots


Screenshot 2024-07-04 at 12 36 36

Example code

func main() {
	a := app.New()
	w := a.NewWindow("Notification Example")

	// Create a button to trigger the notification
	btn := widget.NewButton("Show Notification", func() {
		notification := fyne.NewNotification("Notification Title", "This is the notification now.")
		a.SendNotification(notification)
	})

	btn2 := widget.NewButton("Show Notification in 5s", func() {
		notification := fyne.NewNotification("Notification Title", "This is the notification 5s.")
		time.Sleep(5 * time.Second)
		a.SendNotification(notification)
	})

	// Set the content of the window
	w.SetContent(container.NewVBox(
		widget.NewLabel("Click the button to show a notification."),
		btn,
		btn2,
	))

	// Show the window and run the application
	w.ShowAndRun()
}

Fyne version

2.4.5

Go compiler version

go version go1.21.5 darwin/amd64

Operating system and version

MacOS Sonoma 14.5 (Intel)

Additional Information

When disallowed the fallback is shown because the OS additionally gives an error even when granted is clearly false:
Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}

The code in app_darwin.m will therefore trigger falsely the fallback. The comment in the code is not correct. The error will also be produced if the app is signed but the user disallows notifications:

    UNAuthorizationOptions options = UNAuthorizationOptionAlert;
    [center requestAuthorizationWithOptions:options
        completionHandler:^(BOOL granted, NSError *_Nullable error) {
            if (!granted) {
                if (error != NULL) {
                    NSLog(@"Fyne error asking for permission to send notifications %@", error);
                    // this happens if our app was not signed, so do it the old way
                    fallbackSend((char *)[title UTF8String], (char *)[body UTF8String]);
                } else {
                    NSLog(@"Fyne unable to get permission to send notifications");
                }
            } else {
                doSendNotification(center, title, body);
            }
        }];

I also found an explanation why notifications do not show. At least on my MacBook.

Fyne explicitly asks permission for Alerts. The OS then asks permission: 'Notifications may include alerts, sounds and icon badges'. So this also includes alerts.

So why are the alerts not shown?

If I go to Settings -> Notifications -> test app, it does not show Alerts as an option. It shows Banners. See the screenshot. So for some reason MacOS (on my system?) defaults to allowing banners only, while the Fyne app is sending alerts. Because when I manually switch the app settings from allowing Banners to Alerts, the notifications suddenly show!

Is it something in my system that defaults to allowing banners only? Do Fyne notifications work out of the box for others?

If this is not specific to my system: in the code Fyne sends notifications without explicit setting to banner and/or alert. So it seems the notifications implicitly are treated as alerts while only banners are allowed?

@Gys Gys added the unverified A bug that has been reported but not verified label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

1 participant