Skip to content

Commit c8faa52

Browse files
Merge pull request #123 from nullinside-development-group/feat/skip
feat: adding skip all button
2 parents 3ee2521 + 8613af6 commit c8faa52

File tree

7 files changed

+120
-38
lines changed

7 files changed

+120
-38
lines changed

src/TwitchStreamingTools/Configuration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public static Configuration Instance {
8787
public bool SayUsernameWithMessage { get; set; }
8888

8989
/// <inheritdoc />
90-
public Keybind? SkipTtsKey { get; set; } = new() { Key = Keys.End };
90+
public Keybind? SkipTtsKey { get; set; } = new() { Key = Keys.Pause };
91+
92+
/// <inheritdoc />
93+
public Keybind? SkipAllTtsKey { get; set; }
9194

9295
/// <summary>
9396
/// Writes the configuration file to disk.

src/TwitchStreamingTools/Controls/ViewModels/Keybind.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text;
1+
using System;
2+
using System.Text;
23

34
using TwitchStreamingTools.Models;
45

@@ -52,4 +53,21 @@ public override string ToString() {
5253
sb.Append(Key);
5354
return sb.ToString();
5455
}
56+
57+
/// <inheritdoc />
58+
public override bool Equals(object? obj) {
59+
if (obj is Keybind keybind) {
60+
return Key == keybind.Key &&
61+
IsCtrl == keybind.IsCtrl &&
62+
IsShift == keybind.IsShift &&
63+
IsAlt == keybind.IsAlt;
64+
}
65+
66+
return base.Equals(obj);
67+
}
68+
69+
/// <inheritdoc />
70+
public override int GetHashCode() {
71+
return HashCode.Combine(Key, IsCtrl, IsShift, IsAlt);
72+
}
5573
}

