76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using System;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using VisionAsist.Models;
|
|
using VisionAsist.Views;
|
|
|
|
namespace VisionAsist.ViewModels;
|
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
|
{
|
|
[RelayCommand]
|
|
private void Settingse()
|
|
{
|
|
new Settings
|
|
{
|
|
DataContext = new SettingsViewModel()
|
|
}.Show();
|
|
|
|
}
|
|
|
|
[ObservableProperty]
|
|
private bool isListening;
|
|
[ObservableProperty]
|
|
private string recognizedtext;
|
|
[ObservableProperty]
|
|
private string commandText;
|
|
|
|
[RelayCommand]
|
|
private void Send()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(CommandText))
|
|
{
|
|
// Эмулируем распознанный текст для отображения в логе
|
|
Recognizedtext = CommandText;
|
|
|
|
// Отправляем в селектор
|
|
Selector.selector(CommandText);
|
|
|
|
// Очищаем поле ввода
|
|
CommandText = string.Empty;
|
|
}
|
|
}
|
|
|
|
private Action<string>? _coreHandler;
|
|
|
|
partial void OnIsListeningChanged(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
Core.StartListing();
|
|
|
|
// Сохраняем ссылку на обработчик
|
|
_coreHandler = word =>
|
|
{
|
|
|
|
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
|
|
{
|
|
Recognizedtext = Core.TextAsist;
|
|
});
|
|
};
|
|
|
|
Core.triger.OnRecognized += _coreHandler;
|
|
}
|
|
else
|
|
{
|
|
Core.StopListing();
|
|
|
|
// Правильная отписка
|
|
if (_coreHandler != null)
|
|
{
|
|
Core.triger.OnRecognized -= _coreHandler;
|
|
_coreHandler = null;
|
|
}
|
|
}
|
|
}
|
|
} |