45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using VisionAsist.Models;
|
|
namespace VisionAsist.ViewModels;
|
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
|
{
|
|
[ObservableProperty]
|
|
private bool isListening;
|
|
[ObservableProperty]
|
|
private string recognizedtext;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |