This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using VisionAsist.Models;
|
||||
@@ -15,23 +15,21 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
DataContext = new SettingsViewModel()
|
||||
}.Show();
|
||||
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isListening;
|
||||
private string commandLog = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string recognizedtext;
|
||||
[ObservableProperty]
|
||||
private string commandText;
|
||||
private string commandText = string.Empty;
|
||||
|
||||
[RelayCommand]
|
||||
private void Send()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(CommandText))
|
||||
{
|
||||
// Эмулируем распознанный текст для отображения в логе
|
||||
Recognizedtext = CommandText;
|
||||
// Отображаем введенную команду в логе
|
||||
CommandLog = CommandText;
|
||||
|
||||
// Отправляем в селектор
|
||||
Selector.selector(CommandText);
|
||||
@@ -40,37 +38,4 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user