From 445faf703e5fe6bd25bcd9f3f664860c04f44be1 Mon Sep 17 00:00:00 2001 From: rampaa Date: Sun, 18 Feb 2024 01:29:20 +0300 Subject: [PATCH] Minor --- JL.Windows/GUI/MainWindow.xaml.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/JL.Windows/GUI/MainWindow.xaml.cs b/JL.Windows/GUI/MainWindow.xaml.cs index 5c8dfa21..2053b9e1 100644 --- a/JL.Windows/GUI/MainWindow.xaml.cs +++ b/JL.Windows/GUI/MainWindow.xaml.cs @@ -227,13 +227,13 @@ private void HandlePostCopy(string text) if (ConfigManager.Precaching && DictUtils.DictsReady && !DictUtils.UpdatingJmdict && !DictUtils.UpdatingJmnedict && !DictUtils.UpdatingKanjidic && FreqUtils.FreqsReady - && MainTextBox.Text.Length < Utils.CacheSize) + && text.Length < Utils.CacheSize) { s_precacheCancellationTokenSource.Cancel(); s_precacheCancellationTokenSource.Dispose(); s_precacheCancellationTokenSource = new CancellationTokenSource(); - _ = Dispatcher.InvokeAsync(async () => await Precache(MainTextBox.Text, s_precacheCancellationTokenSource.Token).ConfigureAwait(false), DispatcherPriority.Background); + _ = Dispatcher.InvokeAsync(async () => await Precache(text, s_precacheCancellationTokenSource.Token).ConfigureAwait(false), DispatcherPriority.Background); } } @@ -800,11 +800,18 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e) if (SpeechSynthesisUtils.InstalledVoiceWithHighestPriority is not null) { - string selectedText = MainTextBox.SelectionLength > 0 - ? MainTextBox.SelectedText - : MainTextBox.Text; + string selectedText = WindowState is not WindowState.Minimized + ? MainTextBox.SelectionLength > 0 + ? MainTextBox.SelectedText + : MainTextBox.Text + : s_lastTextCopiedWhileMinimized is not null + ? s_lastTextCopiedWhileMinimized + : MainTextBox.Text; - await SpeechSynthesisUtils.TextToSpeech(SpeechSynthesisUtils.InstalledVoiceWithHighestPriority, selectedText, CoreConfig.AudioVolume).ConfigureAwait(false); + if (selectedText.Length > 0) + { + await SpeechSynthesisUtils.TextToSpeech(SpeechSynthesisUtils.InstalledVoiceWithHighestPriority, selectedText, CoreConfig.AudioVolume).ConfigureAwait(false); + } } }