Skip to content

Commit 1b5e368

Browse files
committed
chore: fixed user notifier default notification handler
1 parent 7e3782f commit 1b5e368

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

App/App.xaml.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace Coder.Desktop.App;
2929

30-
public partial class App : Application, IDispatcherQueueManager, INotificationHandler
30+
public partial class App : Application, IDispatcherQueueManager, IDefaultNotificationHandler
3131
{
3232
private const string MutagenControllerConfigSection = "MutagenController";
3333
private const string UpdaterConfigSection = "Updater";
@@ -91,7 +91,7 @@ public App()
9191
services.AddSingleton<IAgentApiClientFactory, AgentApiClientFactory>();
9292

9393
services.AddSingleton<IDispatcherQueueManager>(_ => this);
94-
services.AddSingleton<INotificationHandler>(_ => this);
94+
services.AddSingleton<IDefaultNotificationHandler>(_ => this);
9595
services.AddSingleton<ICredentialBackend>(_ =>
9696
new WindowsCredentialBackend(WindowsCredentialBackend.CoderCredentialsTargetName));
9797
services.AddSingleton<ICredentialManager, CredentialManager>();
@@ -340,9 +340,6 @@ public void RunInUiThread(DispatcherQueueHandler action)
340340
public void HandleNotificationActivation(IDictionary<string, string> args)
341341
{
342342
var app = (App)Current;
343-
if (app != null && app.TrayWindow != null)
344-
{
345-
app.TrayWindow.Tray_Open();
346-
}
343+
app.TrayWindow?.Tray_Open();
347344
}
348345
}

App/Services/UserNotifier.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public interface INotificationHandler
1515
public void HandleNotificationActivation(IDictionary<string, string> args);
1616
}
1717

18+
// This interface is meant to protect the default
19+
// notification handler from being overriden by DI.
20+
public interface IDefaultNotificationHandler : INotificationHandler
21+
{
22+
}
23+
1824
public interface IUserNotifier : INotificationHandler, IAsyncDisposable
1925
{
2026
public void RegisterHandler(string name, INotificationHandler handler);
@@ -46,7 +52,7 @@ public class UserNotifier : IUserNotifier
4652
private ConcurrentDictionary<string, INotificationHandler> Handlers { get; } = new();
4753

4854
public UserNotifier(ILogger<UserNotifier> logger, IDispatcherQueueManager dispatcherQueueManager,
49-
INotificationHandler notificationHandler)
55+
IDefaultNotificationHandler notificationHandler)
5056
{
5157
_logger = logger;
5258
_dispatcherQueueManager = dispatcherQueueManager;

App/Views/TrayWindow.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ private void SetPageByState(RpcModel rpcModel, CredentialModel credentialModel,
152152
}
153153
}
154154

155+
/// <summary>
156+
/// This method is called when the state changes, but we don't want to notify
157+
/// the user if the state hasn't changed.
158+
/// </summary>
159+
/// <param name="rpcModel"></param>
155160
private void MaybeNotifyUser(RpcModel rpcModel)
156161
{
157-
// This method is called when the state changes, but we don't want to notify
158-
// the user if the state hasn't changed.
159162
var isRpcLifecycleChanged = rpcModel.RpcLifecycle == RpcLifecycle.Disconnected && curRpcLifecycle != rpcModel.RpcLifecycle;
160163
var isVpnLifecycleChanged = (rpcModel.VpnLifecycle == VpnLifecycle.Started || rpcModel.VpnLifecycle == VpnLifecycle.Stopped) && curVpnLifecycle != rpcModel.VpnLifecycle;
161164

0 commit comments

Comments
 (0)