diff --git a/Mystify/App.axaml.cs b/Mystify/App.axaml.cs index e846b63..5304915 100644 --- a/Mystify/App.axaml.cs +++ b/Mystify/App.axaml.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; @@ -6,6 +7,7 @@ using Lib.NotifyIcon; using LightweightIocContainer.Interfaces; using Mystify.ViewModels; using Mystify.Views; +using ReactiveUI; namespace Mystify { @@ -13,6 +15,7 @@ namespace Mystify { private IIocContainer? _kernel; private INotifyIcon? _notifyIcon; + private MainWindow? _mainWindow; public override void Initialize() => AvaloniaXamlLoader.Load(this); public override void OnFrameworkInitializationCompleted() @@ -22,19 +25,30 @@ namespace Mystify Bootstrapper bootstrapper = new(); _kernel = bootstrapper.BootstrapKernel(); - + + _mainWindow = new MainWindow + { + DataContext = new MainWindowViewModel() + }; + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime) { - desktopStyleApplicationLifetime.MainWindow = new MainWindow - { - DataContext = new MainWindowViewModel() - }; - desktopStyleApplicationLifetime.Exit += OnExit; _notifyIcon = _kernel.Resolve(); _notifyIcon.ToolTipText = "Test tool tip"; _notifyIcon.IconPath = "avares://Mystify/Resources/TestIcon.ico"; + + ContextMenu notifyIconContextMenu = new() + { + Items = new List + { + new() {Header = "Close", Command = ReactiveCommand.Create(() => desktopStyleApplicationLifetime.Shutdown())} + } + }; + + _notifyIcon.ContextMenu = notifyIconContextMenu; + _notifyIcon.DoubleClick += (_, _) => _mainWindow?.Show(); _notifyIcon.Visible = true; }