Git Product home page Git Product logo

desktopnotifications's Introduction

DesktopNotifications

A cross-platform C# library for native desktop "toast" notifications.

Build Nuget Nuget

Screenshot (Linux)

Screenshot (Windows)

Features

Windows Linux (FreeDesktop.DBus) OSX
Show notifications
Hide notifications
Schedule notifications ✓*
Launch actions ✓**
Replacing notifications
Buttons
Audio
Images ✓***

* Scheduled notifications will only be delivered while the application is running.
** This is currently not supported when targeting .netstandard
*** If supported by the notification server

Application Context

Most operating systems require you to register the application in some form before you can actually send notifications. This registration process is handled by the ApplicationContext. On Windows (see WindowsApplicationContext) it will create and assign a Application User Model Id to the current process and associate a shell link in the start menu with it. This will cause your application to appear in the Windows Start Menu. On Linux/FreeDesktop.DBUS, the application context is just holding the name and optional icon of your application.

Avalonia

The DesktopNotifications.Avalonia package offers support for the Avalonia project. It doesn't do much on its own, it just provides helpers to register the INotificationManager with the application builder. You can see an example of it in the Example.Avalonia project.

Help wanted

My MacBook Pro is 11 years old now and it does not run OSX Mojave or higher. Unfortunately, Apple deprecated NSUserNotificationCenter with OSX 10.14 and I suppose they want us to use the newer UNUserNotificationCenter API instead. I would kindly appreciate any contributions from folks that own a more modern Mac and are interested in implementing the OSX backend using the new API.

License

See License

desktopnotifications's People

Contributors

alexalok avatar nnym avatar onionware-github avatar pr8x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

desktopnotifications's Issues

System.TypeLoadException: 'Could not load type 'Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat' from assembly 'Microsoft.Toolkit.Uwp.Notifications

Using latest nuget in Avalonia raises:

manager = new WindowsNotificationManager(context);

System.TypeLoadException: 'Could not load type 'Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat' from assembly 'Microsoft.Toolkit.Uwp.Notifications, Version=7.1.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2'.'

image

All nuget installed:

image

Using net6.0, when publishing with net6.0 win-x64 does the same result.

Question - .net5

Is this .net5 ready or will it be?

And I'm new is this how you ask questions?

.NET Standard

Can this library support .NET standard and not .NET Core 3

Avalonia: Missing notification manager

Just added the code from Avalonia example to my project. Targeted the new SDK. Everything builds fine except the line: public static INotificationManager notificationManager = AvaloniaLocator.Current.GetService<INotificationManager>() ?? throw new InvalidOperationException("Missing notification manager"); which throws.

Progress of macOS support

Is there any progress for the macOS support? I'm trying to help with the MacOS API but I don't have any MacBook for now.

Clone x:DataType after installed this package via NuGet

After installed DesktopNotifications packages, my axamls are appeared x:DataType twice.

I still wondering why this happen. I tried to create another project and copy all source code to other project, still happen this.
And I remembered, this happen could affected by installed NuGet packages recently. So I removed DesktopNotifications packages and my axamls no more shows x:DataType twice.

SetupDesktopNotification doesn't correspond to the example in 1.3.1

hi,
I tried to use your library but it looks like the extension method has no second parameters
I have this prototype when I check locally
public static TAppBuilder SetupDesktopNotifications<TAppBuilder>(this TAppBuilder builder) where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
image

I just installed the nuget and tried to follow the example
did I do something wrong ?

OSX notifications

According to the readme, looks like this doesn't support OSX. Adding this issue as a tracking issue for that support

Linux Notification Issue

Error when notification button is pressed on FreeDesktop

