Skip to content

Commit 2147d97

Browse files
committed
Исправил баг с клавиатурой.
Добавил копирование текста в буфер на главной странице.
1 parent bab9645 commit 2147d97

3 files changed

Lines changed: 91 additions & 10 deletions

File tree

ChatCaster.Windows/ViewModels/ChatCasterWindowViewModel.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,18 @@ private async Task HandleVoiceRecordingAsync()
344344
if (_voiceRecordingService.IsRecording)
345345
{
346346
StatusText = _localizationService.GetString("StatusProcessing");
347-
await _voiceRecordingService.StopRecordingAsync();
347+
var result = await _voiceRecordingService.StopRecordingAsync();
348+
349+
// ✅ ДОБАВИТЬ: Отправляем результат в систему если успешно
350+
if (result.Success && !string.IsNullOrEmpty(result.RecognizedText))
351+
{
352+
await _systemService.SendTextAsync(result.RecognizedText);
353+
_trayService.ShowNotification("Распознано", result.RecognizedText, NotificationType.Success);
354+
}
355+
else
356+
{
357+
_trayService.ShowNotification("Ошибка", result.ErrorMessage ?? "Не удалось распознать речь", NotificationType.Error);
358+
}
348359
}
349360
else
350361
{
@@ -359,7 +370,6 @@ private async Task HandleVoiceRecordingAsync()
359370
_trayService.ShowNotification(_localizationService.GetString("Error") ?? "Ошибка", _localizationService.GetString("RecordingError"));
360371
}
361372
}
362-
363373
#endregion
364374

365375
#region Helper Methods

ChatCaster.Windows/ViewModels/Components/RecognitionResultsComponentViewModel.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Collections.ObjectModel;
2+
using System.Windows;
23
using ChatCaster.Core.Events;
34
using ChatCaster.Core.Services.System;
45
using CommunityToolkit.Mvvm.ComponentModel;
6+
using CommunityToolkit.Mvvm.Input;
57
using Serilog;
68

79
namespace ChatCaster.Windows.ViewModels.Components
@@ -35,6 +37,9 @@ public partial class RecognitionResultsComponentViewModel : ObservableObject
3537
[ObservableProperty]
3638
private ObservableCollection<string> _recentRecognitions = new();
3739

40+
[ObservableProperty]
41+
private bool _canCopyText = false;
42+
3843
// События для связи с родительской ViewModel
3944
public event Action<string>? TextRecognized;
4045

@@ -48,6 +53,36 @@ public RecognitionResultsComponentViewModel(ILocalizationService localizationSer
4853
SetInitialState();
4954
}
5055

56+
#region Commands
57+
58+
/// <summary>
59+
/// Команда копирования текста в буфер обмена
60+
/// </summary>
61+
[RelayCommand]
62+
public void CopyText()
63+
{
64+
try
65+
{
66+
Log.Information("RecognitionResultsComponent: попытка копирования текста");
67+
68+
if (!string.IsNullOrEmpty(LastRecognizedText))
69+
{
70+
Clipboard.SetText(LastRecognizedText);
71+
Log.Information($"RecognitionResultsComponent: текст скопирован в буфер обмена: {LastRecognizedText}");
72+
}
73+
else
74+
{
75+
Log.Warning("RecognitionResultsComponent: нет текста для копирования");
76+
}
77+
}
78+
catch (Exception ex)
79+
{
80+
Log.Error(ex, "RecognitionResultsComponent: ошибка копирования текста в буфер обмена");
81+
}
82+
}
83+
84+
#endregion
85+
5186
/// <summary>
5287
/// Обрабатывает завершение распознавания голоса
5388
/// </summary>
@@ -83,6 +118,9 @@ private void HandleSuccessfulRecognition(string recognizedText)
83118
ResultTextBrush = System.Windows.Media.Brushes.White;
84119
ResultFontStyle = System.Windows.FontStyles.Normal;
85120

121+
// Включаем возможность копирования
122+
CanCopyText = true;
123+
86124
// Добавляем в историю
87125
AddToRecentRecognitions(recognizedText);
88126

@@ -103,6 +141,9 @@ private void HandleRecognitionError(string? errorMessage)
103141
ResultTextBrush = System.Windows.Media.Brushes.Red;
104142
ResultFontStyle = System.Windows.FontStyles.Italic;
105143

144+
// Отключаем возможность копирования при ошибке
145+
CanCopyText = false;
146+
106147
// Очищаем метрики при ошибке
107148
ConfidenceText = "";
108149
ProcessingTimeText = "";
@@ -143,6 +184,9 @@ public void SetInitialState()
143184
LastRecognizedText = string.Empty;
144185
ConfidenceText = "";
145186
ProcessingTimeText = "";
187+
188+
// Отключаем копирование в начальном состоянии
189+
CanCopyText = false;
146190
}
147191
catch (Exception ex)
148192
{

ChatCaster.Windows/Views/ViewSettings/MainPageView.xaml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<Page.Resources>
1414
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
15+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
1516
</Page.Resources>
1617

1718
<ScrollViewer Padding="30" HorizontalScrollBarVisibility="Disabled">
@@ -99,18 +100,44 @@
99100
Padding="20"
100101
MinHeight="120"
101102
Margin="0,0,0,15">
102-
<!-- Правильные привязки к результатам -->
103-
<TextBlock Text="{Binding RecognitionResultsComponent.ResultText}"
104-
FontFamily="Consolas"
105-
FontSize="14"
106-
Foreground="{Binding RecognitionResultsComponent.ResultTextBrush}"
107-
FontStyle="{Binding RecognitionResultsComponent.ResultFontStyle}"
108-
TextWrapping="Wrap"/>
103+
104+
<Grid>
105+
<Grid.RowDefinitions>
106+
<RowDefinition Height="*"/>
107+
<RowDefinition Height="Auto"/>
108+
</Grid.RowDefinitions>
109+
110+
<!-- Текст результата -->
111+
<TextBlock Grid.Row="0"
112+
Text="{Binding RecognitionResultsComponent.ResultText}"
113+
FontFamily="Consolas"
114+
FontSize="14"
115+
Foreground="{Binding RecognitionResultsComponent.ResultTextBrush}"
116+
FontStyle="{Binding RecognitionResultsComponent.ResultFontStyle}"
117+
TextWrapping="Wrap"/>
118+
119+
<!-- Кнопка копирования -->
120+
<Button Grid.Row="1"
121+
Command="{Binding RecognitionResultsComponent.CopyTextCommand}"
122+
Background="Transparent"
123+
BorderBrush="Transparent"
124+
HorizontalAlignment="Right"
125+
VerticalAlignment="Bottom"
126+
Padding="8"
127+
Margin="0,10,0,0"
128+
ToolTip="Копировать текст"
129+
Cursor="Hand"
130+
Visibility="{Binding RecognitionResultsComponent.CanCopyText, Converter={StaticResource BooleanToVisibilityConverter}}">
131+
<ui:SymbolIcon Symbol="Copy24"
132+
FontSize="16"
133+
Foreground="#999999"/>
134+
</Button>
135+
</Grid>
109136
</Border>
110137

111138
<StackPanel Grid.Row="2"
112139
Orientation="Horizontal">
113-
<!-- Правильные привязки к метрикам -->
140+
114141
<TextBlock Text="{Binding RecognitionResultsComponent.ConfidenceText}"
115142
FontSize="12"
116143
Foreground="#999999"

0 commit comments

Comments
 (0)