-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppBuilderExtensions.cs
38 lines (33 loc) · 1.23 KB
/
AppBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using DesktopNotifications;
using DesktopNotifications.FreeDesktop;
using DesktopNotifications.Windows;
namespace urlhandler;
public static class AppBuilderExtensions {
public static AppBuilder SetupDesktopNotifications(this AppBuilder builder, out INotificationManager? manager) {
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 10) {
var context = WindowsApplicationContext.FromCurrentProcess();
manager = new WindowsNotificationManager(context);
}
else if (Environment.OSVersion.Platform == PlatformID.Unix) {
var context = FreeDesktopApplicationContext.FromCurrentProcess();
manager = new FreeDesktopNotificationManager(context);
}
else {
// todo: macOS once implemented/stable
manager = null;
return builder;
}
// todo: any better way of doing this?
manager.Initialize().GetAwaiter().GetResult();
var manager_ = manager;
builder.AfterSetup(b => {
if (b.Instance?.ApplicationLifetime is IControlledApplicationLifetime lifetime) {
lifetime.Exit += (s, e) => { manager_.Dispose(); };
}
});
return builder;
}
}