42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using CursorLang.Models;
|
|
|
|
namespace CursorLang.Services;
|
|
|
|
/// <summary>
|
|
/// Ties layout tracking to showing the popup.
|
|
/// Lives for as long as the application runs, regardless of the open windows.
|
|
/// </summary>
|
|
public sealed class LayoutNotificationCoordinator : IDisposable
|
|
{
|
|
private readonly IKeyboardLayoutService _layoutService;
|
|
private readonly ILayoutPopupService _popupService;
|
|
|
|
public LayoutNotificationCoordinator(IKeyboardLayoutService layoutService, ILayoutPopupService popupService)
|
|
{
|
|
_layoutService = layoutService;
|
|
_popupService = popupService;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
_layoutService.LayoutChanged += OnLayoutChanged;
|
|
_layoutService.Start();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_layoutService.LayoutChanged -= OnLayoutChanged;
|
|
_layoutService.Stop();
|
|
}
|
|
|
|
private void OnLayoutChanged(object? sender, LayoutChangedEventArgs e)
|
|
{
|
|
// When moving to another application the layout changes without the user
|
|
// taking part, and a popup would be intrusive
|
|
if (e.Reason == LayoutChangeReason.UserSwitched)
|
|
{
|
|
_popupService.Show(e.Layout);
|
|
}
|
|
}
|
|
}
|