Unhandled exception. Tmds.DBus.DisconnectedException: Signal handler for org.freedesktop.Notifications.NotificationClosed threw an exception
 ---> System.InvalidOperationException: Signal handler for org.freedesktop.Notifications.NotificationClosed threw an exception
 ---> System.Collections.Generic.KeyNotFoundException: The given key '16' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at DesktopNotifications.FreeDesktop.FreeDesktopNotificationManager.OnNotificationClosed(ValueTuple`2 event) in /home/ryoumiya/Documents/DesktopNotifications/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs:line 138
   at Tmds.DBus.WrappedDisposable.Call[T](Action`1 action, T value, Boolean disposes)
   at Tmds.DBus.CodeGen.DBusObjectProxy.<>c__DisplayClass7_0`1.<WatchNonVoidSignalAsync>b__0(Message msg, Exception ex)
   at Tmds.DBus.DBusConnection.HandleSignal(Message msg)
   --- End of inner exception stack trace ---
   at Tmds.DBus.DBusConnection.HandleSignal(Message msg)
   at Tmds.DBus.DBusConnection.HandleMessage(Message msg, IMessageStream peer)
   at Tmds.DBus.DBusConnection.ReceiveMessages(IMessageStream peer, Action`2 disconnectAction)
   --- End of inner exception stack trace ---
   at DesktopNotifications.FreeDesktop.FreeDesktopNotificationManager.OnNotificationActionInvokedError(Exception obj) in /home/ryoumiya/Documents/DesktopNotifications/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs:line 157
   at Tmds.DBus.WrappedDisposable.Call[T](Action`1 action, T value, Boolean disposes)
   at Tmds.DBus.CodeGen.DBusObjectProxy.<>c__DisplayClass7_0`1.<WatchNonVoidSignalAsync>b__0(Message msg, Exception ex)
   at Tmds.DBus.DBusConnection.Disconnect(Boolean dispose, Exception exception)
   at Tmds.DBus.Connection.Disconnect(Boolean dispose, Exception exception)
   at Tmds.DBus.Connection.OnDisconnect(Exception e)
   at Tmds.DBus.DBusConnection.EmitDisconnected(IMessageStream peer, Exception e)
   at Tmds.DBus.DBusConnection.ReceiveMessages(IMessageStream peer, Action`2 disconnectAction)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

OS: OpenSuse Leap 15.5
.net: 7.0

'Could not load ToastNotificationManagerCompat' error on Windows 10

When running on Windows 10 I get this error when creating a new WindowsNotificationManager:

DesktopNotifications.Windows.WindowsNotificationManager..ctor(DesktopNotifications.Windows.WindowsApplicationContext ): System.TypeLoadException: Could not load type 'Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat' from assembly 'Microsoft.Toolkit.Uwp.Notifications, Version=7.1.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2'.

I can find this in the project dependencies

image

Can't build test app with net6.0

C:\Program Files\dotnet\sdk\6.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1149: DesktopNotifications.Windows.dll cannot be referenced because it uses built-in support for WinRT, which is no longer supported in .NET 5 and higher.  An updated version of the component supporting .NET 5 is needed. For more information, see...

Also net6.0-windows gives the same error.

Version 1.3.0 fails with System.PlatformNotSupportedException on Windows

Hey hey,

so I updated from 1.2.0 to 1.3.0 today and the same unchanged code now fails with

System.PlatformNotSupportedException 
Operation is not supported on this platform.
   at DesktopNotifications.Windows.WindowsNotificationManager..ctor(WindowsApplicationContext context)

My code:

public partial class App : Application
{
    private readonly IHost _host;

    public App()
    {
        _host = Host.CreateDefaultBuilder()
            .ConfigureServices((hostContext, services) =>
            {
                services.AddSingleton<INotificationManager, WindowsNotificationManager>();

                services.AddHostedService<UpdateMessageSubscriber>();
            }).Build();
    }

    private async void App_OnStartup(object sender, StartupEventArgs e)
    {
        // throws exception now
        INotificationManager notificationManager = _host.Services.GetRequiredService<INotificationManager>();

        await notificationManager.Initialize();

        await _host.StartAsync();
    }
}

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.