fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.66k stars 1.37k forks source link

Windows: rewrite notification logic in C? #4541

Open mbaklor opened 8 months ago

mbaklor commented 8 months ago

Checklist

Is your feature request related to a problem?

This is a duplicate of #2592 and #3079 since they're both a little old and I don't know which one to wake up for this. I spent a little while looking into notification in windows today, and will just dump here the information I've managed to gather.

First of all, the toasts API can support images, but it looks like they want an image path so the fyne.Resource of the icon isn't really helpful to us, but if we want to save it to a temp file or something maybe that's a current workaround for showing an icon? https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.toastnotificationmanager?view=winrt-22621 https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-notifications-overview

The next interesting thing is that the old notification API (called balloon notification) requires a systray to exist, so maybe the implementation should be check if there's a systray, if so append the notification to the systray, otherwise add a systray icon for the 3 seconds until the notification is over (see https://github.com/gen2brain/beeep who did that)

The one thing I'm not 100% on is if the toast and balloon notifications are in fact the same under the hood, and since my win API skills aren't quite there I tried a few golang libs that do each (see beeep above, and https://github.com/go-toast/toast which beeep calls if the OS is windows 10), and manipulated them to hopefully create notifications, and it looks like they look the same on windows 10? I'm not sure though and would appreciate if someone tests it who knows what's going on. Point is I'm 90% sure using the old balloon API will create toasts in windows 10 and 11.

Some links re- the balloon notifications: https://learn.microsoft.com/en-us/windows/win32/shell/notification-area https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataa#nif_info-0x00000010

** edit forgot to link the microsoft notification example, it's c++ but I hope this is simple enough to port for someone who can parse all this https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/winui/shell/appshellintegration/NotificationIcon

Is it possible to construct a solution with the existing API?

No response

Describe the solution you'd like to see.

Mostly what I'm hoping for is the app icon in the notification, but if in the process we get a better cleaner API without relying on pwsh that's a nice bonus

mbaklor commented 8 months ago

I'm adding this here because if going with the balloon notification API doesn't work, someone made a C version of the microsoft C++ example for the toast API

https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/DesktopToasts/CPP https://gist.github.com/valinet/3283c79ba35fc8f103c747c8adbb6b23

andydotxyz commented 8 months ago

I think it needs to be the toast type doesn't it? The bubbles relate to system tray apps (in my experience). Great suggestion to move off the script based code though.

mbaklor commented 8 months ago

Yea it looks like bubbles require a system tray app, but that might make implementing easier since the tray app logic exists already so it's just about adding notifications to the existing logic. I don't know if that's a possibility since the systray logic isn't directly in fyne but instead it's in the systray package?

Looks like toasts still need the XML document even if you don't go with pwsh script, but I have only a loose grasp on windows APIs so I might be wrong, that said if it's just an xml template it's less of an issue than running a pwsh script from within go, but I'm not sure what to do with the XML once it exists

*edit https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.toastnotificationmanager?view=winrt-22621#sending-toast-notifications-from-desktop-apps looks like toasts are an issue for non-uwp apps, might be solvable, I have no idea what this means haha

Jacalz commented 8 months ago

Fixing this would also likely fix https://github.com/fyne-io/fyne/issues/3079, I think.

andydotxyz commented 8 months ago

Yea it looks like bubbles require a system tray app, but that might make implementing easier since the tray app logic exists already so it's just about adding notifications to the existing logic. I don't know if that's a possibility since the systray logic isn't directly in fyne but instead it's in the systray package?

We cannot require system tray just for notification support.

mbaklor commented 7 months ago

True, but again, I've seen at this point a few implementations of balloon notifications that placed a systray, sent a notification, removed the systray. I don't know if with the way fyne and in general gui apps handle the event loop if this is a viable option, but at least in theory it should work. Again, I have nothing against toast notifs specifically but they seem messy from what I can parse of the windows docs