From 8e782e8b73f2d8a42df14acca83915ee3ee74295 Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Sun, 7 Feb 2021 13:54:08 +0100 Subject: [PATCH] Add Avalonia example project --- .../AppBuilderExtensions.cs | 55 ++++++++++++++++ .../DesktopNotifications.Avalonia.csproj | 17 +++++ DesktopNotifications.sln | 14 ++++- Example.Avalonia/App.axaml | 7 +++ Example.Avalonia/App.axaml.cs | 24 +++++++ Example.Avalonia/Example.Avalonia.csproj | 15 +++++ Example.Avalonia/MainWindow.axaml | 20 ++++++ Example.Avalonia/MainWindow.axaml.cs | 62 +++++++++++++++++++ Example.Avalonia/Program.cs | 22 +++++++ Example.Avalonia/nuget.config | 11 ++++ 10 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 DesktopNotifications.Avalonia/AppBuilderExtensions.cs create mode 100644 DesktopNotifications.Avalonia/DesktopNotifications.Avalonia.csproj create mode 100644 Example.Avalonia/App.axaml create mode 100644 Example.Avalonia/App.axaml.cs create mode 100644 Example.Avalonia/Example.Avalonia.csproj create mode 100644 Example.Avalonia/MainWindow.axaml create mode 100644 Example.Avalonia/MainWindow.axaml.cs create mode 100644 Example.Avalonia/Program.cs create mode 100644 Example.Avalonia/nuget.config diff --git a/DesktopNotifications.Avalonia/AppBuilderExtensions.cs b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs new file mode 100644 index 0000000..f5abe94 --- /dev/null +++ b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs @@ -0,0 +1,55 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Platform; +using DesktopNotifications.FreeDesktop; +using DesktopNotifications.Windows; + +namespace DesktopNotifications.Avalonia +{ + /// + /// Extensions for + /// + public static class AppBuilderExtensions + { + /// + /// Setups the for the current platform and + /// binds it to the service locator (). + /// + /// + /// + /// + public static TAppBuilder SetupDesktopNotifications(this TAppBuilder builder) + where TAppBuilder : AppBuilderBase, new() + { + return builder.AfterSetup(async b => + { + var runtimeInfo = b.RuntimePlatform.GetRuntimeInfo(); + INotificationManager manager; + + switch (runtimeInfo.OperatingSystem) + { + case OperatingSystemType.WinNT: + { + var context = WindowsApplicationContext.FromCurrentProcess(b.Instance.Name); + manager = new WindowsNotificationManager(context); + break; + } + + case OperatingSystemType.Linux: + { + var context = FreeDesktopApplicationContext.FromCurrentProcess(); + manager = new FreeDesktopNotificationManager(context); + break; + } + + //TODO: OSX once implemented/stable + default: return; + } + + await manager.Initialize(); + + AvaloniaLocator.CurrentMutable.Bind().ToConstant(manager); + }); + } + } +} \ No newline at end of file diff --git a/DesktopNotifications.Avalonia/DesktopNotifications.Avalonia.csproj b/DesktopNotifications.Avalonia/DesktopNotifications.Avalonia.csproj new file mode 100644 index 0000000..4fa204a --- /dev/null +++ b/DesktopNotifications.Avalonia/DesktopNotifications.Avalonia.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp3.1 + + + + + + + + + + + + + diff --git a/DesktopNotifications.sln b/DesktopNotifications.sln index 3a20aff..733a4fe 100644 --- a/DesktopNotifications.sln +++ b/DesktopNotifications.sln @@ -11,7 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "Example\Example. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopNotifications.FreeDesktop", "DesktopNotifications.FreeDesktop\DesktopNotifications.FreeDesktop.csproj", "{96F637EF-FD11-41F5-8F40-4E37313697E3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesktopNotifications.Apple", "DesktopNotifications.Apple\DesktopNotifications.Apple.csproj", "{B4A6C639-79C4-48EF-955F-273CF01D7770}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopNotifications.Apple", "DesktopNotifications.Apple\DesktopNotifications.Apple.csproj", "{B4A6C639-79C4-48EF-955F-273CF01D7770}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopNotifications.Avalonia", "DesktopNotifications.Avalonia\DesktopNotifications.Avalonia.csproj", "{5D9904D2-E102-409D-AAFE-394A3DED40D9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Avalonia", "Example.Avalonia\Example.Avalonia.csproj", "{4408FE39-C5AF-453D-B6EE-E1A42504264A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +43,14 @@ Global {B4A6C639-79C4-48EF-955F-273CF01D7770}.Debug|Any CPU.Build.0 = Debug|Any CPU {B4A6C639-79C4-48EF-955F-273CF01D7770}.Release|Any CPU.ActiveCfg = Release|Any CPU {B4A6C639-79C4-48EF-955F-273CF01D7770}.Release|Any CPU.Build.0 = Release|Any CPU + {5D9904D2-E102-409D-AAFE-394A3DED40D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D9904D2-E102-409D-AAFE-394A3DED40D9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D9904D2-E102-409D-AAFE-394A3DED40D9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D9904D2-E102-409D-AAFE-394A3DED40D9}.Release|Any CPU.Build.0 = Release|Any CPU + {4408FE39-C5AF-453D-B6EE-E1A42504264A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4408FE39-C5AF-453D-B6EE-E1A42504264A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4408FE39-C5AF-453D-B6EE-E1A42504264A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4408FE39-C5AF-453D-B6EE-E1A42504264A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Example.Avalonia/App.axaml b/Example.Avalonia/App.axaml new file mode 100644 index 0000000..5143a3d --- /dev/null +++ b/Example.Avalonia/App.axaml @@ -0,0 +1,7 @@ + + + + + diff --git a/Example.Avalonia/App.axaml.cs b/Example.Avalonia/App.axaml.cs new file mode 100644 index 0000000..8e1a798 --- /dev/null +++ b/Example.Avalonia/App.axaml.cs @@ -0,0 +1,24 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +namespace Example.Avalonia +{ + public class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow(); + } + + base.OnFrameworkInitializationCompleted(); + } + } +} diff --git a/Example.Avalonia/Example.Avalonia.csproj b/Example.Avalonia/Example.Avalonia.csproj new file mode 100644 index 0000000..c51e7e1 --- /dev/null +++ b/Example.Avalonia/Example.Avalonia.csproj @@ -0,0 +1,15 @@ + + + WinExe + netcoreapp3.1 + enable + + + + + + + + + + diff --git a/Example.Avalonia/MainWindow.axaml b/Example.Avalonia/MainWindow.axaml new file mode 100644 index 0000000..f555638 --- /dev/null +++ b/Example.Avalonia/MainWindow.axaml @@ -0,0 +1,20 @@ + + + + + + +