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

[WIP] Native notifications for Windows, Linux and OSX #3389

Open
wants to merge 9 commits into
base: master
from

Conversation

@pr8x
Copy link
Contributor

pr8x commented Dec 23, 2019

What does the pull request do?

Implementing native notification support for Windows (10), Linux (DBUS/FreeDesktop) and OSX.

linux_native_notifications


windows_native_notifications


osx_native_notification

Discussion

  • In Windows it is required to register an application shortcut in the StartMenu in order to send toast notifications (See https://docs.microsoft.com/en-us/windows/win32/shell/enable-desktop-toast-with-appusermodelid). I am not exactlly sure how we want to handle this. I could add a RegisterApplication function in the Win32Platform to do this registration and also create a unique AppUserModelID based on the Application.Name. It's probably a good idea to uninstall the shortcut once the application exits.

  • This PR provides a basic implementation that works across the three major desktop platforms. Advanced features (such as replacing notifications, custom buttons, images, etc) can be rolled in future updates.

What is the current behavior?

We only have managed notifications hosted inside avalonia windows.

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

  • Windows 10: Using the UWP ToastNotification API
  • Linux: Using the FreeDesktop DBUS org.freedesktop.Notifications service interface. (Thanks to #2884)
  • OSX: Creating a COM interface for interacting with the native Cocoa API (NSUserNotificationCenter)

Fixed issues

#2155

@@ -4,6 +4,9 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>Avalonia.Win32</PackageId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.18362.2005" />

This comment has been minimized.

Copy link
@kekekeks

kekekeks Dec 23, 2019

Member

Does that work with Win 8.1 or is it Win10+ only?

This comment has been minimized.

Copy link
@jkoritzinsky

jkoritzinsky Dec 24, 2019

Member

This is Win10+ only from what I can tell.

This comment has been minimized.

Copy link
@pr8x

pr8x Dec 24, 2019

Author Contributor

The Windows 10 WinRT API Pack enables you to add the latest Windows Runtime APIs support to your .NET Framework 4.5+ and .NET Core 3.0+ libraries and apps.

https://www.nuget.org/packages/Microsoft.Windows.SDK.Contracts/10.0.17763.1000-preview

But AFAIK the toast notifications only work in Windows 10 anyway.

This comment has been minimized.

Copy link
@MichalPetryka

MichalPetryka Dec 31, 2019

Windows 8.1 also has them

This comment has been minimized.

Copy link
@pr8x

pr8x Jan 4, 2020

Author Contributor

Yeah Windows 8 and 8.1 both have support for the ToastNotification API. Not sure if we really care about Windows 8 though 😄 .

This comment has been minimized.

Copy link
@kekekeks

kekekeks Jan 4, 2020

Member

We probably want a managed fallback that displays notifications in separate windows manually. Like IM clients of the past did. That's not in the scope of this PR though.

This comment has been minimized.

Copy link
@MichalPetryka

MichalPetryka Jan 7, 2020

Well, it's more of "do people who use Avalonia for their software care about Windows 8 and 8.1", not "if we care about it".

pr8x added 3 commits Dec 24, 2019
!F Close and action callbacks
!F Handling notification center events in seperate delegate
!T Renaming some files to be more consistent
@pr8x

This comment has been minimized.

Copy link
Contributor Author

pr8x commented Jan 4, 2020

@danwalmsley So how do we solve the problem with registering the application shortcut in the startmenu on Windows? Should I just register a temporary and uninstall it when the application terminates?

@MonkAlex

This comment has been minimized.

Copy link
Contributor

MonkAlex commented Jan 4, 2020

its not required, but will be used, if registered (not check, only google)
social.msdn.microsoft.com

@pr8x

This comment has been minimized.

Copy link
Contributor Author

pr8x commented Jan 4, 2020

In my experience deleting the shortcut (even when the AppUserModelID has been assigned to the current process via SetCurrentProcessExplicitAppUserModelID) will cause the toast nofications to be ignored by Windows. Most official Microsoft sources confirm this.

A shortcut to your app, with a System.AppUserModel.ID, must be installed to the Start screen. Note, however, that it does not need to be pinned to the Start screen

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh802768(v=vs.85)?redirectedfrom=MSDN

Also it seems like once the shortcut was installed they use the name and the icon of it to display the application in the taskbar. Without a shortcut the taskbar icon will default to the main window icon AFAICT. So it might actually be a good idea to have some sort of RegisterApplication function on the Win32Platform that takes care of registering your AppUserModelID and assigning name and icon of your application via the shortcut.

# Conflicts:
#	src/Avalonia.Native/AvaloniaNativePlatform.cs
@pr8x pr8x marked this pull request as ready for review Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.