From 1b5e3687b645a601a586ef558db4e4c4f6cb2f9e Mon Sep 17 00:00:00 2001 From: Michael Suchacz <203725896+ibetitsmike@users.noreply.github.com> Date: Wed, 2 Jul 2025 01:35:48 +0200 Subject: [PATCH 1/2] chore: fixed user notifier default notification handler --- App/App.xaml.cs | 9 +++------ App/Services/UserNotifier.cs | 8 +++++++- App/Views/TrayWindow.xaml.cs | 7 +++++-- 3 files changed, 15 insertions(+), 9 deletions(-) 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; From 1bc1571aae3df126ad88f85c534a7c2db451e74d Mon Sep 17 00:00:00 2001 From: Michael Suchacz <203725896+ibetitsmike@users.noreply.github.com> Date: Mon, 7 Jul 2025 16:12:13 +0200 Subject: [PATCH 2/2] PR review --- App/App.xaml.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/App/App.xaml.cs b/App/App.xaml.cs index bce7099..a07af43 100644 --- a/App/App.xaml.cs +++ b/App/App.xaml.cs @@ -337,9 +337,8 @@ public void RunInUiThread(DispatcherQueueHandler action) dispatcherQueue.TryEnqueue(action); } - public void HandleNotificationActivation(IDictionary args) + public void HandleNotificationActivation(IDictionary _) { - var app = (App)Current; - app.TrayWindow?.Tray_Open(); + TrayWindow?.Tray_Open(); } }