Skip to content

Commit ff68c62

Browse files
Merge pull request #58 from nullinside-development-group/chore/rework
chore: code clean up
2 parents e08ce3c + 43464c1 commit ff68c62

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/TwitchStreamingTools/ViewModels/Pages/ChatViewModel.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.ObjectModel;
33
using System.Linq;
44
using System.Reactive;
5-
using System.Speech.Synthesis;
65
using System.Threading.Tasks;
76

87
using Nullinside.Api.Common.Twitch;
@@ -131,14 +130,16 @@ private void OnAddChatCommand() {
131130
return;
132131
}
133132

133+
// Add it to the list.
134134
_selectedTwitchChatNames.Add(username);
135135

136136
// Add the callback, we don't need to wait for it to return it can run in the background.
137137
_ = _twitchClient.AddMessageCallback(username, OnChatMessage);
138138

139-
140-
using var speech = new SpeechSynthesizer();
139+
// Clear out the textbox so the user knows we took their input
141140
TwitchChatName = null;
141+
142+
// Update and write the configuration
142143
_configuration.TwitchChats = (
143144
from user in _selectedTwitchChatNames
144145
select new TwitchChatConfiguration {
@@ -148,13 +149,22 @@ from user in _selectedTwitchChatNames
148149
TtsVoice = Configuration.GetDefaultTtsVoice(),
149150
TtsVolume = 100
150151
}).ToList();
152+
151153
_configuration.WriteConfiguration();
152154
}
153155

156+
/// <summary>
157+
/// Handles removing a chat we were monitoring.
158+
/// </summary>
159+
/// <param name="channel">The chat to remove.</param>
154160
private void OnRemoveChatCommand(string channel) {
161+
// Remove it from the list
155162
_selectedTwitchChatNames.Remove(channel);
163+
164+
// Remove the callback
156165
_twitchClient.RemoveMessageCallback(channel, OnChatMessage);
157-
using var speech = new SpeechSynthesizer();
166+
167+
// Update and write the configuration
158168
_configuration.TwitchChats = (
159169
from user in _selectedTwitchChatNames
160170
select new TwitchChatConfiguration {
@@ -168,6 +178,10 @@ from user in _selectedTwitchChatNames
168178
_configuration.WriteConfiguration();
169179
}
170180

181+
/// <summary>
182+
/// Handles a new chat message being received from <see cref="_twitchClient" />.
183+
/// </summary>
184+
/// <param name="msg">The message received.</param>
171185
private void OnChatMessage(OnMessageReceivedArgs msg) {
172186
if (_selectedTwitchChatNames.Count > 1) {
173187
TwitchChat = (TwitchChat + $"\n({msg.ChatMessage.Channel}) {msg.ChatMessage.Username}: {msg.ChatMessage.Message}").Trim();

src/TwitchStreamingTools/ViewModels/Pages/SettingsViewModel.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,24 @@ public class SettingsViewModel : PageViewModelBase {
1919
/// </summary>
2020
private readonly IConfiguration _configuration;
2121

22+
/// <summary>
23+
/// The list of possible output devices that exist on the machine.
24+
/// </summary>
2225
private ObservableCollection<string> _outputDevices;
26+
27+
/// <summary>
28+
/// The selected output device to send TTS to.
29+
/// </summary>
2330
private string? _selectedOutputDevice;
31+
32+
/// <summary>
33+
/// The TTS voice selected to send TTS to.
34+
/// </summary>
2435
private string? _selectedTtsVoice;
36+
37+
/// <summary>
38+
/// The list of installed TTS voices on the machine.
39+
/// </summary>
2540
private ObservableCollection<string> _ttsVoices;
2641

2742
/// <summary>
@@ -35,6 +50,9 @@ public class SettingsViewModel : PageViewModelBase {
3550
/// </summary>
3651
public SettingsViewModel(IConfiguration configuration) {
3752
_configuration = configuration;
53+
54+
// Get the list of output devices and set the default to either what we have in the configuration or the system
55+
// default whichever is more appropriate.
3856
var outputDevices = new List<string>();
3957
for (int i = 0; i < NAudioUtilities.GetTotalOutputDevices(); i++) {
4058
outputDevices.Add(NAudioUtilities.GetOutputDevice(i).ProductName);
@@ -43,9 +61,15 @@ public SettingsViewModel(IConfiguration configuration) {
4361
_outputDevices = new ObservableCollection<string>(outputDevices);
4462
_selectedOutputDevice = Configuration.GetDefaultAudioDevice();
4563

64+
// Get the list of TTS voices and set the default to either what we have in the configuration or the system
65+
// default whichever is more appropriate.
4666
using var speech = new SpeechSynthesizer();
4767
_ttsVoices = new ObservableCollection<string>(speech.GetInstalledVoices().Select(v => v.VoiceInfo.Name));
4868
_selectedTtsVoice = Configuration.GetDefaultTtsVoice();
69+
70+
// Get the volume and set the default to either what we have in the configuration or to half-volume. Why half-volume?
71+
// No one knows. I just figured I'd at least try not to blow anyone's eardrums out. I'm sure this decision will haunt
72+
// me one day.
4973
_ttsVolume = Configuration.GetDefaultTtsVolume() ?? 50u;
5074
}
5175

0 commit comments

Comments
 (0)