55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using VisionAsist.Models;
|
|
using VisionAsist.Views;
|
|
using Avalonia.Threading;
|
|
|
|
namespace VisionAsist.ViewModels;
|
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
|
{
|
|
public MainWindowViewModel()
|
|
{
|
|
Selector.OnLogUpdate += text =>
|
|
{
|
|
Dispatcher.UIThread.Post(() =>
|
|
{
|
|
CommandLog += text;
|
|
});
|
|
};
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void Settingse()
|
|
{
|
|
new Settings { DataContext = new SettingsViewModel() }.Show();
|
|
}
|
|
|
|
[ObservableProperty]
|
|
private string commandLog = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string commandText = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private bool isGenerating = false;
|
|
|
|
[RelayCommand]
|
|
private async Task Send()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(CommandText) && !IsGenerating)
|
|
{
|
|
string input = CommandText;
|
|
CommandText = string.Empty;
|
|
IsGenerating = true;
|
|
|
|
// Запускаем логику в фоновом потоке, чтобы UI не зависал
|
|
await Task.Run(async () => {
|
|
await Selector.selector(input);
|
|
IsGenerating = false;
|
|
});
|
|
}
|
|
}
|
|
} |