moved to MVVM architecture

This commit is contained in:
2026-08-08 21:24:02 +05:00
parent a1ff8cc923
commit 3d614255d8
19 changed files with 565 additions and 346 deletions
+41
View File
@@ -0,0 +1,41 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CursorLang.Models;
using CursorLang.Services;
namespace CursorLang.ViewModels;
/// <summary>
/// Показывает текущую раскладку в главном окне и просит показать подсказку
/// у курсора, когда пользователь переключил раскладку сам.
/// </summary>
public sealed partial class MainViewModel : ObservableObject, IDisposable
{
private readonly IKeyboardLayoutService _layoutService;
private readonly ILayoutPopupService _popupService;
[ObservableProperty]
private string _currentLayout;
public MainViewModel(IKeyboardLayoutService layoutService, ILayoutPopupService popupService)
{
_layoutService = layoutService;
_popupService = popupService;
_currentLayout = layoutService.Current.DisplayName;
_layoutService.LayoutChanged += OnLayoutChanged;
}
public void Dispose() => _layoutService.LayoutChanged -= OnLayoutChanged;
private void OnLayoutChanged(object? sender, LayoutChangedEventArgs e)
{
CurrentLayout = e.Layout.DisplayName;
// При переходе в другое приложение раскладка меняется без участия
// пользователя, и всплывающая подсказка была бы навязчивой
if (e.Reason == LayoutChangeReason.UserSwitched)
{
_popupService.Show(e.Layout);
}
}
}