Skip to content

Commit efb60ca

Browse files
authored
chore: fixed user notifier default notification handler (#141)
1 parent 7e3782f commit efb60ca

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

App/App.xaml.cs

Lines changed: 4 additions & 8 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>();
@@ -337,12 +337,8 @@ public void RunInUiThread(DispatcherQueueHandler action)
337337
dispatcherQueue.TryEnqueue(action);
338338
}
339339

340-
public void HandleNotificationActivation(IDictionary<string, string> args)
340+
public void HandleNotificationActivation(IDictionary<string, string> _)
341341
{
342-
var app = (App)Current;
343-
if (app != null && app.TrayWindow != null)
344-
{
345-
app.TrayWindow.Tray_Open();
346-
}
342+
TrayWindow?.Tray_Open();
347343
}
348344
}

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy