diff --git a/App/App.xaml.cs b/App/App.xaml.cs index 3165e2f..bce7099 100644 --- a/App/App.xaml.cs +++ b/App/App.xaml.cs @@ -27,7 +27,7 @@ namespace Coder.Desktop.App; -public partial class App : Application, IDispatcherQueueManager, INotificationHandler +public partial class App : Application, IDispatcherQueueManager, IDefaultNotificationHandler { private const string MutagenControllerConfigSection = "MutagenController"; private const string UpdaterConfigSection = "Updater"; @@ -91,7 +91,7 @@ public App() services.AddSingleton(); services.AddSingleton(_ => this); - services.AddSingleton(_ => this); + services.AddSingleton(_ => this); services.AddSingleton(_ => new WindowsCredentialBackend(WindowsCredentialBackend.CoderCredentialsTargetName)); services.AddSingleton(); @@ -340,9 +340,6 @@ public void RunInUiThread(DispatcherQueueHandler action) public void HandleNotificationActivation(IDictionary args) { var app = (App)Current; - if (app != null && app.TrayWindow != null) - { - app.TrayWindow.Tray_Open(); - } + app.TrayWindow?.Tray_Open(); } } diff --git a/App/Services/UserNotifier.cs b/App/Services/UserNotifier.cs index e759c50..27f924d 100644 --- a/App/Services/UserNotifier.cs +++ b/App/Services/UserNotifier.cs @@ -15,6 +15,12 @@ public interface INotificationHandler public void HandleNotificationActivation(IDictionary args); } +// This interface is meant to protect the default +// notification handler from being overriden by DI. +public interface IDefaultNotificationHandler : INotificationHandler +{ +} + public interface IUserNotifier : INotificationHandler, IAsyncDisposable { public void RegisterHandler(string name, INotificationHandler handler); @@ -46,7 +52,7 @@ public class UserNotifier : IUserNotifier private ConcurrentDictionary Handlers { get; } = new(); public UserNotifier(ILogger logger, IDispatcherQueueManager dispatcherQueueManager, - INotificationHandler notificationHandler) + IDefaultNotificationHandler notificationHandler) { _logger = logger; _dispatcherQueueManager = dispatcherQueueManager; diff --git a/App/Views/TrayWindow.xaml.cs b/App/Views/TrayWindow.xaml.cs index 7269e68..72ab6cc 100644 --- a/App/Views/TrayWindow.xaml.cs +++ b/App/Views/TrayWindow.xaml.cs @@ -152,10 +152,13 @@ private void SetPageByState(RpcModel rpcModel, CredentialModel credentialModel, } } + /// + /// This method is called when the state changes, but we don't want to notify + /// the user if the state hasn't changed. + /// + /// private void MaybeNotifyUser(RpcModel rpcModel) { - // This method is called when the state changes, but we don't want to notify - // the user if the state hasn't changed. var isRpcLifecycleChanged = rpcModel.RpcLifecycle == RpcLifecycle.Disconnected && curRpcLifecycle != rpcModel.RpcLifecycle; var isVpnLifecycleChanged = (rpcModel.VpnLifecycle == VpnLifecycle.Started || rpcModel.VpnLifecycle == VpnLifecycle.Stopped) && curVpnLifecycle != rpcModel.VpnLifecycle;