src/TwitchStreamingTools/IConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public interface IConfiguration {
5656
/// </summary>
5757
Keybind? SkipTtsKey { get; set; }
5858

59+
/// <summary>
60+
/// The key press to skip all the TTS.
61+
/// </summary>
62+
Keybind? SkipAllTtsKey { get; set; }
63+
5964
/// <summary>
6065
/// Writes the configuration file to disk.
6166
/// </summary>

src/TwitchStreamingTools/Services/GlobalKeyPressService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public class GlobalKeyPressService : IGlobalKeyPressService {
4949
];
5050

5151
/// <summary>
52-
/// The thread to execute on.
52+
/// The keystroke callback.
5353
/// </summary>
54-
private readonly Thread _thread;
54+
private static Action<Keybind>? s_onKeystroke;
5555

5656
/// <summary>
57-
/// The keystroke callback.
57+
/// The thread to execute on.
5858
/// </summary>
59-
private static Action<Keybind>? s_onKeystroke;
59+
private readonly Thread _thread;
6060

6161
/// <summary>
6262
/// Initializes a new instance of the <see cref="GlobalKeyPressService" /> class.
@@ -130,8 +130,8 @@ private static int KeystrokeCallback(int nCode, IntPtr wParam, IntPtr lParam) {
130130
};
131131
LogKey(keybind);
132132

133-
var callbacks = s_onKeystroke;
134-
foreach (var callback in callbacks?.GetInvocationList() ?? []) {
133+
Action<Keybind>? callbacks = s_onKeystroke;
134+
foreach (Delegate callback in callbacks?.GetInvocationList() ?? []) {
135135
try {
136136
callback.DynamicInvoke(keybind);
137137
}

src/TwitchStreamingTools/Services/TwitchTtsService.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,37 @@ public TwitchTtsService(ITwitchClientProxy twitchClientProxy, IConfiguration con
8585
/// <param name="keybind">The keystroke.</param>
8686
private void OnKeystroke(Keybind keybind) {
8787
Keybind? skip = _configuration.SkipTtsKey;
88-
if (null == skip) {
89-
return;
88+
if (null != skip) {
89+
if (keybind.Key == skip.Key &&
90+
keybind.IsAlt == skip.IsAlt &&
91+
keybind.IsCtrl == skip.IsCtrl &&
92+
keybind.IsShift == skip.IsShift) {
93+
List<TwitchChatTts> chats = _chats.ToList();
94+
foreach (TwitchChatTts chat in chats) {
95+
try {
96+
chat.SkipCurrentTts();
97+
}
98+
catch {
99+
// Do nothing, just try to skip the best we can.
100+
}
101+
}
102+
}
90103
}
91104

92-
if (keybind.Key == skip.Key &&
93-
keybind.IsAlt == skip.IsAlt &&
94-
keybind.IsCtrl == skip.IsCtrl &&
95-
keybind.IsShift == skip.IsShift) {
96-
var chats = _chats.ToList();
97-
foreach (TwitchChatTts chat in chats) {
98-
try {
99-
chat.SkipCurrentTts();
100-
}
101-
catch {
102-
// Do nothing, just try to skip the best we can.
105+
Keybind? skipAll = _configuration.SkipAllTtsKey;
106+
if (null != skipAll) {
107+
if (keybind.Key == skipAll.Key &&
108+
keybind.IsAlt == skipAll.IsAlt &&
109+
keybind.IsCtrl == skipAll.IsCtrl &&
110+
keybind.IsShift == skipAll.IsShift) {
111+
List<TwitchChatTts> chats = _chats.ToList();
112+
foreach (TwitchChatTts chat in chats) {
113+
try {
114+
chat.SkipAllTts();
115+
}
116+
catch {
117+
// Do nothing, just try to skip the best we can.
118+
}
103119
}
104120
}
105121
}

src/TwitchStreamingTools/ViewModels/Pages/SettingsView/SettingsViewModel.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public class SettingsViewModel : PageViewModelBase {
7272
/// </summary>
7373
private bool _showAdvancedTts;
7474

75+
/// <summary>
76+
/// The keybind for skipping all TTS messages.
77+
/// </summary>
78+
private KeybindViewModel _skipAllTtsKeyBinding;
79+
7580
/// <summary>
7681
/// The keybind for skipping TTS messages.
7782
/// </summary>
@@ -120,7 +125,8 @@ public class SettingsViewModel : PageViewModelBase {
120125
/// <param name="ttsPhoneticWordsViewModel">The view model for the phonetic words list.</param>
121126
/// <param name="ttsSkipUsernamesViewModel">The control responsible for managing the list of usernames to skip.</param>
122127
/// <param name="keybindViewModel">The skip TTS keybind.</param>
123-
public SettingsViewModel(IConfiguration configuration, TtsPhoneticWordsViewModel ttsPhoneticWordsViewModel, TtsSkipUsernamesViewModel ttsSkipUsernamesViewModel, KeybindViewModel keybindViewModel) {
128+
/// <param name="keybindAllViewModel">The skip all TTS keybind.</param>
129+
public SettingsViewModel(IConfiguration configuration, TtsPhoneticWordsViewModel ttsPhoneticWordsViewModel, TtsSkipUsernamesViewModel ttsSkipUsernamesViewModel, KeybindViewModel keybindViewModel, KeybindViewModel keybindAllViewModel) {
124130
_configuration = configuration;
125131
_ttsPhoneticWordsViewModel = ttsPhoneticWordsViewModel;
126132
_ttsSkipUsernamesViewModel = ttsSkipUsernamesViewModel;
@@ -137,6 +143,9 @@ public SettingsViewModel(IConfiguration configuration, TtsPhoneticWordsViewModel
137143
_skipTtsKeyBinding = keybindViewModel;
138144
_skipTtsKeyBinding.Keybind = _configuration.SkipTtsKey;
139145
_skipTtsKeyBinding.Changed.Subscribe(OnSkipTtsKeybindChanged);
146+
_skipAllTtsKeyBinding = keybindAllViewModel;
147+
_skipAllTtsKeyBinding.Keybind = _configuration.SkipAllTtsKey;
148+
_skipAllTtsKeyBinding.Changed.Subscribe(OnSkipAllTtsKeybindChanged);
140149

141150
ToggleAdvancedTtsCommand = ReactiveCommand.Create(() => ShowAdvancedTts = !ShowAdvancedTts);
142151

@@ -400,6 +409,14 @@ public KeybindViewModel SkipTtsKeyBinding {
400409
set => this.RaiseAndSetIfChanged(ref _skipTtsKeyBinding, value);
401410
}
402411

412+
/// <summary>
413+
/// The keybind to use to skip all TTS messages.
414+
/// </summary>
415+
public KeybindViewModel SkipAllTtsKeyBinding {
416+
get => _skipAllTtsKeyBinding;
417+
set => this.RaiseAndSetIfChanged(ref _skipAllTtsKeyBinding, value);
418+
}
419+
403420
/// <summary>
404421
/// Handles updating the configuration when the skip TTS keybind changes.
405422
/// </summary>
@@ -412,4 +429,17 @@ private void OnSkipTtsKeybindChanged(IReactivePropertyChangedEventArgs<IReactive
412429
_configuration.SkipTtsKey = _skipTtsKeyBinding.Keybind;
413430
_configuration.WriteConfiguration();
414431
}
432+
433+
/// <summary>
434+
/// Handles updating the configuration when the skip all TTS keybind changes.
435+
/// </summary>
436+
/// <param name="args">The arguments about the properties that changed.</param>
437+
private void OnSkipAllTtsKeybindChanged(IReactivePropertyChangedEventArgs<IReactiveObject> args) {
438+
if (!nameof(_skipAllTtsKeyBinding.Keybind).Equals(args.PropertyName)) {
439+
return;
440+
}
441+
442+
_configuration.SkipAllTtsKey = _skipAllTtsKeyBinding.Keybind;
443+
_configuration.WriteConfiguration();
444+
}
415445
}

src/TwitchStreamingTools/Views/Pages/SettingsView/SettingsView.axaml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<RowDefinition Height="Auto" />
2626
<RowDefinition Height="Auto" />
2727
<RowDefinition Height="Auto" />
28+
<RowDefinition Height="Auto" />
2829
<RowDefinition />
2930
</Grid.RowDefinitions>
3031
<Grid.ColumnDefinitions>
@@ -44,33 +45,42 @@
4445
Grid.Column="0"
4546
HorizontalAlignment="Right"
4647
VerticalAlignment="Center">
48+
Skip All TTS Button:
49+
</Label>
50+
<controls:Keybind Grid.Row="1"
51+
Grid.Column="1"
52+
DataContext="{Binding SkipAllTtsKeyBinding}" />
53+
<Label Grid.Row="2"
54+
Grid.Column="0"
55+
HorizontalAlignment="Right"
56+
VerticalAlignment="Center">
4757
TTS Output Device:
4858
</Label>
49-
<ComboBox Grid.Row="1"
59+
<ComboBox Grid.Row="2"
5060
Grid.Column="1"
5161
HorizontalAlignment="Stretch"
5262
VerticalAlignment="Center"
5363
ItemsSource="{Binding OutputDevices}"
5464
SelectedItem="{Binding SelectedOutputDevice}" />
55-
<Label Grid.Row="2"
65+
<Label Grid.Row="3"
5666
Grid.Column="0"
5767
HorizontalAlignment="Right"
5868
VerticalAlignment="Center">
5969
TTS Voice:
6070
</Label>
61-
<ComboBox Grid.Row="2"
71+
<ComboBox Grid.Row="3"
6272
Grid.Column="1"
6373
HorizontalAlignment="Stretch"
6474
VerticalAlignment="Center"
6575
ItemsSource="{Binding TtsVoices}"
6676
SelectedItem="{Binding SelectedTtsVoice}" />
67-
<Label Grid.Row="3"
77+
<Label Grid.Row="4"
6878
Grid.Column="0"
6979
HorizontalAlignment="Right"
7080
VerticalAlignment="Center">
7181
TTS Volume:
7282
</Label>
73-
<Grid Grid.Row="3"
83+
<Grid Grid.Row="4"
7484
Grid.Column="1">
7585
<Grid.ColumnDefinitions>
7686
<ColumnDefinition Width="Auto" />
@@ -89,14 +99,14 @@
8999
IsSnapToTickEnabled="True"
90100
Value="{Binding TtsVolume}" />
91101
</Grid>
92-
<Label Grid.Row="4"
102+
<Label Grid.Row="5"
93103
Grid.Column="0"
94104
HorizontalAlignment="Right"
95105
VerticalAlignment="Top"
96106
Margin="0 12 0 0">
97107
TTS Playback Speed:
98108
</Label>
99-
<Grid Grid.Row="4"
109+
<Grid Grid.Row="5"
100110
Grid.Column="1">
101111
<Grid.ColumnDefinitions>
102112
<ColumnDefinition Width="Auto" />
@@ -117,30 +127,30 @@
117127
Maximum="3"
118128
Value="{Binding Speed}" />
119129
</Grid>
120-
<Label Grid.Row="5"
130+
<Label Grid.Row="6"
121131
Grid.Column="0"
122132
HorizontalAlignment="Right"
123133
VerticalAlignment="Top"
124134
Margin="0 3 0 0">
125135
Say Username with Message:
126136
</Label>
127-
<CheckBox Grid.Row="5"
137+
<CheckBox Grid.Row="6"
128138
Grid.Column="1"
129139
IsChecked="{Binding SayUsernameWithMessage}" />
130-
<Label Grid.Row="6"
140+
<Label Grid.Row="7"
131141
Grid.Column="0"
132142
HorizontalAlignment="Right"
133143
VerticalAlignment="Top"
134144
Margin="0 5 0 0">
135145
Advanced TTS Playback:
136146
</Label>
137-
<Button Grid.Row="6"
147+
<Button Grid.Row="7"
138148
Grid.Column="1"
139149
IsVisible="{Binding !ShowAdvancedTts}"
140150
Command="{Binding ToggleAdvancedTtsCommand}">
141151
Show Options
142152
</Button>
143-
<Grid Grid.Row="6"
153+
<Grid Grid.Row="7"
144154
Grid.Column="1"
145155
IsVisible="{Binding ShowAdvancedTts}">
146156
<Grid>
@@ -208,26 +218,26 @@
208218
IsChecked="{Binding TurnOnSpeech}" />
209219
</Grid>
210220
</Grid>
211-
<Label Grid.Row="7"
221+
<Label Grid.Row="8"
212222
Grid.Column="0"
213223
HorizontalAlignment="Right"
214224
VerticalAlignment="Top"
215225
Margin="0 5 0 0">
216226
Skip User TTS:
217227
</Label>
218-
<Grid Grid.Row="7"
228+
<Grid Grid.Row="8"
219229
Grid.Column="1">
220230
<settingsView:TtsSkipUsernamesControl Margin="0,0,5,0"
221231
DataContext="{Binding TtsSkipUsernamesViewModel}" />
222232
</Grid>
223-
<Label Grid.Row="8"
233+
<Label Grid.Row="9"
224234
Grid.Column="0"
225235
HorizontalAlignment="Right"
226236
VerticalAlignment="Top"
227237
Margin="0 5 0 0">
228238
Phonetic Spellings:
229239
</Label>
230-
<Grid Grid.Row="8"
240+
<Grid Grid.Row="9"
231241
Grid.Column="1">
232242
<settingsView:TtsPhoneticWordsControl Margin="0,0,5,0"
233243
DataContext="{Binding TtsPhoneticWordsViewModel}" />

0 commit comments

Comments
 (0)