Skip to content

chore: fixed user notifier default notification handler #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -91,7 +91,7 @@ public App()
services.AddSingleton<IAgentApiClientFactory, AgentApiClientFactory>();

services.AddSingleton<IDispatcherQueueManager>(_ => this);
services.AddSingleton<INotificationHandler>(_ => this);
services.AddSingleton<IDefaultNotificationHandler>(_ => this);
services.AddSingleton<ICredentialBackend>(_ =>
new WindowsCredentialBackend(WindowsCredentialBackend.CoderCredentialsTargetName));
services.AddSingleton<ICredentialManager, CredentialManager>();
Expand Down Expand Up @@ -340,9 +340,6 @@ public void RunInUiThread(DispatcherQueueHandler action)
public void HandleNotificationActivation(IDictionary<string, string> args)
{
var app = (App)Current;
if (app != null && app.TrayWindow != null)
{
app.TrayWindow.Tray_Open();
}
app.TrayWindow?.Tray_Open();
Comment on lines 342 to +343
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be TrayWindow?.Tray_Open();

}
}
8 changes: 7 additions & 1 deletion App/Services/UserNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public interface INotificationHandler
public void HandleNotificationActivation(IDictionary<string, string> 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);
Expand Down Expand Up @@ -46,7 +52,7 @@ public class UserNotifier : IUserNotifier
private ConcurrentDictionary<string, INotificationHandler> Handlers { get; } = new();

public UserNotifier(ILogger<UserNotifier> logger, IDispatcherQueueManager dispatcherQueueManager,
INotificationHandler notificationHandler)
IDefaultNotificationHandler notificationHandler)
{
_logger = logger;
_dispatcherQueueManager = dispatcherQueueManager;
Expand Down
7 changes: 5 additions & 2 deletions App/Views/TrayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ private void SetPageByState(RpcModel rpcModel, CredentialModel credentialModel,
}
}

/// <summary>
/// This method is called when the state changes, but we don't want to notify
/// the user if the state hasn't changed.
/// </summary>
/// <param name="rpcModel"></param>
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;

Expand Down
Loading